@@ -72,6 +72,38 @@ func (run *ActionRun) Link() string {
72
72
return fmt .Sprintf ("%s/actions/runs/%d" , run .Repo .Link (), run .Index )
73
73
}
74
74
75
+ func (run * ActionRun ) RefShaBaseRefAndHeadRef () (string , string , string , string ) {
76
+ var ref , sha , baseRef , headRef string
77
+
78
+ ref = run .Ref
79
+ sha = run .CommitSHA
80
+
81
+ if pullPayload , err := run .GetPullRequestEventPayload (); err == nil && pullPayload .PullRequest != nil && pullPayload .PullRequest .Base != nil && pullPayload .PullRequest .Head != nil {
82
+ baseRef = pullPayload .PullRequest .Base .Ref
83
+ headRef = pullPayload .PullRequest .Head .Ref
84
+
85
+ // if the TriggerEvent is pull_request_target, ref and sha need to be set according to the base of pull request
86
+ // In GitHub's documentation, ref should be the branch or tag that triggered workflow. But when the TriggerEvent is pull_request_target,
87
+ // the ref will be the base branch.
88
+ if run .TriggerEvent == "pull_request_target" {
89
+ ref = git .BranchPrefix + pullPayload .PullRequest .Base .Name
90
+ sha = pullPayload .PullRequest .Base .Sha
91
+ }
92
+ }
93
+ return ref , sha , baseRef , headRef
94
+ }
95
+
96
+ func (run * ActionRun ) EventName () string {
97
+ // TriggerEvent is added in https://github.com/go-gitea/gitea/pull/25229
98
+ // This fallback is for the old ActionRun that doesn't have the TriggerEvent field
99
+ // and should be removed in 1.22
100
+ eventName := run .TriggerEvent
101
+ if eventName == "" {
102
+ eventName = run .Event .Event ()
103
+ }
104
+ return eventName
105
+ }
106
+
75
107
// RefLink return the url of run's ref
76
108
func (run * ActionRun ) RefLink () string {
77
109
refName := git .RefName (run .Ref )
0 commit comments