Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ref to trigger Actions #22679

Merged
merged 8 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: link to PR
  • Loading branch information
wolfogre committed Jan 31, 2023
commit b81bbfbb7ce4b0f6fbd70844bd24753e76da643c
23 changes: 23 additions & 0 deletions models/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -63,6 +65,27 @@ func (run *ActionRun) Link() string {
return fmt.Sprintf("%s/actions/runs/%d", run.Repo.Link(), run.Index)
}

func (run *ActionRun) RefLink() string {
refName := git.RefName(run.Ref)
switch refName.RefGroup() {
case "heads":
return run.Repo.Link() + "/src/branch/" + refName.ShortName()
case "tags":
return run.Repo.Link() + "/src/tag/" + refName.ShortName()
case "pull":
return run.Repo.Link() + "/pulls/" + refName.ShortName()
}
return ""
}

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()
}
Comment on lines +78 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's some similar code within the git commit graph.


// LoadAttributes load Repo TriggerUser if not loaded
func (run *ActionRun) LoadAttributes(ctx context.Context) error {
if run == nil {
Expand Down
2 changes: 1 addition & 1 deletion services/actions/notifier_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (input *notifyInput) WithPayload(payload api.Payloader) *notifyInput {
func (input *notifyInput) WithPullRequest(pr *issues_model.PullRequest) *notifyInput {
input.PullRequest = pr
if input.Ref == "" {
input.Ref = fmt.Sprintf("pull/%d/head", pr.Index)
input.Ref = pr.GetGitRefName()
}
return input
}
Expand Down
9 changes: 8 additions & 1 deletion templates/repo/actions/runs_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
<div class="issue-item-main f1 fc df">
<div class="issue-item-top-row">
<a class="index ml-0 mr-2" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}">
{{.Title}} <span class="ui label">{{RefShortName .Ref}}</span>
{{.Title}}
</a>
<span class="ui label">
{{if .RefLink}}
<a href="{{.RefLink}}">{{.PrettyRef}}</a>
{{else}}
{{.PrettyRef}}
{{end}}
</span>
</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"}}
Expand Down