Skip to content

Commit 245e8d1

Browse files
GiteaBotyp05327
andauthored
Avoid user does not exist error when detecting schedule actions when the commit author is an external user (#30357) (#30408)
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 529604a commit 245e8d1

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
@@ -494,12 +494,9 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
494494
}
495495

496496
// We need a notifyInput to call handleSchedules
497-
// Here we use the commit author as the Doer of the notifyInput
498-
commitUser, err := user_model.GetUserByEmail(ctx, commit.Author.Email)
499-
if err != nil {
500-
return fmt.Errorf("get user by email: %w", err)
501-
}
502-
notifyInput := newNotifyInput(repo, commitUser, webhook_module.HookEventSchedule)
497+
// if repo is a mirror, commit author maybe an external user,
498+
// so we use action user as the Doer of the notifyInput
499+
notifyInput := newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
503500

504501
return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
505502
}

0 commit comments

Comments
 (0)