mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-12-05 02:54:46 +01:00
b1162495af
Backport #23370 by @HesterG 1 Right now on actions page, the action list will not be aligned if commit message is long. In this PR, the changes are: - The branch tag is moved to bottom row - Width percentage is given to make them aligned - Show "..." if commit is longer than two lines. - Align the status icon with the commit message with baseline Before: <img width="1068" alt="截屏2023-03-08 12 23 22" src="https://user-images.githubusercontent.com/17645053/223628534-6b9472cb-29f5-40a3-9714-c5152553049e.png"> After: <img width="756" alt="截屏2023-03-08 13 34 28" src="https://user-images.githubusercontent.com/17645053/223628571-da94698b-0e0a-43e3-ae82-34d8c780e5ba.png"> 2 Right now the actions list's pagination is not working properly because Param is not passed to pagination template, in this PR Param Strings are passed to the pager Before: <img width="1176" alt="截屏2023-03-08 12 23 50" src="https://user-images.githubusercontent.com/17645053/223629207-8b67ce74-2342-4259-bc81-036e37752716.png"> After: <img width="1343" alt="截屏2023-03-08 13 11 54" src="https://user-images.githubusercontent.com/17645053/223629321-4f538f8a-45dc-4d6f-ae60-2c82680ae3e7.png"> 3 A small simplify in `RepoActionView.vue` . Co-authored-by: Hester Gong <hestergong@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
141 lines
3.5 KiB
Go
141 lines
3.5 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
actions_model "code.gitea.io/gitea/models/actions"
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/models/unit"
|
|
"code.gitea.io/gitea/modules/actions"
|
|
"code.gitea.io/gitea/modules/base"
|
|
"code.gitea.io/gitea/modules/context"
|
|
"code.gitea.io/gitea/modules/git"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/util"
|
|
"code.gitea.io/gitea/services/convert"
|
|
)
|
|
|
|
const (
|
|
tplListActions base.TplName = "repo/actions/list"
|
|
tplViewActions base.TplName = "repo/actions/view"
|
|
)
|
|
|
|
// MustEnableActions check if actions are enabled in settings
|
|
func MustEnableActions(ctx *context.Context) {
|
|
if !setting.Actions.Enabled {
|
|
ctx.NotFound("MustEnableActions", nil)
|
|
return
|
|
}
|
|
|
|
if unit.TypeActions.UnitGlobalDisabled() {
|
|
ctx.NotFound("MustEnableActions", nil)
|
|
return
|
|
}
|
|
|
|
if ctx.Repo.Repository != nil {
|
|
if !ctx.Repo.CanRead(unit.TypeActions) {
|
|
ctx.NotFound("MustEnableActions", nil)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func List(ctx *context.Context) {
|
|
ctx.Data["Title"] = ctx.Tr("actions.actions")
|
|
ctx.Data["PageIsActions"] = true
|
|
|
|
var workflows git.Entries
|
|
if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil {
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
} else if !empty {
|
|
defaultBranch, err := ctx.Repo.GitRepo.GetDefaultBranch()
|
|
if err != nil {
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
commit, err := ctx.Repo.GitRepo.GetBranchCommit(defaultBranch)
|
|
if err != nil {
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
workflows, err = actions.ListWorkflows(commit)
|
|
if err != nil {
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
}
|
|
|
|
ctx.Data["workflows"] = workflows
|
|
ctx.Data["RepoLink"] = ctx.Repo.Repository.Link()
|
|
|
|
page := ctx.FormInt("page")
|
|
if page <= 0 {
|
|
page = 1
|
|
}
|
|
|
|
workflow := ctx.FormString("workflow")
|
|
ctx.Data["CurWorkflow"] = workflow
|
|
|
|
opts := actions_model.FindRunOptions{
|
|
ListOptions: db.ListOptions{
|
|
Page: page,
|
|
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
|
},
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
WorkflowFileName: workflow,
|
|
}
|
|
|
|
// open counts
|
|
opts.IsClosed = util.OptionalBoolFalse
|
|
numOpenRuns, err := actions_model.CountRuns(ctx, opts)
|
|
if err != nil {
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
ctx.Data["NumOpenActionRuns"] = numOpenRuns
|
|
|
|
// closed counts
|
|
opts.IsClosed = util.OptionalBoolTrue
|
|
numClosedRuns, err := actions_model.CountRuns(ctx, opts)
|
|
if err != nil {
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
ctx.Data["NumClosedActionRuns"] = numClosedRuns
|
|
|
|
opts.IsClosed = util.OptionalBoolNone
|
|
if ctx.FormString("state") == "closed" {
|
|
opts.IsClosed = util.OptionalBoolTrue
|
|
ctx.Data["IsShowClosed"] = true
|
|
} else {
|
|
opts.IsClosed = util.OptionalBoolFalse
|
|
}
|
|
runs, total, err := actions_model.FindRuns(ctx, opts)
|
|
if err != nil {
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
|
|
for _, run := range runs {
|
|
run.Repo = ctx.Repo.Repository
|
|
}
|
|
|
|
if err := runs.LoadTriggerUser(ctx); err != nil {
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
|
|
ctx.Data["Runs"] = runs
|
|
|
|
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
|
|
pager.SetDefaultParams(ctx)
|
|
pager.AddParamString("workflow", workflow)
|
|
pager.AddParamString("state", ctx.FormString("state"))
|
|
ctx.Data["Page"] = pager
|
|
|
|
ctx.HTML(http.StatusOK, tplListActions)
|
|
}
|