feat: improve listing runs

This commit is contained in:
Jason Song
2023-01-06 16:29:10 +08:00
parent 6f6bfc5d51
commit aba1c03fee
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 {