mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-13 21:46:15 +01:00
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. (cherry picked from commit 96d31fe0a8b88c09488989cd5459d4124dcb7983)
This commit is contained in:
parent
a527f5a3e7
commit
e74865caba
2 changed files with 6 additions and 6 deletions
|
@ -44,6 +44,9 @@ func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error {
|
||||||
schedule.TriggerUser = user_model.NewActionsUser()
|
schedule.TriggerUser = user_model.NewActionsUser()
|
||||||
} else {
|
} else {
|
||||||
schedule.TriggerUser = users[schedule.TriggerUserID]
|
schedule.TriggerUser = users[schedule.TriggerUserID]
|
||||||
|
if schedule.TriggerUser == nil {
|
||||||
|
schedule.TriggerUser = user_model.NewGhostUser()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -560,12 +560,9 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need a notifyInput to call handleSchedules
|
// We need a notifyInput to call handleSchedules
|
||||||
// Here we use the commit author as the Doer of the notifyInput
|
// if repo is a mirror, commit author maybe an external user,
|
||||||
commitUser, err := user_model.GetUserByEmail(ctx, commit.Author.Email)
|
// so we use action user as the Doer of the notifyInput
|
||||||
if err != nil {
|
notifyInput := newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
|
||||||
return fmt.Errorf("get user by email: %w", err)
|
|
||||||
}
|
|
||||||
notifyInput := newNotifyInput(repo, commitUser, webhook_module.HookEventSchedule)
|
|
||||||
|
|
||||||
return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
|
return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue