From e74865cabae8c8c1919a8c7ffed1dda39d98bc37 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 11 Apr 2024 16:11:32 +0900 Subject: [PATCH] Avoid user does not exist error when detecting schedule actions when the commit author is an external user (#30357) ![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. (cherry picked from commit 96d31fe0a8b88c09488989cd5459d4124dcb7983) --- models/actions/schedule_list.go | 3 +++ services/actions/notifier_helper.go | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/models/actions/schedule_list.go b/models/actions/schedule_list.go index b806550b87..ecd2c1121c 100644 --- a/models/actions/schedule_list.go +++ b/models/actions/schedule_list.go @@ -44,6 +44,9 @@ func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error { schedule.TriggerUser = user_model.NewActionsUser() } else { schedule.TriggerUser = users[schedule.TriggerUserID] + if schedule.TriggerUser == nil { + schedule.TriggerUser = user_model.NewGhostUser() + } } } return nil diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 5d1e2c122b..ef37ff87ee 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -560,12 +560,9 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository) } // We need a notifyInput to call handleSchedules - // Here we use the commit author as the Doer of the notifyInput - commitUser, err := user_model.GetUserByEmail(ctx, commit.Author.Email) - if err != nil { - return fmt.Errorf("get user by email: %w", err) - } - notifyInput := newNotifyInput(repo, commitUser, webhook_module.HookEventSchedule) + // 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) return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch) }