diff --git a/service/hook/github/github.go b/service/hook/github/github.go index dee29c7e..f7199fd2 100644 --- a/service/hook/github/github.go +++ b/service/hook/github/github.go @@ -266,11 +266,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 6c9650f6..5ad646e8 100644 --- a/service/hook/github/github_test.go +++ b/service/hook/github/github_test.go @@ -1326,7 +1326,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) @@ -1397,7 +1397,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", @@ -1437,13 +1437,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", @@ -1483,28 +1483,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: &intTwelve, - PullRequestRepositoryURL: "https://github.com/bitrise-io/bitrise-webhooks.git", - BaseRepositoryURL: "https://github.com/bitrise-io/bitrise-webhooks.git", - HeadRepositoryURL: "https://github.com/bitrise-io/bitrise-webhooks.git", - PullRequestMergeBranch: "pull/12/merge", - PullRequestUnverifiedMergeBranch: "pull/12/merge", - PullRequestHeadBranch: "pull/12/head", - Environments: make([]bitriseapi.EnvironmentItem, 0), - PullRequestReadyState: bitriseapi.PullRequestReadyStateReadyForReview, - }, - TriggeredBy: "webhook-github/test_user", - }, - }, 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) }