Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Support skip-ci-build label for beatsWhen (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Sep 29, 2020
1 parent 4360ce6 commit 6ad6ed6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/test/groovy/BeatsWhenStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,39 @@ class BeatsWhenStepTests extends ApmBasePipelineTest {
printCallStack()
assertTrue(ret)
}

@Test
void test_isSkipCiBuildLabel_without_content() throws Exception {
def script = loadScript(scriptName)
helper.registerAllowedMethod('matchesPrLabel', [Map.class], { false })
def ret = script.isSkipCiBuildLabel(content: [:])
printCallStack()
assertFalse(ret)
}

@Test
void test_isSkipCiBuildLabel_with_label_enabled_and_pr_without_label_match() throws Exception {
def script = loadScript(scriptName)
helper.registerAllowedMethod('matchesPrLabel', [Map.class], { false })
def ret = script.isSkipCiBuildLabel(content: [ 'skip-ci-build-label': true ])
printCallStack()
assertFalse(ret)
}

@Test
void test_isSkipCiBuildLabel_with_label_enabled_and_pr_with_label_match() throws Exception {
def script = loadScript(scriptName)
helper.registerAllowedMethod('matchesPrLabel', [Map.class], { true })
def ret = script.isSkipCiBuildLabel(content: [ 'skip-ci-build-label': true ])
printCallStack()
assertTrue(ret)
}

@Test
void test_isSkipCiBuildLabel_with_label_disabled() throws Exception {
def script = loadScript(scriptName)
def ret = script.isSkipCiBuildLabel(content: [ 'skip-ci-build-label': false ])
printCallStack()
assertFalse(ret)
}
}
16 changes: 15 additions & 1 deletion vars/beatsWhen.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Boolean call(Map args = [:]){
def ret = false

markdownReason(project: project, reason: "## Build reasons for `${project} ${description}`")
if (whenEnabled(args)) {
if (whenEnabled(args) || !isSkipCiBuildLabel(args)) {
markdownReason(project: project, reason: "<details><summary>Expand to view the reasons</summary><p>\n")
if (whenBranches(args)) { ret = true }
if (whenChangeset(args)) { ret = true }
Expand Down Expand Up @@ -172,6 +172,20 @@ private Boolean whenTags(Map args = [:]) {
return false
}

private boolean isSkipCiBuildLabel(Map args = [:]) {
def gitHubLabel = 'skip-ci-build'
if (args.content?.get('skip-ci-build-label', false)) {
if (matchesPrLabel(label: gitHubLabel) ) {
markdownReason(project: args.project, reason: "* ✅ skip-ci-build-label is `enabled` and matches with the pattern `${gitHubLabel}`.")
return true
}
markdownReason(project: args.project, reason: "* skip-ci-build-label is `enabled` and does **NOT** match with the pattern `${gitHubLabel}`.")
} else {
markdownReason(project: args.project, reason: '* ❕skip-ci-build-label label is `disabled`.')
}
return false
}

private void markdownReason(Map args = [:]) {
buildReasons << args.reason
}
Expand Down

0 comments on commit 6ad6ed6

Please sign in to comment.