Skip to content

Commit 3c21621

Browse files
authored
check for skip ci in PR comments too (#229)
1 parent e6efed9 commit 3c21621

File tree

7 files changed

+25
-17
lines changed

7 files changed

+25
-17
lines changed

service/hook/bitbucketv2/bitbucketv2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ func transformPullRequestEvent(pullRequest PullRequestEventModel) hookCommon.Tra
309309
TriggeredBy: hookCommon.GenerateTriggeredBy(ProviderID, pullRequest.PullRequestInfo.Author.Nickname),
310310
},
311311
},
312-
SkippedByPrDescription: !hookCommon.IsSkipBuildByCommitMessage(pullRequest.PullRequestInfo.Title) &&
313-
hookCommon.IsSkipBuildByCommitMessage(pullRequest.PullRequestInfo.Description),
312+
SkippedByPrDescription: !hookCommon.ContainsSkipInstruction(pullRequest.PullRequestInfo.Title) &&
313+
hookCommon.ContainsSkipInstruction(pullRequest.PullRequestInfo.Description),
314314
}
315315
}
316316

service/hook/common/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type TransformResultModel struct {
3030
// TriggerAPIParams is the transformed Bitrise Trigger API params
3131
TriggerAPIParams []bitriseapi.TriggerAPIParamsModel
3232
// ShouldSkip if true then no build should be started for this webhook
33-
// but we should respond with a succcess HTTP status code
33+
// but we should respond with a success HTTP status code
3434
ShouldSkip bool
3535
// Error in transforming the hook. If ShouldSkip=true this is
3636
// the reason why the hook should be skipped.

service/hook/common/skipci.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package common
22

33
import "strings"
44

5-
// IsSkipBuildByCommitMessage ...
6-
func IsSkipBuildByCommitMessage(commitMsg string) bool {
5+
// ContainsSkipInstruction ...
6+
func ContainsSkipInstruction(commitMsg string) bool {
77
if checkSkipPatternPair(commitMsg, "ci", "skip") {
88
return true
99
}

service/hook/common/skipci_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ line too`,
2424
`this message has \\[skip bitrise\\] because of markdown`,
2525
} {
2626
t.Log(" * Commit message:", aCommitMsg)
27-
require.Equal(t, true, IsSkipBuildByCommitMessage(aCommitMsg))
27+
require.Equal(t, true, ContainsSkipInstruction(aCommitMsg))
2828
}
2929
}
3030

@@ -38,7 +38,7 @@ line too`,
3838
"this won't be skipped either: [ bitrise skip ]",
3939
} {
4040
t.Log(" * Commit message:", aCommitMsg)
41-
require.Equal(t, false, IsSkipBuildByCommitMessage(aCommitMsg))
41+
require.Equal(t, false, ContainsSkipInstruction(aCommitMsg))
4242
}
4343
}
4444
}
@@ -61,7 +61,7 @@ line too`,
6161
`this message has \\[skip ci\\] because of markdown`,
6262
} {
6363
t.Log(" * Commit message:", aCommitMsg)
64-
require.Equal(t, true, IsSkipBuildByCommitMessage(aCommitMsg))
64+
require.Equal(t, true, ContainsSkipInstruction(aCommitMsg))
6565
}
6666
}
6767

@@ -75,7 +75,7 @@ line too`,
7575
"this won't be skipped either: [ ci skip ]",
7676
} {
7777
t.Log(" * Commit message:", aCommitMsg)
78-
require.Equal(t, false, IsSkipBuildByCommitMessage(aCommitMsg))
78+
require.Equal(t, false, ContainsSkipInstruction(aCommitMsg))
7979
}
8080
}
8181
}

service/hook/endpoint.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,22 @@ func (c *Client) HTTPHandler(w http.ResponseWriter, r *http.Request) {
276276
for _, aBuildTriggerParam := range hookTransformResult.TriggerAPIParams {
277277
commitMessage := aBuildTriggerParam.BuildParams.CommitMessage
278278

279-
if hookCommon.IsSkipBuildByCommitMessage(commitMessage) {
279+
if hookCommon.ContainsSkipInstruction(commitMessage) {
280280
respondWith.SkippedTriggerResponses = append(respondWith.SkippedTriggerResponses, hookCommon.SkipAPIResponseModel{
281281
Message: "Build skipped because the commit message included a skip ci keyword ([skip ci] or [ci skip]).",
282282
CommitHash: aBuildTriggerParam.BuildParams.CommitHash,
283283
CommitMessage: aBuildTriggerParam.BuildParams.CommitMessage,
284284
Branch: aBuildTriggerParam.BuildParams.Branch,
285285
})
286286
continue
287+
} else if hookCommon.ContainsSkipInstruction(aBuildTriggerParam.BuildParams.PullRequestComment) {
288+
respondWith.SkippedTriggerResponses = append(respondWith.SkippedTriggerResponses, hookCommon.SkipAPIResponseModel{
289+
Message: "Build skipped because the PR comment included a skip ci keyword ([skip ci] or [ci skip]).",
290+
CommitHash: aBuildTriggerParam.BuildParams.CommitHash,
291+
CommitMessage: aBuildTriggerParam.BuildParams.CommitMessage,
292+
Branch: aBuildTriggerParam.BuildParams.Branch,
293+
})
294+
continue
287295
}
288296

289297
triggerBuildAndPrepareRespondWith := func() {

service/hook/github/github.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func transformPullRequestEvent(pullRequest PullRequestEventModel) hookCommon.Tra
268268
if pullRequest.Action == "edited" {
269269
// skip it if only title / description changed, and the previous pattern did not include a [skip ci] pattern
270270
if pullRequest.Changes.Base == nil {
271-
if !hookCommon.IsSkipBuildByCommitMessage(pullRequest.Changes.Title.From) && !hookCommon.IsSkipBuildByCommitMessage(pullRequest.Changes.Body.From) {
271+
if !hookCommon.ContainsSkipInstruction(pullRequest.Changes.Title.From) && !hookCommon.ContainsSkipInstruction(pullRequest.Changes.Body.From) {
272272
return hookCommon.TransformResultModel{
273273
Error: errors.New("pull Request edit doesn't require a build: only title and/or description was changed, and previous one was not skipped"),
274274
ShouldSkip: true,
@@ -355,8 +355,8 @@ func transformPullRequestEvent(pullRequest PullRequestEventModel) hookCommon.Tra
355355
TriggerAPIParams: []bitriseapi.TriggerAPIParamsModel{
356356
result,
357357
},
358-
SkippedByPrDescription: !hookCommon.IsSkipBuildByCommitMessage(pullRequest.PullRequestInfo.Title) &&
359-
hookCommon.IsSkipBuildByCommitMessage(pullRequest.PullRequestInfo.Body),
358+
SkippedByPrDescription: !hookCommon.ContainsSkipInstruction(pullRequest.PullRequestInfo.Title) &&
359+
hookCommon.ContainsSkipInstruction(pullRequest.PullRequestInfo.Body),
360360
}
361361
}
362362

@@ -472,8 +472,8 @@ func transformIssueCommentEvent(eventModel IssueCommentEventModel) hookCommon.Tr
472472
TriggerAPIParams: []bitriseapi.TriggerAPIParamsModel{
473473
result,
474474
},
475-
SkippedByPrDescription: !hookCommon.IsSkipBuildByCommitMessage(issue.Title) &&
476-
hookCommon.IsSkipBuildByCommitMessage(issue.Body),
475+
SkippedByPrDescription: !hookCommon.ContainsSkipInstruction(issue.Title) &&
476+
hookCommon.ContainsSkipInstruction(issue.Body),
477477
}
478478
}
479479

service/hook/gitlab/gitlab.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,8 @@ func transformMergeRequest(
624624
TriggeredBy: hookCommon.GenerateTriggeredBy(ProviderID, user.Username),
625625
},
626626
},
627-
SkippedByPrDescription: !hookCommon.IsSkipBuildByCommitMessage(mergeRequest.Title) &&
628-
hookCommon.IsSkipBuildByCommitMessage(mergeRequest.Description),
627+
SkippedByPrDescription: !hookCommon.ContainsSkipInstruction(mergeRequest.Title) &&
628+
hookCommon.ContainsSkipInstruction(mergeRequest.Description),
629629
}
630630
}
631631

0 commit comments

Comments
 (0)