1
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-04-18 00:47:48 -04:00

feat: improve listing runs

This commit is contained in:
Jason Song 2023-01-06 16:29:10 +08:00
parent 6f6bfc5d51
commit aba1c03fee
No known key found for this signature in database
GPG Key ID: 8402EEEE4511A8B5
5 changed files with 22 additions and 35 deletions

View File

@ -51,9 +51,19 @@ func init() {
} }
func (run *ActionRun) HTMLURL() string { func (run *ActionRun) HTMLURL() string {
if run.Repo == nil {
return ""
}
return fmt.Sprintf("%s/actions/runs/%d", run.Repo.HTMLURL(), run.Index) return fmt.Sprintf("%s/actions/runs/%d", run.Repo.HTMLURL(), run.Index)
} }
func (run *ActionRun) Link() string {
if run.Repo == nil {
return ""
}
return fmt.Sprintf("%s/actions/runs/%d", run.Repo.Link(), run.Index)
}
// LoadAttributes load Repo TriggerUser if not loaded // LoadAttributes load Repo TriggerUser if not loaded
func (run *ActionRun) LoadAttributes(ctx context.Context) error { func (run *ActionRun) LoadAttributes(ctx context.Context) error {
if run == nil { if run == nil {

View File

@ -7,7 +7,6 @@ import (
"context" "context"
"crypto/subtle" "crypto/subtle"
"fmt" "fmt"
"strconv"
"time" "time"
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
@ -83,40 +82,18 @@ func (task *ActionTask) IsStopped() bool {
return task.Stopped > 0 return task.Stopped > 0
} }
func (task *ActionTask) GetCommitSHA() string { func (task *ActionTask) GetRunLink() string {
if task.Job == nil { if task.Job == nil || task.Job.Run == nil {
return "" return ""
} }
if task.Job.Run == nil { return task.Job.Run.Link()
return ""
}
return task.Job.Run.CommitSHA
}
func (task *ActionTask) GetCommitSHAShort() string {
commitSHA := task.GetCommitSHA()
if len(commitSHA) > 8 {
return commitSHA[:8]
}
return commitSHA
}
func (task *ActionTask) GetBuildViewLink() string {
if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil {
return ""
}
return task.Job.Run.Repo.Link() + "/actions/runs/" + strconv.FormatInt(task.ID, 10)
} }
func (task *ActionTask) GetCommitLink() string { func (task *ActionTask) GetCommitLink() string {
if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil { if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil {
return "" return ""
} }
if commitSHA := task.GetCommitSHA(); commitSHA != "" { return task.Job.Run.Repo.CommitLink(task.CommitSHA)
return task.Job.Run.Repo.CommitLink(commitSHA)
}
return ""
} }
func (task *ActionTask) GetRepoName() string { func (task *ActionTask) GetRepoName() string {

View File

@ -3264,7 +3264,7 @@ runners.custom_labels = Custom Labels
runners.custom_labels_helper = Custom labels are labels that are added manually by an administrator. A comma separates labels, whitespace at the start and end of each label are ignored. runners.custom_labels_helper = Custom labels are labels that are added manually by an administrator. A comma separates labels, whitespace at the start and end of each label are ignored.
runners.runner_title = Runner runners.runner_title = Runner
runners.task_list = Recent tasks on this runner runners.task_list = Recent tasks on this runner
runners.task_list.job = Job runners.task_list.run = Run
runners.task_list.status = Status runners.task_list.status = Status
runners.task_list.repository = Repository runners.task_list.repository = Repository
runners.task_list.commit = Commit runners.task_list.commit = Commit

View File

@ -12,7 +12,7 @@
</div> </div>
<div class="desc issue-item-bottom-row df ac fw my-1"> <div class="desc issue-item-bottom-row df ac fw my-1">
<b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b>: {{$.locale.Tr "actions.runs.commit"}} <b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b>: {{$.locale.Tr "actions.runs.commit"}}
<a href="{{$.RepoLink}}/commit/{{.CommitSHA}}">{{SubStr .CommitSHA 0 10}}</a>&nbsp; {{$.locale.Tr "actions.runs.pushed_by"}} {{.TriggerUser.GetDisplayName | Escape}} <a href="{{$.RepoLink}}/commit/{{.CommitSHA}}">{{ShortSha .CommitSHA}}</a>&nbsp; {{$.locale.Tr "actions.runs.pushed_by"}} {{.TriggerUser.GetDisplayName | Escape}}
</div> </div>
</div> </div>
<div class="issue-item-right"> <div class="issue-item-right">

View File

@ -59,7 +59,7 @@
<table class="ui very basic striped table unstackable"> <table class="ui very basic striped table unstackable">
<thead> <thead>
<tr> <tr>
<th>{{.locale.Tr "actions.runners.task_list.job"}}</th> <th>{{.locale.Tr "actions.runners.task_list.run"}}</th>
<th>{{.locale.Tr "actions.runners.task_list.status"}}</th> <th>{{.locale.Tr "actions.runners.task_list.status"}}</th>
<th>{{.locale.Tr "actions.runners.task_list.repository"}}</th> <th>{{.locale.Tr "actions.runners.task_list.repository"}}</th>
<th>{{.locale.Tr "actions.runners.task_list.commit"}}</th> <th>{{.locale.Tr "actions.runners.task_list.commit"}}</th>
@ -69,12 +69,12 @@
<tbody> <tbody>
{{range .Tasks}} {{range .Tasks}}
<tr> <tr>
<td><a href="{{.GetBuildViewLink}}" target="_blank">{{template "shared/actions/runner_id" .ID}}</a></td> <td><a href="{{.GetRunLink}}" target="_blank">{{template "shared/actions/runner_id" .ID}}</a></td>
<td><span class="ui label task-status-{{.Status.String}}">{{.Status.LocaleString $.locale}}</span></td> <td><span class="ui label task-status-{{.Status.String}}">{{.Status.LocaleString $.locale}}</span></td>
<td>{{.GetRepoName}}</td> <td><a href="{{.GetRepoLink}}" target="_blank">{{.GetRepoName}}</a></td>
<td><strong> <td>
<a href="{{.GetCommitLink}}" target="_blank">{{.GetCommitSHAShort}}</a> <strong><a href="{{.GetCommitLink}}" target="_blank">{{ShortSha .CommitSHA}}</a></strong>
</strong> </td> </td>
<td>{{if .IsStopped}} <td>{{if .IsStopped}}
<span>{{TimeSinceUnix .Stopped $.locale}}</span> <span>{{TimeSinceUnix .Stopped $.locale}}</span>
{{else}}-{{end}}</td> {{else}}-{{end}}</td>