Skip to content

Commit bf44f4e

Browse files
committed
[github] Don't consider PR body in CI skip logic
GitHub pull request edits were not triggering CI when the PR body/description contained the `[ ci skip ]`/`[ skip ci ]` pattern. This was an issue, for example, in Dependabot-generated PRs that include commit messages from upstream dependencies that do include the pattern. Furthermore, no other CI service or vendor considers the PR body for the "ci skip" mechanism. This corrects the behavior so that only commit messages or PR titles are considered when a PR is edited.
1 parent 4c20bd0 commit bf44f4e

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

service/hook/github/github.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,19 @@ func transformPullRequestEvent(pullRequest PullRequestEventModel) hookCommon.Tra
176176
}
177177
}
178178
if pullRequest.Action == "edited" {
179-
// skip it if only title / description changed, and the previous pattern did not include a [skip ci] pattern
179+
// skip it if only title / description changed, and the current title did not remove a [skip ci] pattern
180180
if pullRequest.Changes.Base == nil {
181-
if !hookCommon.IsSkipBuildByCommitMessage(pullRequest.Changes.Title.From) && !hookCommon.IsSkipBuildByCommitMessage(pullRequest.Changes.Body.From) {
181+
// only description changed
182+
if pullRequest.Changes.Title.From == "" {
182183
return hookCommon.TransformResultModel{
183-
Error: errors.New("Pull Request edit doesn't require a build: only title and/or description was changed, and previous one was not skipped"),
184+
Error: errors.New("Pull Request edit doesn't require a build: only body/description was changed"),
185+
ShouldSkip: true,
186+
}
187+
}
188+
// title changed without removing any [skip ci] pattern
189+
if !hookCommon.IsSkipBuildByCommitMessage(pullRequest.Changes.Title.From) {
190+
return hookCommon.TransformResultModel{
191+
Error: errors.New("Pull Request edit doesn't require a build: only title was changed, and previous one was not skipped"),
184192
ShouldSkip: true,
185193
}
186194
}

service/hook/github/github_test.go

+7-20
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ func Test_transformPullRequestEvent(t *testing.T) {
632632
},
633633
}
634634
hookTransformResult := transformPullRequestEvent(pullRequest)
635-
require.EqualError(t, hookTransformResult.Error, "Pull Request edit doesn't require a build: only title and/or description was changed, and previous one was not skipped")
635+
require.EqualError(t, hookTransformResult.Error, "Pull Request edit doesn't require a build: only title was changed, and previous one was not skipped")
636636
require.True(t, hookTransformResult.ShouldSkip)
637637
require.Equal(t, []bitriseapi.TriggerAPIParamsModel(nil), hookTransformResult.TriggerAPIParams)
638638
require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse)
@@ -693,7 +693,7 @@ func Test_transformPullRequestEvent(t *testing.T) {
693693
require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse)
694694
}
695695

696-
t.Log("Pull Request - edited - only body/description change - no skip ci in previous - no build")
696+
t.Log("Pull Request - edited - only body/description change - no build")
697697
{
698698
pullRequest := PullRequestEventModel{
699699
Action: "edited",
@@ -729,13 +729,13 @@ func Test_transformPullRequestEvent(t *testing.T) {
729729
},
730730
}
731731
hookTransformResult := transformPullRequestEvent(pullRequest)
732-
require.EqualError(t, hookTransformResult.Error, "Pull Request edit doesn't require a build: only title and/or description was changed, and previous one was not skipped")
732+
require.EqualError(t, hookTransformResult.Error, "Pull Request edit doesn't require a build: only body/description was changed")
733733
require.True(t, hookTransformResult.ShouldSkip)
734734
require.Equal(t, []bitriseapi.TriggerAPIParamsModel(nil), hookTransformResult.TriggerAPIParams)
735735
require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse)
736736
}
737737

738-
t.Log("Pull Request - edited - only body/description change - BUT the previous title included a skip CI pattern - should build")
738+
t.Log("Pull Request - edited - only body/description change - the previous body included a skip CI pattern - still shouldn't build")
739739
{
740740
pullRequest := PullRequestEventModel{
741741
Action: "edited",
@@ -771,22 +771,9 @@ func Test_transformPullRequestEvent(t *testing.T) {
771771
},
772772
}
773773
hookTransformResult := transformPullRequestEvent(pullRequest)
774-
require.NoError(t, hookTransformResult.Error)
775-
require.False(t, hookTransformResult.ShouldSkip)
776-
require.Equal(t, []bitriseapi.TriggerAPIParamsModel{
777-
{
778-
BuildParams: bitriseapi.BuildParamsModel{
779-
CommitHash: "83b86e5f286f546dc5a4a58db66ceef44460c85e",
780-
CommitMessage: "PR test\n\nPR text body",
781-
Branch: "feature/github-pr",
782-
BranchDest: "develop",
783-
PullRequestID: pointers.NewIntPtr(12),
784-
PullRequestRepositoryURL: "https://github.com/bitrise-io/bitrise-webhooks.git",
785-
PullRequestMergeBranch: "pull/12/merge",
786-
PullRequestHeadBranch: "pull/12/head",
787-
},
788-
},
789-
}, hookTransformResult.TriggerAPIParams)
774+
require.EqualError(t, hookTransformResult.Error, "Pull Request edit doesn't require a build: only body/description was changed")
775+
require.True(t, hookTransformResult.ShouldSkip)
776+
require.Equal(t, []bitriseapi.TriggerAPIParamsModel(nil), hookTransformResult.TriggerAPIParams)
790777
require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse)
791778
}
792779
}

0 commit comments

Comments
 (0)