Skip to content

Commit 96d31fe

Browse files
authored
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.
1 parent f3cc006 commit 96d31fe

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

models/actions/schedule_list.go

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error {
4040
schedule.TriggerUser = user_model.NewActionsUser()
4141
} else {
4242
schedule.TriggerUser = users[schedule.TriggerUserID]
43+
if schedule.TriggerUser == nil {
44+
schedule.TriggerUser = user_model.NewGhostUser()
45+
}
4346
}
4447
}
4548
return nil

services/actions/notifier_helper.go

+3-6
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)