Skip to content

Commit 7a90e59

Browse files
authored
add skip ci support for pull request title (#29774)
Extends #28075 to support [skip ci] inside PR titles. Close #29265
1 parent e79a807 commit 7a90e59

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

custom/conf/app.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2608,7 +2608,7 @@ LEVEL = Info
26082608
;ENDLESS_TASK_TIMEOUT = 3h
26092609
;; Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time
26102610
;ABANDONED_JOB_TIMEOUT = 24h
2611-
;; Strings committers can place inside a commit message to skip executing the corresponding actions workflow
2611+
;; Strings committers can place inside a commit message or PR title to skip executing the corresponding actions workflow
26122612
;SKIP_WORKFLOW_STRINGS = [skip ci],[ci skip],[no ci],[skip actions],[actions skip]
26132613

26142614
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ PROXY_HOSTS = *.github.com
14061406
- `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time
14071407
- `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time
14081408
- `ABANDONED_JOB_TIMEOUT`: **24h**: Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time
1409-
- `SKIP_WORKFLOW_STRINGS`: **[skip ci],[ci skip],[no ci],[skip actions],[actions skip]**: Strings committers can place inside a commit message to skip executing the corresponding actions workflow
1409+
- `SKIP_WORKFLOW_STRINGS`: **[skip ci],[ci skip],[no ci],[skip actions],[actions skip]**: Strings committers can place inside a commit message or PR title to skip executing the corresponding actions workflow
14101410

14111411
`DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path.
14121412
For example, `uses: actions/checkout@v4` means `https://github.com/actions/checkout@v4` since the value of `DEFAULT_ACTIONS_URL` is `github`.

services/actions/notifier_helper.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func notify(ctx context.Context, input *notifyInput) error {
157157
return fmt.Errorf("gitRepo.GetCommit: %w", err)
158158
}
159159

160-
if skipWorkflowsForCommit(input, commit) {
160+
if skipWorkflows(input, commit) {
161161
return nil
162162
}
163163

@@ -223,8 +223,8 @@ func notify(ctx context.Context, input *notifyInput) error {
223223
return handleWorkflows(ctx, detectedWorkflows, commit, input, ref)
224224
}
225225

226-
func skipWorkflowsForCommit(input *notifyInput, commit *git.Commit) bool {
227-
// skip workflow runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync)
226+
func skipWorkflows(input *notifyInput, commit *git.Commit) bool {
227+
// skip workflow runs with a configured skip-ci string in commit message or pr title if the event is push or pull_request(_sync)
228228
// https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
229229
skipWorkflowEvents := []webhook_module.HookEventType{
230230
webhook_module.HookEventPush,
@@ -233,6 +233,10 @@ func skipWorkflowsForCommit(input *notifyInput, commit *git.Commit) bool {
233233
}
234234
if slices.Contains(skipWorkflowEvents, input.Event) {
235235
for _, s := range setting.Actions.SkipWorkflowStrings {
236+
if input.PullRequest != nil && strings.Contains(input.PullRequest.Issue.Title, s) {
237+
log.Debug("repo %s: skipped run for pr %v because of %s string", input.Repo.RepoPath(), input.PullRequest.Issue.ID, s)
238+
return true
239+
}
236240
if strings.Contains(commit.CommitMessage, s) {
237241
log.Debug("repo %s with commit %s: skipped run because of %s string", input.Repo.RepoPath(), commit.ID, s)
238242
return true

tests/integration/actions_trigger_test.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
actions_module "code.gitea.io/gitea/modules/actions"
2121
"code.gitea.io/gitea/modules/git"
2222
"code.gitea.io/gitea/modules/setting"
23+
"code.gitea.io/gitea/modules/test"
2324
pull_service "code.gitea.io/gitea/services/pull"
2425
repo_service "code.gitea.io/gitea/services/repository"
2526
files_service "code.gitea.io/gitea/services/repository/files"
@@ -199,6 +200,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
199200

200201
func TestSkipCI(t *testing.T) {
201202
onGiteaRun(t, func(t *testing.T, u *url.URL) {
203+
session := loginUser(t, "user2")
202204
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
203205

204206
// create the repo
@@ -209,7 +211,7 @@ func TestSkipCI(t *testing.T) {
209211
Gitignores: "Go",
210212
License: "MIT",
211213
Readme: "Default",
212-
DefaultBranch: "main",
214+
DefaultBranch: "master",
213215
IsPrivate: false,
214216
})
215217
assert.NoError(t, err)
@@ -228,12 +230,12 @@ func TestSkipCI(t *testing.T) {
228230
{
229231
Operation: "create",
230232
TreePath: ".gitea/workflows/pr.yml",
231-
ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
233+
ContentReader: strings.NewReader("name: test\non:\n push:\n branches: [master]\n pull_request:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
232234
},
233235
},
234236
Message: "add workflow",
235-
OldBranch: "main",
236-
NewBranch: "main",
237+
OldBranch: "master",
238+
NewBranch: "master",
237239
Author: &files_service.IdentityOptions{
238240
Name: user2.Name,
239241
Email: user2.Email,
@@ -263,8 +265,8 @@ func TestSkipCI(t *testing.T) {
263265
},
264266
},
265267
Message: fmt.Sprintf("%s add bar", setting.Actions.SkipWorkflowStrings[0]),
266-
OldBranch: "main",
267-
NewBranch: "main",
268+
OldBranch: "master",
269+
NewBranch: "master",
268270
Author: &files_service.IdentityOptions{
269271
Name: user2.Name,
270272
Email: user2.Email,
@@ -283,5 +285,42 @@ func TestSkipCI(t *testing.T) {
283285

284286
// the commit message contains a configured skip-ci string, so there is still only 1 record
285287
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
288+
289+
// add file to new branch
290+
addFileToBranchResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
291+
Files: []*files_service.ChangeRepoFile{
292+
{
293+
Operation: "create",
294+
TreePath: "test-skip-ci",
295+
ContentReader: strings.NewReader("test-skip-ci"),
296+
},
297+
},
298+
Message: "add test file",
299+
OldBranch: "master",
300+
NewBranch: "test-skip-ci",
301+
Author: &files_service.IdentityOptions{
302+
Name: user2.Name,
303+
Email: user2.Email,
304+
},
305+
Committer: &files_service.IdentityOptions{
306+
Name: user2.Name,
307+
Email: user2.Email,
308+
},
309+
Dates: &files_service.CommitDateOptions{
310+
Author: time.Now(),
311+
Committer: time.Now(),
312+
},
313+
})
314+
assert.NoError(t, err)
315+
assert.NotEmpty(t, addFileToBranchResp)
316+
317+
resp := testPullCreate(t, session, "user2", "skip-ci", true, "master", "test-skip-ci", "[skip ci] test-skip-ci")
318+
319+
// check the redirected URL
320+
url := test.RedirectURL(resp)
321+
assert.Regexp(t, "^/user2/skip-ci/pulls/[0-9]*$", url)
322+
323+
// the pr title contains a configured skip-ci string, so there is still only 1 record
324+
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
286325
})
287326
}

0 commit comments

Comments
 (0)