Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.dev/models/db"
|
|
user_model "gitea.dev/models/user"
|
|
"gitea.dev/modules/container"
|
|
)
|
|
|
|
type ActionRunAttemptList []*ActionRunAttempt
|
|
|
|
// GetUserIDs returns a slice of user's id
|
|
func (attempts ActionRunAttemptList) GetUserIDs() []int64 {
|
|
return container.FilterSlice(attempts, func(attempt *ActionRunAttempt) (int64, bool) {
|
|
return attempt.TriggerUserID, true
|
|
})
|
|
}
|
|
|
|
func (attempts ActionRunAttemptList) LoadTriggerUser(ctx context.Context) error {
|
|
userIDs := attempts.GetUserIDs()
|
|
users := make(map[int64]*user_model.User, len(userIDs))
|
|
if err := db.GetEngine(ctx).In("id", userIDs).Find(&users); err != nil {
|
|
return err
|
|
}
|
|
for _, attempt := range attempts {
|
|
attempt.TriggerUser = user_model.GetPossibleUserFromMap(attempt.TriggerUserID, users)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ListRunAttemptsByRunID returns all attempts of a run, ordered by attempt number DESC (newest first).
|
|
func ListRunAttemptsByRunID(ctx context.Context, runID int64) (ActionRunAttemptList, error) {
|
|
var attempts ActionRunAttemptList
|
|
return attempts, db.GetEngine(ctx).Where("run_id=?", runID).OrderBy("attempt DESC").Find(&attempts)
|
|
}
|