]> source.dussan.org Git - gitea.git/commitdiff
Use action user as the trigger user of schedules (#30581) (#30609)
authorGiteabot <teabot@gitea.io>
Sat, 20 Apr 2024 02:46:17 +0000 (10:46 +0800)
committerGitHub <noreply@github.com>
Sat, 20 Apr 2024 02:46:17 +0000 (10:46 +0800)
Backport #30581 by @yp05327

Follow https://github.com/go-gitea/gitea/pull/30357

When user push to default branch, the schedule trigger user will be the
user.
When disable then enable action units in settings, the schedule trigger
user will be action user.
When repo is a mirror, the schedule trigger user will be action user. (
before it will return error, fixed by #30357)

As scheduled job is a cron, the trigger user should be action user from
Gitea, not a real user.

Co-authored-by: yp05327 <576951401@qq.com>
services/actions/notifier_helper.go

index 4e3df4bbb38c1f2f8bfb33f2cab7186ba9effe52..2296e14a88e123235a28226383f4eee1a2389b8e 100644 (file)
@@ -74,6 +74,11 @@ func newNotifyInput(repo *repo_model.Repository, doer *user_model.User, event we
        }
 }
 
+func newNotifyInputForSchedules(repo *repo_model.Repository) *notifyInput {
+       // the doer here will be ignored as we force using action user when handling schedules
+       return newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
+}
+
 func (input *notifyInput) WithDoer(doer *user_model.User) *notifyInput {
        input.Doer = doer
        return input
@@ -454,7 +459,7 @@ func handleSchedules(
                        RepoID:        input.Repo.ID,
                        OwnerID:       input.Repo.OwnerID,
                        WorkflowID:    dwf.EntryName,
-                       TriggerUserID: input.Doer.ID,
+                       TriggerUserID: user_model.ActionsUserID,
                        Ref:           ref,
                        CommitSHA:     commit.ID.String(),
                        Event:         input.Event,
@@ -496,7 +501,7 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
        // We need a notifyInput to call handleSchedules
        // if repo is a mirror, commit author maybe an external user,
        // so we use action user as the Doer of the notifyInput
-       notifyInput := newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
+       notifyInput := newNotifyInputForSchedules(repo)
 
        return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
 }