diff --git a/models/actions/run.go b/models/actions/run.go index a9c458c86d..5185eb28bd 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -153,7 +153,9 @@ func (run *ActionRun) LoadAttributes(ctx context.Context) error { if run.TriggerUser == nil { u, err := user_model.GetPossibleUserByID(ctx, run.TriggerUserID) - if err != nil { + if user_model.IsErrUserNotExist(err) { + u = user_model.NewGhostUser() + } else if err != nil { return err } run.TriggerUser = u diff --git a/models/actions/run_test.go b/models/actions/run_test.go index 9a5eb99537..f8b2c9fb2d 100644 --- a/models/actions/run_test.go +++ b/models/actions/run_test.go @@ -19,9 +19,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestGetRunBefore(t *testing.T) { -} - func TestSetConcurrencyGroup(t *testing.T) { run := ActionRun{} run.SetConcurrencyGroup("abc123") @@ -686,3 +683,12 @@ jobs: assert.Zero(t, insertedJobs[1].TaskID) assert.Equal(t, StatusWaiting, insertedJobs[1].Status) } + +func TestActionRunLoadAttributes(t *testing.T) { + run := &ActionRun{ + RepoID: 10, + TriggerUserID: 1000, + } + require.NoError(t, run.LoadAttributes(t.Context())) + assert.Equal(t, "ghost", run.TriggerUser.LowerName) +}