diff --git a/service/hook/github/github.go b/service/hook/github/github.go index c48ea0d6..a18fae4a 100644 --- a/service/hook/github/github.go +++ b/service/hook/github/github.go @@ -176,11 +176,19 @@ func transformPullRequestEvent(pullRequest PullRequestEventModel) hookCommon.Tra } } if pullRequest.Action == "edited" { - // skip it if only title / description changed, and the previous pattern did not include a [skip ci] pattern + // skip it if only title / description changed, and the current title did not remove a [skip ci] pattern if pullRequest.Changes.Base == nil { - if !hookCommon.IsSkipBuildByCommitMessage(pullRequest.Changes.Title.From) && !hookCommon.IsSkipBuildByCommitMessage(pullRequest.Changes.Body.From) { + // only description changed + if pullRequest.Changes.Title.From == "" { return hookCommon.TransformResultModel{ - Error: errors.New("Pull Request edit doesn't require a build: only title and/or description was changed, and previous one was not skipped"), + Error: errors.New("Pull Request edit doesn't require a build: only body/description was changed"), + ShouldSkip: true, + } + } + // title changed without removing any [skip ci] pattern + if !hookCommon.IsSkipBuildByCommitMessage(pullRequest.Changes.Title.From) { + return hookCommon.TransformResultModel{ + Error: errors.New("Pull Request edit doesn't require a build: only title was changed, and previous one was not skipped"), ShouldSkip: true, } } diff --git a/service/hook/github/github_test.go b/service/hook/github/github_test.go index d324e333..11dbd7c9 100644 --- a/service/hook/github/github_test.go +++ b/service/hook/github/github_test.go @@ -632,7 +632,7 @@ func Test_transformPullRequestEvent(t *testing.T) { }, } hookTransformResult := transformPullRequestEvent(pullRequest) - 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") + require.EqualError(t, hookTransformResult.Error, "Pull Request edit doesn't require a build: only title was changed, and previous one was not skipped") require.True(t, hookTransformResult.ShouldSkip) require.Equal(t, []bitriseapi.TriggerAPIParamsModel(nil), hookTransformResult.TriggerAPIParams) require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse) @@ -693,7 +693,7 @@ func Test_transformPullRequestEvent(t *testing.T) { require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse) } - t.Log("Pull Request - edited - only body/description change - no skip ci in previous - no build") + t.Log("Pull Request - edited - only body/description change - no build") { pullRequest := PullRequestEventModel{ Action: "edited", @@ -729,13 +729,13 @@ func Test_transformPullRequestEvent(t *testing.T) { }, } hookTransformResult := transformPullRequestEvent(pullRequest) - 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") + require.EqualError(t, hookTransformResult.Error, "Pull Request edit doesn't require a build: only body/description was changed") require.True(t, hookTransformResult.ShouldSkip) require.Equal(t, []bitriseapi.TriggerAPIParamsModel(nil), hookTransformResult.TriggerAPIParams) require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse) } - t.Log("Pull Request - edited - only body/description change - BUT the previous title included a skip CI pattern - should build") + t.Log("Pull Request - edited - only body/description change - the previous body included a skip CI pattern - still shouldn't build") { pullRequest := PullRequestEventModel{ Action: "edited", @@ -771,22 +771,9 @@ func Test_transformPullRequestEvent(t *testing.T) { }, } hookTransformResult := transformPullRequestEvent(pullRequest) - require.NoError(t, hookTransformResult.Error) - require.False(t, hookTransformResult.ShouldSkip) - require.Equal(t, []bitriseapi.TriggerAPIParamsModel{ - { - BuildParams: bitriseapi.BuildParamsModel{ - CommitHash: "83b86e5f286f546dc5a4a58db66ceef44460c85e", - CommitMessage: "PR test\n\nPR text body", - Branch: "feature/github-pr", - BranchDest: "develop", - PullRequestID: pointers.NewIntPtr(12), - PullRequestRepositoryURL: "https://github.com/bitrise-io/bitrise-webhooks.git", - PullRequestMergeBranch: "pull/12/merge", - PullRequestHeadBranch: "pull/12/head", - }, - }, - }, hookTransformResult.TriggerAPIParams) + require.EqualError(t, hookTransformResult.Error, "Pull Request edit doesn't require a build: only body/description was changed") + require.True(t, hookTransformResult.ShouldSkip) + require.Equal(t, []bitriseapi.TriggerAPIParamsModel(nil), hookTransformResult.TriggerAPIParams) require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse) } }