]> source.dussan.org Git - gitea.git/commitdiff
Avoid user does not exist error when detecting schedule actions when the commit autho...
authorGiteabot <teabot@gitea.io>
Thu, 11 Apr 2024 07:51:02 +0000 (15:51 +0800)
committerGitHub <noreply@github.com>
Thu, 11 Apr 2024 07:51:02 +0000 (07:51 +0000)
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 <576951401@qq.com>
models/actions/schedule_list.go
services/actions/notifier_helper.go

index b806550b87d81387d196ee7f839829b61be1ab15..ecd2c1121c9825ab2e70c10f36ab3b5135e3b532 100644 (file)
@@ -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
index 8c98f56af53ef25b4ced69a15382faf156fd1589..c48886a8246eb5af589d45ff94763adf8cfa7d2c 100644 (file)
@@ -525,12 +525,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)
 }