diff options
author | Jason Song <i@wolfogre.com> | 2023-02-01 06:45:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-31 22:45:25 +0000 |
commit | 707ecec71514fbadb09bdbe915129a9badf0755c (patch) | |
tree | 239cba72647fb1745e6d1f8aec22bf96500124eb /models/actions | |
parent | fd29071e5760e740a533b4f876aef761fdc7ffde (diff) | |
download | gitea-707ecec71514fbadb09bdbe915129a9badf0755c.tar.gz gitea-707ecec71514fbadb09bdbe915129a9badf0755c.zip |
Fix ref to trigger Actions (#22679)
If triggered by PR, the ref should be `pull/<index>/head` instead of
`repo.DefaultBranch`.
And improve UI:
<img width="493" alt="image"
src="https://user-images.githubusercontent.com/9418365/215731280-312564f2-2450-45d0-b986-1accb0670976.png">
Related to #21937.
Diffstat (limited to 'models/actions')
-rw-r--r-- | models/actions/run.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/models/actions/run.go b/models/actions/run.go index 2b748bb0d5..14d191c814 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -6,11 +6,13 @@ package actions import ( "context" "fmt" + "strings" "time" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/json" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" @@ -63,6 +65,24 @@ func (run *ActionRun) Link() string { return fmt.Sprintf("%s/actions/runs/%d", run.Repo.Link(), run.Index) } +// RefLink return the url of run's ref +func (run *ActionRun) RefLink() string { + refName := git.RefName(run.Ref) + if refName.RefGroup() == "pull" { + return run.Repo.Link() + "/pulls/" + refName.ShortName() + } + return git.RefURL(run.Repo.Link(), run.Ref) +} + +// PrettyRef return #id for pull ref or ShortName for others +func (run *ActionRun) PrettyRef() string { + refName := git.RefName(run.Ref) + if refName.RefGroup() == "pull" { + return "#" + strings.TrimSuffix(strings.TrimPrefix(run.Ref, git.PullPrefix), "/head") + } + return refName.ShortName() +} + // LoadAttributes load Repo TriggerUser if not loaded func (run *ActionRun) LoadAttributes(ctx context.Context) error { if run == nil { |