@@ -65,7 +65,7 @@ type notifyInput struct {
65
65
Event webhook_module.HookEventType
66
66
67
67
// optional
68
- Ref string
68
+ Ref git. RefName
69
69
Payload api.Payloader
70
70
PullRequest * issues_model.PullRequest
71
71
}
@@ -89,7 +89,7 @@ func (input *notifyInput) WithDoer(doer *user_model.User) *notifyInput {
89
89
}
90
90
91
91
func (input * notifyInput ) WithRef (ref string ) * notifyInput {
92
- input .Ref = ref
92
+ input .Ref = git . RefName ( ref )
93
93
return input
94
94
}
95
95
@@ -101,7 +101,7 @@ func (input *notifyInput) WithPayload(payload api.Payloader) *notifyInput {
101
101
func (input * notifyInput ) WithPullRequest (pr * issues_model.PullRequest ) * notifyInput {
102
102
input .PullRequest = pr
103
103
if input .Ref == "" {
104
- input .Ref = pr .GetGitRefName ()
104
+ input .Ref = git . RefName ( pr .GetGitRefName () )
105
105
}
106
106
return input
107
107
}
@@ -144,20 +144,25 @@ func notify(ctx context.Context, input *notifyInput) error {
144
144
defer gitRepo .Close ()
145
145
146
146
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 ) {
148
148
if ref != "" {
149
149
log .Warn ("Event %q should only trigger workflows on the default branch, but its ref is %q. Will fall back to the default branch" ,
150
150
input .Event , ref )
151
151
}
152
- ref = input .Repo .DefaultBranch
152
+ ref = git . RefNameFromBranch ( input .Repo .DefaultBranch )
153
153
}
154
154
if ref == "" {
155
155
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 )
157
162
}
158
163
159
164
// Get the commit object for the ref
160
- commit , err := gitRepo .GetCommit (ref )
165
+ commit , err := gitRepo .GetCommit (commitID )
161
166
if err != nil {
162
167
return fmt .Errorf ("gitRepo.GetCommit: %w" , err )
163
168
}
@@ -168,7 +173,7 @@ func notify(ctx context.Context, input *notifyInput) error {
168
173
169
174
var detectedWorkflows []* actions_module.DetectedWorkflow
170
175
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
172
177
workflows , schedules , err := actions_module .DetectWorkflows (gitRepo , commit ,
173
178
input .Event ,
174
179
input .Payload ,
@@ -220,12 +225,12 @@ func notify(ctx context.Context, input *notifyInput) error {
220
225
}
221
226
222
227
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 {
224
229
return err
225
230
}
226
231
}
227
232
228
- return handleWorkflows (ctx , detectedWorkflows , commit , input , ref )
233
+ return handleWorkflows (ctx , detectedWorkflows , commit , input , ref . String () )
229
234
}
230
235
231
236
func skipWorkflows (input * notifyInput , commit * git.Commit ) bool {
0 commit comments