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 {
if run.Repo == nil {
return ""
}
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
func (run *ActionRun) LoadAttributes(ctx context.Context) error {
if run == nil {

View File

@ -7,7 +7,6 @@ import (
"context"
"crypto/subtle"
"fmt"
"strconv"
"time"
auth_model "code.gitea.io/gitea/models/auth"
@ -83,40 +82,18 @@ func (task *ActionTask) IsStopped() bool {
return task.Stopped > 0
}
func (task *ActionTask) GetCommitSHA() string {
if task.Job == nil {
func (task *ActionTask) GetRunLink() string {
if task.Job == nil || task.Job.Run == nil {
return ""
}
if task.Job.Run == nil {
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)
return task.Job.Run.Link()
}
func (task *ActionTask) GetCommitLink() string {
if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil {
return ""
}
if commitSHA := task.GetCommitSHA(); commitSHA != "" {
return task.Job.Run.Repo.CommitLink(commitSHA)
}
return ""
return task.Job.Run.Repo.CommitLink(task.CommitSHA)
}
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.runner_title = 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.repository = Repository
runners.task_list.commit = Commit

View File

@ -12,7 +12,7 @@
</div>
<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"}}
<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 class="issue-item-right">

View File

@ -59,7 +59,7 @@
<table class="ui very basic striped table unstackable">
<thead>
<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.repository"}}</th>
<th>{{.locale.Tr "actions.runners.task_list.commit"}}</th>
@ -69,12 +69,12 @@
<tbody>
{{range .Tasks}}
<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>{{.GetRepoName}}</td>
<td><strong>
<a href="{{.GetCommitLink}}" target="_blank">{{.GetCommitSHAShort}}</a>
</strong> </td>
<td><a href="{{.GetRepoLink}}" target="_blank">{{.GetRepoName}}</a></td>
<td>
<strong><a href="{{.GetCommitLink}}" target="_blank">{{ShortSha .CommitSHA}}</a></strong>
</td>
<td>{{if .IsStopped}}
<span>{{TimeSinceUnix .Stopped $.locale}}</span>
{{else}}-{{end}}</td>