Skip to content

Commit

Permalink
Avoid user does not exist error when detecting schedule actions when …
Browse files Browse the repository at this point in the history
…the commit author is an external user (go-gitea#30357) (go-gitea#30409)

Backport go-gitea#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 go-gitea#24706, it only fixed normal runs, not scheduled runs.

Co-authored-by: yp05327 <[email protected]>
  • Loading branch information
GiteaBot and yp05327 authored Apr 11, 2024
1 parent 40f1f77 commit 69cc791
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 3 additions & 0 deletions models/actions/schedule_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions services/actions/notifier_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 69cc791

Please sign in to comment.