Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[github] Don't consider PR body in CI skip logic #103

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions service/hook/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
33 changes: 7 additions & 26 deletions service/hook/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}

Expand Down