mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
No forwarding of config map in to ChangeManagement class.
This commit is contained in:
parent
87c61ae7fb
commit
5e09e2fb88
@ -17,25 +17,6 @@ public class ChangeManagement implements Serializable {
|
||||
this.gitUtils = gitUtils ?: new GitUtils()
|
||||
}
|
||||
|
||||
String getChangeDocumentId(Map config) {
|
||||
|
||||
if(config.changeDocumentId) {
|
||||
script.echo "[INFO] Use changeDocumentId '${config.changeDocumentId}' from configuration."
|
||||
return config.changeDocumentId
|
||||
}
|
||||
|
||||
script.echo "[INFO] Retrieving changeDocumentId from git commit(s) [FROM: ${config.gitFrom}, TO: ${config.gitTo}]"
|
||||
def changeDocumentId = getChangeDocumentId(
|
||||
config.gitFrom,
|
||||
config.gitTo,
|
||||
config.gitChangeDocumentLabel,
|
||||
config.gitFormat
|
||||
)
|
||||
script.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from git commit(s)."
|
||||
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
String getChangeDocumentId(
|
||||
String from = 'origin/master',
|
||||
String to = 'HEAD',
|
||||
|
@ -86,6 +86,29 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
assert !inDevelopment
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifChangeIdPresentAsParameterAndFromCommitsChangeIdFromParameterIsUsedTest() {
|
||||
ChangeManagement cm = getChangeManagementUtils(true, '0815')
|
||||
|
||||
jsr.step.checkChangeInDevelopment(
|
||||
changeDocumentId: '42',
|
||||
cmUtils: cm,
|
||||
endpoint: 'https://example.org/cm')
|
||||
|
||||
assert cmUtilReceivedParams.changeId == '42'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifChangeIdNotPresentAsParameterButFromCommitsChangeIdFromCommitsIsUsedTest() {
|
||||
ChangeManagement cm = getChangeManagementUtils(true, '0815')
|
||||
|
||||
jsr.step.checkChangeInDevelopment(
|
||||
cmUtils: cm,
|
||||
endpoint: 'https://example.org/cm')
|
||||
|
||||
assert cmUtilReceivedParams.changeId == '0815'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeDocumentIdRetrievalFailsTest() {
|
||||
|
||||
|
@ -38,15 +38,6 @@ public class ChangeManagementTest extends BasePiperTest {
|
||||
.around(script)
|
||||
.around(logging)
|
||||
|
||||
@Test
|
||||
public void testGetChangeIdFromConfigWhenProvidedInsideConfig() {
|
||||
String[] viaGitUtils = ['0815']
|
||||
def changeDocumentId = new ChangeManagement(nullScript, gitUtilsMock(false, viaGitUtils))
|
||||
.getChangeDocumentId([changeDocumentId: '0042'])
|
||||
|
||||
assertThat(logging.log, containsString('[INFO] Use changeDocumentId \'0042\' from configuration.'))
|
||||
assertThat(changeDocumentId, is(equalTo('0042')))
|
||||
}
|
||||
@Test
|
||||
public void testRetrieveChangeDocumentIdOutsideGitWorkTreeTest() {
|
||||
|
||||
@ -95,22 +86,6 @@ public class ChangeManagementTest extends BasePiperTest {
|
||||
assert changeID == 'a'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveChangeDocumentWithUniqueResult() {
|
||||
|
||||
String[] changeIds = [ 'a' ];
|
||||
|
||||
def params = [ gitFrom: 'origin/master',
|
||||
gitTo: 'HEAD',
|
||||
gitChangeDocumentLabel: 'ChangeDocument\\s?:',
|
||||
gitFormat: '%b']
|
||||
|
||||
def changeID = new ChangeManagement(nullScript, gitUtilsMock(true, changeIds)).getChangeDocumentId(params)
|
||||
|
||||
assertThat(logging.log, containsString('[INFO] ChangeDocumentId \'a\' retrieved from git commit(s). '))
|
||||
assert changeID == 'a'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsChangeInDevelopmentReturnsTrueWhenChangeIsInDevelopent() {
|
||||
|
||||
|
@ -46,18 +46,32 @@ def call(parameters = [:]) {
|
||||
parameters, parameterKeys,
|
||||
stepConfigurationKeys)
|
||||
|
||||
def changeId = configuration.changeDocumentId
|
||||
|
||||
def changeId
|
||||
if(changeId?.trim()) {
|
||||
|
||||
try {
|
||||
echo "[INFO] ChangeDocumentId retrieved from parameters."
|
||||
|
||||
changeId = cm.getChangeDocumentId(configuration)
|
||||
} else {
|
||||
|
||||
if(! changeId?.trim()) {
|
||||
throw new ChangeManagementException("ChangeId is null or empty.")
|
||||
echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.gitFrom}, to: ${configuration.gitTo}]." +
|
||||
"Searching for pattern '${configuration.gitChangeDocumentLabel}'. Searching with format '${configuration.gitFormat}'."
|
||||
|
||||
try {
|
||||
changeId = cm.getChangeDocumentId(
|
||||
configuration.gitFrom,
|
||||
configuration.gitTo,
|
||||
configuration.gitChangeDocumentLabel,
|
||||
configuration.gitFormat
|
||||
)
|
||||
if(changeId?.trim()) {
|
||||
echo "[INFO] ChangeDocumentId '${changeId}' retrieved from commit history"
|
||||
} else {
|
||||
throw new ChangeManagementException("ChangeId is null or empty.")
|
||||
}
|
||||
} catch(ChangeManagementException ex) {
|
||||
throw new AbortException(ex.getMessage())
|
||||
}
|
||||
} catch(ChangeManagementException ex) {
|
||||
throw new AbortException(ex.getMessage())
|
||||
}
|
||||
|
||||
boolean isInDevelopment
|
||||
|
Loading…
x
Reference in New Issue
Block a user