mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-30 05:59:39 +02:00
Read transportId from commit history: split getChangeID method
This commit is contained in:
parent
75a9a76205
commit
8d60a81ec5
@ -24,22 +24,34 @@ public class ChangeManagement implements Serializable {
|
|||||||
String format = '%b'
|
String format = '%b'
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
return getLabeledItem('ChangeDocumentId', from, to, label, format)
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLabeledItem(
|
||||||
|
String name,
|
||||||
|
String from,
|
||||||
|
String to,
|
||||||
|
String label,
|
||||||
|
String format
|
||||||
|
) {
|
||||||
|
|
||||||
if( ! gitUtils.insideWorkTree() ) {
|
if( ! gitUtils.insideWorkTree() ) {
|
||||||
throw new ChangeManagementException('Cannot retrieve change document id. Not in a git work tree. Change document id is extracted from git commit messages.')
|
throw new ChangeManagementException("Cannot retrieve ${name}. Not in a git work tree. ${name} is extracted from git commit messages.")
|
||||||
}
|
}
|
||||||
|
|
||||||
def changeIds = gitUtils.extractLogLines(".*${label}.*", from, to, format)
|
def items = gitUtils.extractLogLines(".*${label}.*", from, to, format)
|
||||||
.collect { line -> line?.replaceAll(label,'')?.trim() }
|
.collect { line -> line?.replaceAll(label,'')?.trim() }
|
||||||
.unique()
|
.unique()
|
||||||
|
|
||||||
changeIds.retainAll { line -> line != null && ! line.isEmpty() }
|
items.retainAll { line -> line != null && ! line.isEmpty() }
|
||||||
if( changeIds.size() == 0 ) {
|
|
||||||
throw new ChangeManagementException("Cannot retrieve changeId from git commits. Change id retrieved from git commit messages via pattern '${label}'.")
|
if( items.size() == 0 ) {
|
||||||
} else if (changeIds.size() > 1) {
|
throw new ChangeManagementException("Cannot retrieve ${name} from git commits. ${name} retrieved from git commit messages via pattern '${label}'.")
|
||||||
throw new ChangeManagementException("Multiple ChangeIds found: ${changeIds}. Change id retrieved from git commit messages via pattern '${label}'.")
|
} else if (items.size() > 1) {
|
||||||
|
throw new ChangeManagementException("Multiple ${name}s found: ${items}. ${name} retrieved from git commit messages via pattern '${label}'.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return changeIds.get(0)
|
return items[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isChangeInDevelopment(String changeId, String endpoint, String username, String password, String clientOpts = '') {
|
boolean isChangeInDevelopment(String changeId, String endpoint, String username, String password, String clientOpts = '') {
|
||||||
|
@ -42,9 +42,9 @@ public class ChangeManagementTest extends BasePiperTest {
|
|||||||
public void testRetrieveChangeDocumentIdOutsideGitWorkTreeTest() {
|
public void testRetrieveChangeDocumentIdOutsideGitWorkTreeTest() {
|
||||||
|
|
||||||
thrown.expect(ChangeManagementException)
|
thrown.expect(ChangeManagementException)
|
||||||
thrown.expectMessage('Cannot retrieve change document id. ' +
|
thrown.expectMessage('Cannot retrieve ChangeDocumentId. ' +
|
||||||
'Not in a git work tree. ' +
|
'Not in a git work tree. ' +
|
||||||
'Change document id is extracted from git commit messages.')
|
'ChangeDocumentId is extracted from git commit messages.')
|
||||||
|
|
||||||
new ChangeManagement(nullScript, gitUtilsMock(false, new String[0])).getChangeDocumentId()
|
new ChangeManagement(nullScript, gitUtilsMock(false, new String[0])).getChangeDocumentId()
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ public class ChangeManagementTest extends BasePiperTest {
|
|||||||
public void testRetrieveChangeDocumentIdNothingFound() {
|
public void testRetrieveChangeDocumentIdNothingFound() {
|
||||||
|
|
||||||
thrown.expect(ChangeManagementException)
|
thrown.expect(ChangeManagementException)
|
||||||
thrown.expectMessage('Cannot retrieve changeId from git commits.')
|
thrown.expectMessage('Cannot retrieve ChangeDocumentId from git commits.')
|
||||||
|
|
||||||
new ChangeManagement(nullScript, gitUtilsMock(true, new String[0])).getChangeDocumentId()
|
new ChangeManagement(nullScript, gitUtilsMock(true, new String[0])).getChangeDocumentId()
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ public class ChangeManagementTest extends BasePiperTest {
|
|||||||
public void testRetrieveChangeDocumentIdReturnsArrayWithNullValue() {
|
public void testRetrieveChangeDocumentIdReturnsArrayWithNullValue() {
|
||||||
|
|
||||||
thrown.expect(ChangeManagementException)
|
thrown.expect(ChangeManagementException)
|
||||||
thrown.expectMessage('Cannot retrieve changeId from git commits.')
|
thrown.expectMessage('Cannot retrieve ChangeDocumentId from git commits.')
|
||||||
|
|
||||||
new ChangeManagement(nullScript, gitUtilsMock(true, (String[])[ null ])).getChangeDocumentId()
|
new ChangeManagement(nullScript, gitUtilsMock(true, (String[])[ null ])).getChangeDocumentId()
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ public class ChangeManagementTest extends BasePiperTest {
|
|||||||
public void testRetrieveChangeDocumentNotUnique() {
|
public void testRetrieveChangeDocumentNotUnique() {
|
||||||
|
|
||||||
thrown.expect(ChangeManagementException)
|
thrown.expect(ChangeManagementException)
|
||||||
thrown.expectMessage('Multiple ChangeIds found')
|
thrown.expectMessage('Multiple ChangeDocumentIds found')
|
||||||
|
|
||||||
String[] changeIds = [ 'a', 'b' ]
|
String[] changeIds = [ 'a', 'b' ]
|
||||||
new ChangeManagement(nullScript, gitUtilsMock(true, changeIds)).getChangeDocumentId()
|
new ChangeManagement(nullScript, gitUtilsMock(true, changeIds)).getChangeDocumentId()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user