Skip to content

Commit 0e20ccf

Browse files
GiteaBotyp05327
andauthored
Use action user as the trigger user of schedules (#30581) (#30609)
Backport #30581 by @yp05327 Follow #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 <[email protected]>
1 parent 0882265 commit 0e20ccf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

services/actions/notifier_helper.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func newNotifyInput(repo *repo_model.Repository, doer *user_model.User, event we
7474
}
7575
}
7676

77+
func newNotifyInputForSchedules(repo *repo_model.Repository) *notifyInput {
78+
// the doer here will be ignored as we force using action user when handling schedules
79+
return newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
80+
}
81+
7782
func (input *notifyInput) WithDoer(doer *user_model.User) *notifyInput {
7883
input.Doer = doer
7984
return input
@@ -454,7 +459,7 @@ func handleSchedules(
454459
RepoID: input.Repo.ID,
455460
OwnerID: input.Repo.OwnerID,
456461
WorkflowID: dwf.EntryName,
457-
TriggerUserID: input.Doer.ID,
462+
TriggerUserID: user_model.ActionsUserID,
458463
Ref: ref,
459464
CommitSHA: commit.ID.String(),
460465
Event: input.Event,
@@ -496,7 +501,7 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
496501
// We need a notifyInput to call handleSchedules
497502
// if repo is a mirror, commit author maybe an external user,
498503
// so we use action user as the Doer of the notifyInput
499-
notifyInput := newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
504+
notifyInput := newNotifyInputForSchedules(repo)
500505

501506
return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
502507
}

0 commit comments

Comments
 (0)