Skip to content

Commit a210fa4

Browse files
yp05327GiteaBot
andcommitted
Use action user as the trigger user of schedules (go-gitea#30581)
Follow go-gitea#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 go-gitea#30357) As scheduled job is a cron, the trigger user should be action user from Gitea, not a real user. --------- Co-authored-by: Giteabot <[email protected]>
1 parent 7eaf790 commit a210fa4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

services/actions/notifier_helper.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ func newNotifyInput(repo *repo_model.Repository, doer *user_model.User, event we
7878
}
7979
}
8080

81+
func newNotifyInputForSchedules(repo *repo_model.Repository) *notifyInput {
82+
// the doer here will be ignored as we force using action user when handling schedules
83+
return newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
84+
}
85+
8186
func (input *notifyInput) WithDoer(doer *user_model.User) *notifyInput {
8287
input.Doer = doer
8388
return input
@@ -485,7 +490,7 @@ func handleSchedules(
485490
RepoID: input.Repo.ID,
486491
OwnerID: input.Repo.OwnerID,
487492
WorkflowID: dwf.EntryName,
488-
TriggerUserID: input.Doer.ID,
493+
TriggerUserID: user_model.ActionsUserID,
489494
Ref: ref,
490495
CommitSHA: commit.ID.String(),
491496
Event: input.Event,
@@ -527,7 +532,7 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
527532
// We need a notifyInput to call handleSchedules
528533
// if repo is a mirror, commit author maybe an external user,
529534
// so we use action user as the Doer of the notifyInput
530-
notifyInput := newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
535+
notifyInput := newNotifyInputForSchedules(repo)
531536

532537
return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
533538
}

0 commit comments

Comments
 (0)