Make GetPossibleUserByID can handle deleted user (#37430)

Make sure deleted user won't cause 500 error, simplify the caller's code
This commit is contained in:
wxiaoguang
2026-04-27 00:57:53 +08:00
committed by GitHub
parent 2f42c8cf72
commit 068b59aa97
11 changed files with 36 additions and 74 deletions
+2 -3
View File
@@ -120,7 +120,7 @@ func (run *ActionRun) RefTooltip() string {
}
// LoadAttributes load Repo TriggerUser if not loaded
func (run *ActionRun) LoadAttributes(ctx context.Context) error {
func (run *ActionRun) LoadAttributes(ctx context.Context) (err error) {
if run == nil {
return nil
}
@@ -134,11 +134,10 @@ func (run *ActionRun) LoadAttributes(ctx context.Context) error {
}
if run.TriggerUser == nil {
u, err := user_model.GetPossibleUserByID(ctx, run.TriggerUserID)
run.TriggerUserID, run.TriggerUser, err = user_model.GetPossibleUserByID(ctx, run.TriggerUserID)
if err != nil {
return err
}
run.TriggerUser = u
}
return nil
+2 -3
View File
@@ -50,7 +50,7 @@ func (attempt *ActionRunAttempt) Duration() time.Duration {
return calculateDuration(attempt.Started, attempt.Stopped, attempt.Status, attempt.Updated)
}
func (attempt *ActionRunAttempt) LoadAttributes(ctx context.Context) error {
func (attempt *ActionRunAttempt) LoadAttributes(ctx context.Context) (err error) {
if attempt == nil {
return nil
}
@@ -67,11 +67,10 @@ func (attempt *ActionRunAttempt) LoadAttributes(ctx context.Context) error {
}
if attempt.TriggerUser == nil {
u, err := user_model.GetPossibleUserByID(ctx, attempt.TriggerUserID)
attempt.TriggerUserID, attempt.TriggerUser, err = user_model.GetPossibleUserByID(ctx, attempt.TriggerUserID)
if err != nil {
return err
}
attempt.TriggerUser = u
}
return nil