Skip to content

Commit 86a3521

Browse files
committed
feat: add skip CI command support
Implement support for skip CI commands in commit messages to allow users to skip PipelineRun execution. Supports [skip ci], [ci skip], [skip tkn], and [tkn skip] commands. When a skip command is detected in the commit message, PipelineRun execution is skipped. However, GitOps commands (/test, /retest, etc.) will still trigger PipelineRuns regardless of the skip command, allowing users to manually trigger CI when needed. Skipping Tekton till tests are added [skip tkn] Jira: https://issues.redhat.com/browse/SRVKP-8933 Signed-off-by: Akshay Pant <akshay.akshaypant@gmail.com>
1 parent f3db57f commit 86a3521

File tree

8 files changed

+35
-2
lines changed

8 files changed

+35
-2
lines changed

pkg/params/info/events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Event struct {
4343
PullRequestTitle string // Title of the pull Request
4444
PullRequestLabel []string // Labels of the pull Request
4545
TriggerComment string // The comment triggering the pipelinerun when using on-comment annotation
46+
HasSkipCommand bool // Commit has command to skip PipelineRun
4647

4748
// TODO: move forge specifics to each driver
4849
// Github

pkg/pipelineascode/pipelineascode.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/openshift-pipelines/pipelines-as-code/pkg/formatting"
1414
"github.com/openshift-pipelines/pipelines-as-code/pkg/kubeinteraction"
1515
"github.com/openshift-pipelines/pipelines-as-code/pkg/matcher"
16+
"github.com/openshift-pipelines/pipelines-as-code/pkg/opscomments"
1617
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
1718
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
1819
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings"
@@ -89,7 +90,14 @@ func (p *PacRun) Run(ctx context.Context) error {
8990
if repo.Spec.ConcurrencyLimit != nil && *repo.Spec.ConcurrencyLimit != 0 {
9091
p.manager.Enable()
9192
}
92-
93+
// Check skip logic after annotation matching, so that the EventType has been properly updated.
94+
// In order for the PR to be skipped, the commit message should include the skip command.
95+
// We don't want to skip the PR when the event is a GitOps command. For example, if the
96+
// user has added `[skip ci]` to the commit, they don't need to push again to trigger the
97+
// PipelineRun, they can simply add a comment to trigger the CI via `/test pr-name` or on-comment.
98+
if p.event.HasSkipCommand && !opscomments.IsAnyOpsEventType(p.event.EventType) {
99+
return nil
100+
}
93101
// set params for the console driver, only used for the custom console ones
94102
cp := customparams.NewCustomParams(p.event, repo, p.run, p.k8int, p.eventEmitter, p.vcx)
95103
maptemplate, _, err := cp.GetParams(ctx)

pkg/provider/bitbucketcloud/bitbucket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (v *Provider) GetCommitInfo(_ context.Context, event *info.Event) error {
250250
event.SHATitle = commitinfo.Message
251251
event.SHAURL = commitinfo.Links.HTML.HRef
252252
event.SHA = commitinfo.Hash
253-
253+
event.HasSkipCommand = provider.SkipCI(commitinfo.Message)
254254
// now to get the default branch from repository.Get
255255
repo, err := v.Client().Repositories.Repository.Get(&bitbucket.RepositoryOptions{
256256
Owner: event.Organization,

pkg/provider/bitbucketdatacenter/bitbucketdatacenter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ func (v *Provider) GetCommitInfo(_ context.Context, event *info.Event) error {
339339
}
340340
event.SHATitle = sanitizeTitle(commit.Message)
341341
event.SHAURL = fmt.Sprintf("%s/projects/%s/repos/%s/commits/%s", v.baseURL, v.projectKey, event.Repository, event.SHA)
342+
event.HasSkipCommand = provider.SkipCI(commit.Message)
342343

343344
ref, _, err := v.Client().Git.GetDefaultBranch(context.Background(), OrgAndRepo)
344345
if err != nil {

pkg/provider/gitea/gitea.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ func (v *Provider) GetCommitInfo(_ context.Context, runevent *info.Event) error
377377
runevent.SHAURL = commit.HTMLURL
378378
runevent.SHATitle = strings.Split(commit.RepoCommit.Message, "\n\n")[0]
379379
runevent.SHA = commit.SHA
380+
runevent.HasSkipCommand = provider.SkipCI(commit.RepoCommit.Message)
381+
380382
return nil
381383
}
382384

pkg/provider/github/github.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ func (v *Provider) GetCommitInfo(ctx context.Context, runevent *info.Event) erro
406406
runevent.SHAURL = commit.GetHTMLURL()
407407
runevent.SHATitle = strings.Split(commit.GetMessage(), "\n\n")[0]
408408
runevent.SHA = commit.GetSHA()
409+
runevent.HasSkipCommand = provider.SkipCI(commit.GetMessage())
409410

410411
return nil
411412
}

pkg/provider/gitlab/gitlab.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ func (v *Provider) GetCommitInfo(_ context.Context, runevent *info.Event) error
477477
runevent.SHA = branchinfo.ID
478478
runevent.SHATitle = branchinfo.Title
479479
runevent.SHAURL = branchinfo.WebURL
480+
runevent.HasSkipCommand = provider.SkipCI(branchinfo.Message)
480481
}
481482

482483
return nil

pkg/provider/provider.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,22 @@ func GetCheckName(status StatusOpts, pacopts *info.PacOpts) string {
214214
func IsZeroSHA(sha string) bool {
215215
return sha == "0000000000000000000000000000000000000000"
216216
}
217+
218+
// These commands if present in the commit message will skip the CI.
219+
var skipCICommands = []string{
220+
"[skip ci]",
221+
"[ci skip]",
222+
"[skip tkn]",
223+
"[tkn skip]",
224+
}
225+
226+
// Skip CI returns true if the given commit message contains any skip command.
227+
func SkipCI(commitMessage string) bool {
228+
for _, command := range skipCICommands {
229+
if strings.Contains(commitMessage, command) {
230+
return true
231+
}
232+
}
233+
234+
return false
235+
}

0 commit comments

Comments
 (0)