From 775174f08bb4d73dafe303782cb36adada7dae47 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 9 Apr 2024 08:19:54 +0000 Subject: [PATCH 1/3] fix --- models/actions/schedule_list.go | 3 +++ services/actions/notifier_helper.go | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/models/actions/schedule_list.go b/models/actions/schedule_list.go index b806550b87d81..ecd2c1121c982 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 8c98f56af53ef..04736f61c62b4 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -528,7 +528,11 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository) // 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) + if user_model.IsErrUserNotExist(err) { + commitUser = user_model.NewReplaceUser(commit.Author.Name) + } else { + return fmt.Errorf("get user by email: %w", err) + } } notifyInput := newNotifyInput(repo, commitUser, webhook_module.HookEventSchedule) From 463cf71730cea6af972f188bebccb47ecf3b73df Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 10 Apr 2024 03:01:11 +0000 Subject: [PATCH 2/3] improve fix --- services/actions/notifier_helper.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 04736f61c62b4..a4a083bb9e121 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -525,16 +525,12 @@ 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 { - if user_model.IsErrUserNotExist(err) { - commitUser = user_model.NewReplaceUser(commit.Author.Name) - } else { - return fmt.Errorf("get user by email: %w", err) - } + // if repo is a mirror, commit author maybe external user, + // so we need to use the repo owner as the Doer of the notifyInput + if err := repo.LoadOwner(ctx); err != nil { + return err } - notifyInput := newNotifyInput(repo, commitUser, webhook_module.HookEventSchedule) + notifyInput := newNotifyInput(repo, repo.Owner, webhook_module.HookEventSchedule) return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch) } From 000e27a56fc86d4e2be42b9b942d7ea19b020c8b Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 10 Apr 2024 04:07:02 +0000 Subject: [PATCH 3/3] convert to using action user --- services/actions/notifier_helper.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index a4a083bb9e121..c48886a8246eb 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -525,12 +525,9 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository) } // We need a notifyInput to call handleSchedules - // if repo is a mirror, commit author maybe external user, - // so we need to use the repo owner as the Doer of the notifyInput - if err := repo.LoadOwner(ctx); err != nil { - return err - } - notifyInput := newNotifyInput(repo, repo.Owner, 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) }