Skip to content

Commit 69cc791

Browse files
GiteaBotyp05327
andauthored
Avoid user does not exist error when detecting schedule actions when the commit author is an external user (#30357) (#30409)
Backport #30357 by @yp05327 ![image](https://github.com/go-gitea/gitea/assets/18380374/ddf6ee84-2242-49b9-b066-bd8429ba4d76) When repo is a mirror, and commit author is an external user, then `GetUserByEmail` will return error. reproduce/test: - mirror Gitea to your instance - disable action and enable it again, this will trigger `DetectAndHandleSchedules` ps: also follow #24706, it only fixed normal runs, not scheduled runs. Co-authored-by: yp05327 <[email protected]>
1 parent 40f1f77 commit 69cc791

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

models/actions/schedule_list.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error {
4444
schedule.TriggerUser = user_model.NewActionsUser()
4545
} else {
4646
schedule.TriggerUser = users[schedule.TriggerUserID]
47+
if schedule.TriggerUser == nil {
48+
schedule.TriggerUser = user_model.NewGhostUser()
49+
}
4750
}
4851
}
4952
return nil

services/actions/notifier_helper.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,9 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
525525
}
526526

527527
// We need a notifyInput to call handleSchedules
528-
// Here we use the commit author as the Doer of the notifyInput
529-
commitUser, err := user_model.GetUserByEmail(ctx, commit.Author.Email)
530-
if err != nil {
531-
return fmt.Errorf("get user by email: %w", err)
532-
}
533-
notifyInput := newNotifyInput(repo, commitUser, webhook_module.HookEventSchedule)
528+
// if repo is a mirror, commit author maybe an external user,
529+
// so we use action user as the Doer of the notifyInput
530+
notifyInput := newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
534531

535532
return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
536533
}

0 commit comments

Comments
 (0)