@@ -65,7 +65,7 @@ type notifyInput struct {
6565 Event webhook_module.HookEventType
6666
6767 // optional
68- Ref string
68+ Ref git. RefName
6969 Payload api.Payloader
7070 PullRequest * issues_model.PullRequest
7171}
@@ -89,7 +89,7 @@ func (input *notifyInput) WithDoer(doer *user_model.User) *notifyInput {
8989}
9090
9191func (input * notifyInput ) WithRef (ref string ) * notifyInput {
92- input .Ref = ref
92+ input .Ref = git . RefName ( ref )
9393 return input
9494}
9595
@@ -101,7 +101,7 @@ func (input *notifyInput) WithPayload(payload api.Payloader) *notifyInput {
101101func (input * notifyInput ) WithPullRequest (pr * issues_model.PullRequest ) * notifyInput {
102102 input .PullRequest = pr
103103 if input .Ref == "" {
104- input .Ref = pr .GetGitRefName ()
104+ input .Ref = git . RefName ( pr .GetGitRefName () )
105105 }
106106 return input
107107}
@@ -144,20 +144,25 @@ func notify(ctx context.Context, input *notifyInput) error {
144144 defer gitRepo .Close ()
145145
146146 ref := input .Ref
147- if ref != input .Repo .DefaultBranch && actions_module .IsDefaultBranchWorkflow (input .Event ) {
147+ if ref . BranchName () != input .Repo .DefaultBranch && actions_module .IsDefaultBranchWorkflow (input .Event ) {
148148 if ref != "" {
149149 log .Warn ("Event %q should only trigger workflows on the default branch, but its ref is %q. Will fall back to the default branch" ,
150150 input .Event , ref )
151151 }
152- ref = input .Repo .DefaultBranch
152+ ref = git . RefNameFromBranch ( input .Repo .DefaultBranch )
153153 }
154154 if ref == "" {
155155 log .Warn ("Ref of event %q is empty, will fall back to the default branch" , input .Event )
156- ref = input .Repo .DefaultBranch
156+ ref = git .RefNameFromBranch (input .Repo .DefaultBranch )
157+ }
158+
159+ commitID , err := gitRepo .GetRefCommitID (ref .String ())
160+ if err != nil {
161+ return fmt .Errorf ("gitRepo.GetRefCommitID: %w" , err )
157162 }
158163
159164 // Get the commit object for the ref
160- commit , err := gitRepo .GetCommit (ref )
165+ commit , err := gitRepo .GetCommit (commitID )
161166 if err != nil {
162167 return fmt .Errorf ("gitRepo.GetCommit: %w" , err )
163168 }
@@ -168,7 +173,7 @@ func notify(ctx context.Context, input *notifyInput) error {
168173
169174 var detectedWorkflows []* actions_module.DetectedWorkflow
170175 actionsConfig := input .Repo .MustGetUnit (ctx , unit_model .TypeActions ).ActionsConfig ()
171- shouldDetectSchedules := input .Event == webhook_module .HookEventPush && git . RefName ( input .Ref ) .BranchName () == input .Repo .DefaultBranch
176+ shouldDetectSchedules := input .Event == webhook_module .HookEventPush && input .Ref .BranchName () == input .Repo .DefaultBranch
172177 workflows , schedules , err := actions_module .DetectWorkflows (gitRepo , commit ,
173178 input .Event ,
174179 input .Payload ,
@@ -220,12 +225,12 @@ func notify(ctx context.Context, input *notifyInput) error {
220225 }
221226
222227 if shouldDetectSchedules {
223- if err := handleSchedules (ctx , schedules , commit , input , ref ); err != nil {
228+ if err := handleSchedules (ctx , schedules , commit , input , ref . String () ); err != nil {
224229 return err
225230 }
226231 }
227232
228- return handleWorkflows (ctx , detectedWorkflows , commit , input , ref )
233+ return handleWorkflows (ctx , detectedWorkflows , commit , input , ref . String () )
229234}
230235
231236func skipWorkflows (input * notifyInput , commit * git.Commit ) bool {
0 commit comments