diff --git a/models/actions/run.go b/models/actions/run.go index f6c1e005373..2ca797b8f33 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -295,9 +295,8 @@ func GetRunByRepoAndID(ctx context.Context, repoID, runID int64) (*ActionRun, er return &run, nil } -func GetRunsByRepoAndID(ctx context.Context, repoID int64, runIDs []int64) ([]*ActionRun, error) { - var runs []*ActionRun - err := db.GetEngine(ctx).In("id", runIDs).Where("repo_id=?", repoID).Find(&runs) +func GetRunsByRepoAndID(ctx context.Context, repoID int64, runIDs []int64) (runs []*ActionRun, err error) { + err = db.GetEngine(ctx).In("id", runIDs).Where("repo_id=?", repoID).OrderBy("id").Find(&runs) return runs, err } diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 57cb60e8b91..4cb4c687ab5 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -642,7 +642,15 @@ func (data *actionRunListData) preparePartialRefreshRuns(ctx *context.Context) b ctx.ServerError("GetRunsByRepoAndID", err) return false } - data.ActionRuns = runs + runsMap := make(map[int64]*actions_model.ActionRun, len(runs)) + for _, run := range runs { + runsMap[run.ID] = run + } + for _, id := range data.refreshRunIDs { + if run, ok := runsMap[id]; ok { + data.ActionRuns = append(data.ActionRuns, run) + } + } return true } diff --git a/routers/web/repo/actions/actions_test.go b/routers/web/repo/actions/actions_test.go index 7d4bebf0073..5950af8385a 100644 --- a/routers/web/repo/actions/actions_test.go +++ b/routers/web/repo/actions/actions_test.go @@ -15,6 +15,7 @@ import ( "gitea.dev/modules/setting" "gitea.dev/modules/test" web_context "gitea.dev/services/context" + "gitea.dev/services/contexttest" "github.com/stretchr/testify/assert" ) @@ -74,3 +75,17 @@ func newWorkflowBadgeTestContext(t *testing.T) *web_context.Context { } return ctx } + +func TestActionRunListData(t *testing.T) { + unittest.PrepareTestEnv(t) + t.Run("preparePartialRefreshRuns", func(t *testing.T) { + ctx, _ := contexttest.MockContext(t, "user5/repo4/actions") + contexttest.LoadRepo(t, ctx, 4) + d := &actionRunListData{refreshRunIDs: []int64{791, 792}} + d.preparePartialRefreshRuns(ctx) + assert.Equal(t, []int64{791, 792}, []int64{d.ActionRuns[0].ID, d.ActionRuns[1].ID}) + d = &actionRunListData{refreshRunIDs: []int64{792, 791}} + d.preparePartialRefreshRuns(ctx) + assert.Equal(t, []int64{792, 791}, []int64{d.ActionRuns[0].ID, d.ActionRuns[1].ID}) + }) +}