aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorDenys Konovalov <kontakt@denyskon.de>2023-11-18 12:37:08 +0100
committerGitHub <noreply@github.com>2023-11-18 13:37:08 +0200
commit816e46ee7ce4b2649479554a940ecbe1cc505a3d (patch)
treecc00f0fa563bde5fe6706659b0a102eb4799577a /services
parente88377470a05f7b57a5f421f7af7c03ed66e7983 (diff)
downloadgitea-816e46ee7ce4b2649479554a940ecbe1cc505a3d.tar.gz
gitea-816e46ee7ce4b2649479554a940ecbe1cc505a3d.zip
add skip ci functionality (#28075)
Adds the possibility to skip workflow execution if the commit message contains a string like [skip ci] or similar. The default strings are the same as on GitHub, users can also set custom ones in app.ini Reference: https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs Close #28020
Diffstat (limited to 'services')
-rw-r--r--services/actions/notifier_helper.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go
index 7d5f6c6c0a..1c08cec007 100644
--- a/services/actions/notifier_helper.go
+++ b/services/actions/notifier_helper.go
@@ -7,6 +7,7 @@ import (
"bytes"
"context"
"fmt"
+ "slices"
"strings"
actions_model "code.gitea.io/gitea/models/actions"
@@ -20,6 +21,7 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/convert"
@@ -144,6 +146,10 @@ func notify(ctx context.Context, input *notifyInput) error {
return fmt.Errorf("gitRepo.GetCommit: %w", err)
}
+ if skipWorkflowsForCommit(input, commit) {
+ return nil
+ }
+
var detectedWorkflows []*actions_module.DetectedWorkflow
actionsConfig := input.Repo.MustGetUnit(ctx, unit_model.TypeActions).ActionsConfig()
workflows, schedules, err := actions_module.DetectWorkflows(gitRepo, commit, input.Event, input.Payload)
@@ -195,6 +201,25 @@ func notify(ctx context.Context, input *notifyInput) error {
return handleWorkflows(ctx, detectedWorkflows, commit, input, ref)
}
+func skipWorkflowsForCommit(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)
+ // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
+ skipWorkflowEvents := []webhook_module.HookEventType{
+ webhook_module.HookEventPush,
+ webhook_module.HookEventPullRequest,
+ webhook_module.HookEventPullRequestSync,
+ }
+ if slices.Contains(skipWorkflowEvents, input.Event) {
+ for _, s := range setting.Actions.SkipWorkflowStrings {
+ 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)
+ return true
+ }
+ }
+ }
+ return false
+}
+
func handleWorkflows(
ctx context.Context,
detectedWorkflows []*actions_module.DetectedWorkflow,