add skip ci support for pull request title (#29774)

Extends #28075 to support [skip ci] inside PR titles.

Close #29265

(cherry picked from commit 7a90e5954f8515329f20ff0e391130e1ee7b8864)

Conflicts:
	services/actions/notifier_helper.go
	tests/integration/actions_trigger_test.go
	conflicts easily resolved because of
	[TESTS] Convert more tests to CreateDeclarativeRepo
	[ACTIONS] skip superflous pull request synchronized event (#2314)
This commit is contained in:
Denys Konovalov 2024-03-14 04:18:04 +01:00 committed by Earl Warren
parent 4c40a261d5
commit d3d0c4cbe7
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 49 additions and 6 deletions

View file

@ -18,6 +18,7 @@ import (
actions_module "code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
webhook_module "code.gitea.io/gitea/modules/webhook"
actions_service "code.gitea.io/gitea/services/actions"
pull_service "code.gitea.io/gitea/services/pull"
@ -186,6 +187,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
func TestSkipCI(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
session := loginUser(t, "user2")
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
// create the repo
@ -195,7 +197,7 @@ func TestSkipCI(t *testing.T) {
{
Operation: "create",
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: [main]\n pull_request:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
},
},
)
@ -234,5 +236,42 @@ func TestSkipCI(t *testing.T) {
// 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}))
// 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: "main",
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, "main", "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}))
})
}