mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-22 15:14:54 +08:00
add skip ci support for pull request title (#29774)
Extends #28075 to support [skip ci] inside PR titles. Close #29265
This commit is contained in:
parent
e79a807a84
commit
7a90e5954f
|
@ -2608,7 +2608,7 @@ LEVEL = Info
|
||||||
;ENDLESS_TASK_TIMEOUT = 3h
|
;ENDLESS_TASK_TIMEOUT = 3h
|
||||||
;; Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time
|
;; Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time
|
||||||
;ABANDONED_JOB_TIMEOUT = 24h
|
;ABANDONED_JOB_TIMEOUT = 24h
|
||||||
;; Strings committers can place inside a commit message to skip executing the corresponding actions workflow
|
;; Strings committers can place inside a commit message or PR title to skip executing the corresponding actions workflow
|
||||||
;SKIP_WORKFLOW_STRINGS = [skip ci],[ci skip],[no ci],[skip actions],[actions skip]
|
;SKIP_WORKFLOW_STRINGS = [skip ci],[ci skip],[no ci],[skip actions],[actions skip]
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
@ -1406,7 +1406,7 @@ PROXY_HOSTS = *.github.com
|
||||||
- `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time
|
- `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time
|
||||||
- `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time
|
- `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time
|
||||||
- `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
|
- `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
|
||||||
- `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
|
- `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
|
||||||
|
|
||||||
`DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path.
|
`DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path.
|
||||||
For example, `uses: actions/checkout@v4` means `https://github.com/actions/checkout@v4` since the value of `DEFAULT_ACTIONS_URL` is `github`.
|
For example, `uses: actions/checkout@v4` means `https://github.com/actions/checkout@v4` since the value of `DEFAULT_ACTIONS_URL` is `github`.
|
||||||
|
|
|
@ -157,7 +157,7 @@ func notify(ctx context.Context, input *notifyInput) error {
|
||||||
return fmt.Errorf("gitRepo.GetCommit: %w", err)
|
return fmt.Errorf("gitRepo.GetCommit: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if skipWorkflowsForCommit(input, commit) {
|
if skipWorkflows(input, commit) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,8 +223,8 @@ func notify(ctx context.Context, input *notifyInput) error {
|
||||||
return handleWorkflows(ctx, detectedWorkflows, commit, input, ref)
|
return handleWorkflows(ctx, detectedWorkflows, commit, input, ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
func skipWorkflowsForCommit(input *notifyInput, commit *git.Commit) bool {
|
func skipWorkflows(input *notifyInput, commit *git.Commit) bool {
|
||||||
// skip workflow runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync)
|
// skip workflow runs with a configured skip-ci string in commit message or pr title if the event is push or pull_request(_sync)
|
||||||
// https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
|
// https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
|
||||||
skipWorkflowEvents := []webhook_module.HookEventType{
|
skipWorkflowEvents := []webhook_module.HookEventType{
|
||||||
webhook_module.HookEventPush,
|
webhook_module.HookEventPush,
|
||||||
|
@ -233,6 +233,10 @@ func skipWorkflowsForCommit(input *notifyInput, commit *git.Commit) bool {
|
||||||
}
|
}
|
||||||
if slices.Contains(skipWorkflowEvents, input.Event) {
|
if slices.Contains(skipWorkflowEvents, input.Event) {
|
||||||
for _, s := range setting.Actions.SkipWorkflowStrings {
|
for _, s := range setting.Actions.SkipWorkflowStrings {
|
||||||
|
if input.PullRequest != nil && strings.Contains(input.PullRequest.Issue.Title, s) {
|
||||||
|
log.Debug("repo %s: skipped run for pr %v because of %s string", input.Repo.RepoPath(), input.PullRequest.Issue.ID, s)
|
||||||
|
return true
|
||||||
|
}
|
||||||
if strings.Contains(commit.CommitMessage, s) {
|
if strings.Contains(commit.CommitMessage, s) {
|
||||||
log.Debug("repo %s with commit %s: skipped run because of %s string", input.Repo.RepoPath(), commit.ID, s)
|
log.Debug("repo %s with commit %s: skipped run because of %s string", input.Repo.RepoPath(), commit.ID, s)
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
actions_module "code.gitea.io/gitea/modules/actions"
|
actions_module "code.gitea.io/gitea/modules/actions"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
pull_service "code.gitea.io/gitea/services/pull"
|
pull_service "code.gitea.io/gitea/services/pull"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
files_service "code.gitea.io/gitea/services/repository/files"
|
files_service "code.gitea.io/gitea/services/repository/files"
|
||||||
|
@ -199,6 +200,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
|
||||||
|
|
||||||
func TestSkipCI(t *testing.T) {
|
func TestSkipCI(t *testing.T) {
|
||||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||||
|
session := loginUser(t, "user2")
|
||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||||
|
|
||||||
// create the repo
|
// create the repo
|
||||||
|
@ -209,7 +211,7 @@ func TestSkipCI(t *testing.T) {
|
||||||
Gitignores: "Go",
|
Gitignores: "Go",
|
||||||
License: "MIT",
|
License: "MIT",
|
||||||
Readme: "Default",
|
Readme: "Default",
|
||||||
DefaultBranch: "main",
|
DefaultBranch: "master",
|
||||||
IsPrivate: false,
|
IsPrivate: false,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -228,12 +230,12 @@ func TestSkipCI(t *testing.T) {
|
||||||
{
|
{
|
||||||
Operation: "create",
|
Operation: "create",
|
||||||
TreePath: ".gitea/workflows/pr.yml",
|
TreePath: ".gitea/workflows/pr.yml",
|
||||||
ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
|
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"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Message: "add workflow",
|
Message: "add workflow",
|
||||||
OldBranch: "main",
|
OldBranch: "master",
|
||||||
NewBranch: "main",
|
NewBranch: "master",
|
||||||
Author: &files_service.IdentityOptions{
|
Author: &files_service.IdentityOptions{
|
||||||
Name: user2.Name,
|
Name: user2.Name,
|
||||||
Email: user2.Email,
|
Email: user2.Email,
|
||||||
|
@ -263,8 +265,8 @@ func TestSkipCI(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Message: fmt.Sprintf("%s add bar", setting.Actions.SkipWorkflowStrings[0]),
|
Message: fmt.Sprintf("%s add bar", setting.Actions.SkipWorkflowStrings[0]),
|
||||||
OldBranch: "main",
|
OldBranch: "master",
|
||||||
NewBranch: "main",
|
NewBranch: "master",
|
||||||
Author: &files_service.IdentityOptions{
|
Author: &files_service.IdentityOptions{
|
||||||
Name: user2.Name,
|
Name: user2.Name,
|
||||||
Email: user2.Email,
|
Email: user2.Email,
|
||||||
|
@ -283,5 +285,42 @@ func TestSkipCI(t *testing.T) {
|
||||||
|
|
||||||
// the commit message contains a configured skip-ci string, so there is still only 1 record
|
// the commit message contains a configured skip-ci string, so there is still only 1 record
|
||||||
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
||||||
|
|
||||||
|
// add file to new branch
|
||||||
|
addFileToBranchResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
|
||||||
|
Files: []*files_service.ChangeRepoFile{
|
||||||
|
{
|
||||||
|
Operation: "create",
|
||||||
|
TreePath: "test-skip-ci",
|
||||||
|
ContentReader: strings.NewReader("test-skip-ci"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Message: "add test file",
|
||||||
|
OldBranch: "master",
|
||||||
|
NewBranch: "test-skip-ci",
|
||||||
|
Author: &files_service.IdentityOptions{
|
||||||
|
Name: user2.Name,
|
||||||
|
Email: user2.Email,
|
||||||
|
},
|
||||||
|
Committer: &files_service.IdentityOptions{
|
||||||
|
Name: user2.Name,
|
||||||
|
Email: user2.Email,
|
||||||
|
},
|
||||||
|
Dates: &files_service.CommitDateOptions{
|
||||||
|
Author: time.Now(),
|
||||||
|
Committer: time.Now(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotEmpty(t, addFileToBranchResp)
|
||||||
|
|
||||||
|
resp := testPullCreate(t, session, "user2", "skip-ci", true, "master", "test-skip-ci", "[skip ci] test-skip-ci")
|
||||||
|
|
||||||
|
// check the redirected URL
|
||||||
|
url := test.RedirectURL(resp)
|
||||||
|
assert.Regexp(t, "^/user2/skip-ci/pulls/[0-9]*$", url)
|
||||||
|
|
||||||
|
// the pr title contains a configured skip-ci string, so there is still only 1 record
|
||||||
|
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user