mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-01 20:59:45 +09:00
Co-authored-by: JerryLien <jerrylien0801@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user