1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-03 09:07:19 +00:00

Use db.Find instead of writing methods for every object (#28084)

For those simple objects, it's unnecessary to write the find and count
methods again and again.
This commit is contained in:
Lunny Xiao
2023-11-24 11:49:41 +08:00
committed by GitHub
parent d24a8223ce
commit df1e7d0067
88 changed files with 611 additions and 685 deletions

View File

@ -75,11 +75,10 @@ func List(ctx *context.Context) {
}
// Get all runner labels
opts := actions_model.FindRunnerOptions{
runners, err := db.Find[actions_model.ActionRunner](ctx, actions_model.FindRunnerOptions{
RepoID: ctx.Repo.Repository.ID,
WithAvailable: true,
}
runners, err := actions_model.FindRunners(ctx, opts)
})
if err != nil {
ctx.ServerError("FindRunners", err)
return
@ -169,7 +168,7 @@ func List(ctx *context.Context) {
opts.Status = []actions_model.Status{actions_model.Status(status)}
}
runs, total, err := actions_model.FindRuns(ctx, opts)
runs, total, err := db.FindAndCount[actions_model.ActionRun](ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
@ -179,7 +178,7 @@ func List(ctx *context.Context) {
run.Repo = ctx.Repo.Repository
}
if err := runs.LoadTriggerUser(ctx); err != nil {
if err := actions_model.RunList(runs).LoadTriggerUser(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
}

View File

@ -512,7 +512,7 @@ func ArtifactsView(ctx *context_module.Context) {
}
for _, art := range artifacts {
status := "completed"
if art.Status == int64(actions_model.ArtifactStatusExpired) {
if art.Status == actions_model.ArtifactStatusExpired {
status = "expired"
}
artifactsResponse.Artifacts = append(artifactsResponse.Artifacts, &ArtifactsViewItem{
@ -538,7 +538,10 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
return
}
artifacts, err := actions_model.ListArtifactsByRunIDAndName(ctx, run.ID, artifactName)
artifacts, err := db.Find[actions_model.ActionArtifact](ctx, actions_model.FindArtifactsOptions{
RunID: run.ID,
ArtifactName: artifactName,
})
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return