Improve ui for builds

This commit is contained in:
Lunny Xiao 2022-10-19 22:31:05 +08:00 committed by Jason Song
parent d69423a3b0
commit 3518c098b9
6 changed files with 75 additions and 47 deletions

View File

@ -8,6 +8,7 @@ import (
"context" "context"
"fmt" "fmt"
"hash/fnv" "hash/fnv"
"time"
"code.gitea.io/gitea/core" "code.gitea.io/gitea/core"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
@ -84,6 +85,10 @@ func (r *Run) LoadAttributes(ctx context.Context) error {
return nil return nil
} }
func (run *Run) TakeTime() time.Duration {
return run.EndTime.AsTime().Sub(run.StartTime.AsTime())
}
func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error { func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error {
_, err := db.GetEngine(ctx).ID(repo.ID). _, err := db.GetEngine(ctx).ID(repo.ID).
SetExpr("num_runs", SetExpr("num_runs",

View File

@ -41,6 +41,54 @@ func SanitizeRefPattern(name string) string {
return refNamePatternInvalid.ReplaceAllString(name, "_") return refNamePatternInvalid.ReplaceAllString(name, "_")
} }
// RefName represents a git reference name
type RefName string
func (ref RefName) IsBranch() bool {
return strings.HasPrefix(string(ref), BranchPrefix)
}
func (ref RefName) IsTag() bool {
return strings.HasPrefix(string(ref), TagPrefix)
}
// ShortName returns the short name of the reference name
func (ref RefName) ShortName() string {
refName := string(ref)
if strings.HasPrefix(refName, BranchPrefix) {
return strings.TrimPrefix(refName, BranchPrefix)
}
if strings.HasPrefix(refName, TagPrefix) {
return strings.TrimPrefix(refName, TagPrefix)
}
if strings.HasPrefix(refName, RemotePrefix) {
return strings.TrimPrefix(refName, RemotePrefix)
}
if strings.HasPrefix(refName, PullPrefix) && strings.IndexByte(refName[pullLen:], '/') > -1 {
return refName[pullLen : strings.IndexByte(refName[pullLen:], '/')+pullLen]
}
return refName
}
// RefGroup returns the group type of the reference
func (ref RefName) RefGroup() string {
refName := string(ref)
if strings.HasPrefix(refName, BranchPrefix) {
return "heads"
}
if strings.HasPrefix(refName, TagPrefix) {
return "tags"
}
if strings.HasPrefix(refName, RemotePrefix) {
return "remotes"
}
if strings.HasPrefix(refName, PullPrefix) && strings.IndexByte(refName[pullLen:], '/') > -1 {
return "pull"
}
return ""
}
// Reference represents a Git ref. // Reference represents a Git ref.
type Reference struct { type Reference struct {
Name string Name string
@ -54,43 +102,12 @@ func (ref *Reference) Commit() (*Commit, error) {
return ref.repo.getCommit(ref.Object) return ref.repo.getCommit(ref.Object)
} }
// ShortName returns the short name of the reference // ShortName returns the short name of the reference name
func (ref *Reference) ShortName() string { func (ref *Reference) ShortName() string {
if ref == nil { return RefName(ref.Name).ShortName()
return ""
}
if strings.HasPrefix(ref.Name, BranchPrefix) {
return strings.TrimPrefix(ref.Name, BranchPrefix)
}
if strings.HasPrefix(ref.Name, TagPrefix) {
return strings.TrimPrefix(ref.Name, TagPrefix)
}
if strings.HasPrefix(ref.Name, RemotePrefix) {
return strings.TrimPrefix(ref.Name, RemotePrefix)
}
if strings.HasPrefix(ref.Name, PullPrefix) && strings.IndexByte(ref.Name[pullLen:], '/') > -1 {
return ref.Name[pullLen : strings.IndexByte(ref.Name[pullLen:], '/')+pullLen]
}
return ref.Name
} }
// RefGroup returns the group type of the reference // RefGroup returns the group type of the reference
func (ref *Reference) RefGroup() string { func (ref *Reference) RefGroup() string {
if ref == nil { return RefName(ref.Name).RefGroup()
return ""
}
if strings.HasPrefix(ref.Name, BranchPrefix) {
return "heads"
}
if strings.HasPrefix(ref.Name, TagPrefix) {
return "tags"
}
if strings.HasPrefix(ref.Name, RemotePrefix) {
return "remotes"
}
if strings.HasPrefix(ref.Name, PullPrefix) && strings.IndexByte(ref.Name[pullLen:], '/') > -1 {
return "pull"
}
return ""
} }

View File

@ -472,6 +472,9 @@ func NewFuncMap() []template.FuncMap {
curBranch, curBranch,
) )
}, },
"RefShortName": func(ref string) string {
return git.RefName(ref).ShortName()
},
}} }}
} }

View File

@ -65,13 +65,16 @@ func List(ctx *context.Context) {
page = 1 page = 1
} }
workflow := ctx.FormString("workflow")
ctx.Data["CurWorkflow"] = workflow
opts := bots_model.FindRunOptions{ opts := bots_model.FindRunOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: page, Page: page,
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")), PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
}, },
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
WorkflowFileName: ctx.FormString("workflow"), WorkflowFileName: workflow,
} }
if ctx.FormString("state") == "closed" { if ctx.FormString("state") == "closed" {
opts.IsClosed = util.OptionalBoolTrue opts.IsClosed = util.OptionalBoolTrue

View File

@ -2,22 +2,22 @@
{{range .Builds}} {{range .Builds}}
<li class="item df py-3"> <li class="item df py-3">
<div class="issue-item-left df"> <div class="issue-item-left df">
{{if $.CanWriteIssuesOrPulls}}
<div class="ui checkbox issue-checkbox">
<input type="checkbox" data-issue-id={{.ID}}></input>
<label></label>
</div>
{{end}}
{{template "repo/builds/status" .Status}} {{template "repo/builds/status" .Status}}
</div> </div>
<div class="issue-item-main f1 fc df"> <div class="issue-item-main f1 fc df">
<div class="desc issue-item-bottom-row df ac fw my-1"> <div class="issue-item-top-row">
<a class="index ml-0 mr-2" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}"> <a class="index ml-0 mr-2" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}">
#{{.Index}} {{.Title}} {{.Title}} <span class="ui label">{{RefShortName .Ref}}</span>
</a> </a>
{{ $timeStr := TimeSinceUnix .Updated $.locale }}
{{$.locale.Tr "repo.builds.opened_by" $timeStr (.TriggerUser.GetDisplayName | Escape) | Safe}}
</div> </div>
<div class="desc issue-item-bottom-row df ac fw my-1">
<b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b>: Commit
<a href="{{$.Link}}/commit/{{.CommitSHA}}">{{SubStr .CommitSHA 0 10}}</a>&nbsp; pushed by {{.TriggerUser.GetDisplayName | Escape}}
</div>
</div>
<div class="issue-item-right">
<div>{{ TimeSinceUnix .Updated $.locale }}</div>
<div>{{.TakeTime}}</div>
</div> </div>
</li> </li>
{{end}} {{end}}

View File

@ -6,10 +6,10 @@
<div class="ui grid"> <div class="ui grid">
<div class="four wide column"> <div class="four wide column">
<div class="ui fluid vertical menu"> <div class="ui fluid vertical menu">
<a class="item" href="{{$.Link}}">All Workflows</a> <a class="item{{if not $.CurWorkflow}} active{{end}}" href="{{$.Link}}">All Workflows</a>
<div class="divider"></div> <div class="divider"></div>
{{range .workflows}} {{range .workflows}}
<a class="item" href="{{$.Link}}?workflow={{.Name}}">{{.Name}}</a> <a class="item{{if eq .Name $.CurWorkflow}} active{{end}}" href="{{$.Link}}?workflow={{.Name}}">{{.Name}}</a>
{{end}} {{end}}
</div> </div>
</div> </div>