diff options
author | Jason Song <i@wolfogre.com> | 2023-01-31 23:45:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-31 23:45:25 +0100 |
commit | 707ecec71514fbadb09bdbe915129a9badf0755c (patch) | |
tree | 239cba72647fb1745e6d1f8aec22bf96500124eb /services/actions/notifier_helper.go | |
parent | Rootless Docker - Mistake with the repo-avatars parent folder name (#22637) (diff) | |
download | forgejo-707ecec71514fbadb09bdbe915129a9badf0755c.tar.xz forgejo-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 'services/actions/notifier_helper.go')
-rw-r--r-- | services/actions/notifier_helper.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 44df568cbe..9c9fc644cb 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -67,7 +67,6 @@ type notifyInput struct { func newNotifyInput(repo *repo_model.Repository, doer *user_model.User, event webhook_module.HookEventType) *notifyInput { return ¬ifyInput{ Repo: repo, - Ref: repo.DefaultBranch, Doer: doer, Event: event, } @@ -90,6 +89,9 @@ 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 = pr.GetGitRefName() + } return input } @@ -124,8 +126,13 @@ func notify(ctx context.Context, input *notifyInput) error { } defer gitRepo.Close() + ref := input.Ref + if ref == "" { + ref = input.Repo.DefaultBranch + } + // Get the commit object for the ref - commit, err := gitRepo.GetCommit(input.Ref) + commit, err := gitRepo.GetCommit(ref) if err != nil { return fmt.Errorf("gitRepo.GetCommit: %w", err) } @@ -152,7 +159,7 @@ func notify(ctx context.Context, input *notifyInput) error { OwnerID: input.Repo.OwnerID, WorkflowID: id, TriggerUserID: input.Doer.ID, - Ref: input.Ref, + Ref: ref, CommitSHA: commit.ID.String(), IsForkPullRequest: input.PullRequest != nil && input.PullRequest.IsFromFork(), Event: input.Event, |