From 5e09e2fb88e2c989b2431548ab4c695514453051 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Tue, 10 Jul 2018 11:09:20 +0200 Subject: [PATCH] No forwarding of config map in to ChangeManagement class. --- src/com/sap/piper/cm/ChangeManagement.groovy | 19 ------------- .../CheckChangeInDevelopmentTest.groovy | 23 +++++++++++++++ .../sap/piper/cm/ChangeManagementTest.groovy | 25 ----------------- vars/checkChangeInDevelopment.groovy | 28 ++++++++++++++----- 4 files changed, 44 insertions(+), 51 deletions(-) diff --git a/src/com/sap/piper/cm/ChangeManagement.groovy b/src/com/sap/piper/cm/ChangeManagement.groovy index f66e089f2..a1bb73de9 100644 --- a/src/com/sap/piper/cm/ChangeManagement.groovy +++ b/src/com/sap/piper/cm/ChangeManagement.groovy @@ -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', diff --git a/test/groovy/CheckChangeInDevelopmentTest.groovy b/test/groovy/CheckChangeInDevelopmentTest.groovy index c2d2c4087..037acf3fd 100644 --- a/test/groovy/CheckChangeInDevelopmentTest.groovy +++ b/test/groovy/CheckChangeInDevelopmentTest.groovy @@ -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() { diff --git a/test/groovy/com/sap/piper/cm/ChangeManagementTest.groovy b/test/groovy/com/sap/piper/cm/ChangeManagementTest.groovy index a758a5b60..f3492aa4a 100644 --- a/test/groovy/com/sap/piper/cm/ChangeManagementTest.groovy +++ b/test/groovy/com/sap/piper/cm/ChangeManagementTest.groovy @@ -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() { diff --git a/vars/checkChangeInDevelopment.groovy b/vars/checkChangeInDevelopment.groovy index 92b54eb3b..dc7bfeda9 100644 --- a/vars/checkChangeInDevelopment.groovy +++ b/vars/checkChangeInDevelopment.groovy @@ -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