loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request '[PORT] add skip ci support for pull request title (#29774)' (#2701) from earl-warren/forgejo:wip-gitea-skip-ci into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2701
Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>

+57 -11
+1 -1
custom/conf/app.example.ini
··· 2623 2623 ;ENDLESS_TASK_TIMEOUT = 3h 2624 2624 ;; Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time 2625 2625 ;ABANDONED_JOB_TIMEOUT = 24h 2626 - ;; Strings committers can place inside a commit message to skip executing the corresponding actions workflow 2626 + ;; Strings committers can place inside a commit message or PR title to skip executing the corresponding actions workflow 2627 2627 ;SKIP_WORKFLOW_STRINGS = [skip ci],[ci skip],[no ci],[skip actions],[actions skip] 2628 2628 2629 2629 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+1 -1
docs/content/administration/config-cheat-sheet.en-us.md
··· 1422 1422 - `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time 1423 1423 - `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time 1424 1424 - `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 1425 - - `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 1425 + - `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 1426 1426 1427 1427 `DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path. 1428 1428 For example, `uses: actions/checkout@v4` means `https://github.com/actions/checkout@v4` since the value of `DEFAULT_ACTIONS_URL` is `github`.
+7 -3
services/actions/notifier_helper.go
··· 154 154 return fmt.Errorf("gitRepo.GetCommit: %w", err) 155 155 } 156 156 157 - if skipWorkflowsForCommit(input, commit) { 157 + if skipWorkflows(input, commit) { 158 158 return nil 159 159 } 160 160 ··· 232 232 return exist 233 233 } 234 234 235 - func skipWorkflowsForCommit(input *notifyInput, commit *git.Commit) bool { 236 - // skip workflow runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync) 235 + func skipWorkflows(input *notifyInput, commit *git.Commit) bool { 236 + // skip workflow runs with a configured skip-ci string in commit message or pr title if the event is push or pull_request(_sync) 237 237 // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs 238 238 skipWorkflowEvents := []webhook_module.HookEventType{ 239 239 webhook_module.HookEventPush, ··· 242 242 } 243 243 if slices.Contains(skipWorkflowEvents, input.Event) { 244 244 for _, s := range setting.Actions.SkipWorkflowStrings { 245 + if input.PullRequest != nil && strings.Contains(input.PullRequest.Issue.Title, s) { 246 + log.Debug("repo %s: skipped run for pr %v because of %s string", input.Repo.RepoPath(), input.PullRequest.Issue.ID, s) 247 + return true 248 + } 245 249 if strings.Contains(commit.CommitMessage, s) { 246 250 log.Debug("repo %s with commit %s: skipped run because of %s string", input.Repo.RepoPath(), commit.ID, s) 247 251 return true
+40 -1
tests/integration/actions_trigger_test.go
··· 18 18 actions_module "code.gitea.io/gitea/modules/actions" 19 19 "code.gitea.io/gitea/modules/git" 20 20 "code.gitea.io/gitea/modules/setting" 21 + "code.gitea.io/gitea/modules/test" 21 22 webhook_module "code.gitea.io/gitea/modules/webhook" 22 23 actions_service "code.gitea.io/gitea/services/actions" 23 24 pull_service "code.gitea.io/gitea/services/pull" ··· 186 187 187 188 func TestSkipCI(t *testing.T) { 188 189 onGiteaRun(t, func(t *testing.T, u *url.URL) { 190 + session := loginUser(t, "user2") 189 191 user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 190 192 191 193 // create the repo ··· 195 197 { 196 198 Operation: "create", 197 199 TreePath: ".gitea/workflows/pr.yml", 198 - ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"), 200 + 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"), 199 201 }, 200 202 }, 201 203 ) ··· 233 235 assert.NotEmpty(t, addFileResp) 234 236 235 237 // the commit message contains a configured skip-ci string, so there is still only 1 record 238 + assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID})) 239 + 240 + // add file to new branch 241 + addFileToBranchResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ 242 + Files: []*files_service.ChangeRepoFile{ 243 + { 244 + Operation: "create", 245 + TreePath: "test-skip-ci", 246 + ContentReader: strings.NewReader("test-skip-ci"), 247 + }, 248 + }, 249 + Message: "add test file", 250 + OldBranch: "main", 251 + NewBranch: "test-skip-ci", 252 + Author: &files_service.IdentityOptions{ 253 + Name: user2.Name, 254 + Email: user2.Email, 255 + }, 256 + Committer: &files_service.IdentityOptions{ 257 + Name: user2.Name, 258 + Email: user2.Email, 259 + }, 260 + Dates: &files_service.CommitDateOptions{ 261 + Author: time.Now(), 262 + Committer: time.Now(), 263 + }, 264 + }) 265 + assert.NoError(t, err) 266 + assert.NotEmpty(t, addFileToBranchResp) 267 + 268 + resp := testPullCreate(t, session, "user2", "skip-ci", true, "main", "test-skip-ci", "[skip ci] test-skip-ci") 269 + 270 + // check the redirected URL 271 + url := test.RedirectURL(resp) 272 + assert.Regexp(t, "^/user2/skip-ci/pulls/[0-9]*$", url) 273 + 274 + // the pr title contains a configured skip-ci string, so there is still only 1 record 236 275 assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID})) 237 276 }) 238 277 }
+8 -5
tests/integration/pull_create_test.go
··· 10 10 "net/http/httptest" 11 11 "net/url" 12 12 "path" 13 + "regexp" 13 14 "strings" 14 15 "testing" 15 16 ··· 42 43 link = strings.Replace(link, targetUser, user, 1) 43 44 } 44 45 45 - if targetBranch != "master" { 46 - link = strings.Replace(link, "master...", targetBranch+"...", 1) 46 + // get main out of /user/project/main...some:other/branch 47 + defaultBranch := regexp.MustCompile(`^.*/(.*)\.\.\.`).FindStringSubmatch(link)[1] 48 + if targetBranch != defaultBranch { 49 + link = strings.Replace(link, defaultBranch+"...", targetBranch+"...", 1) 47 50 } 48 - if sourceBranch != "master" { 51 + if sourceBranch != defaultBranch { 49 52 if targetUser == user { 50 - link = strings.Replace(link, "...master", "..."+sourceBranch, 1) 53 + link = strings.Replace(link, "..."+defaultBranch, "..."+sourceBranch, 1) 51 54 } else { 52 - link = strings.Replace(link, ":master", ":"+sourceBranch, 1) 55 + link = strings.Replace(link, ":"+defaultBranch, ":"+sourceBranch, 1) 53 56 } 54 57 } 55 58