@@ -69,7 +69,7 @@ type notifyInput struct {
69
69
Event webhook_module.HookEventType
70
70
71
71
// optional
72
- Ref string
72
+ Ref git. RefName
73
73
Payload api.Payloader
74
74
PullRequest * issues_model.PullRequest
75
75
}
@@ -93,7 +93,7 @@ func (input *notifyInput) WithDoer(doer *user_model.User) *notifyInput {
93
93
}
94
94
95
95
func (input * notifyInput ) WithRef (ref string ) * notifyInput {
96
- input .Ref = ref
96
+ input .Ref = git . RefName ( ref )
97
97
return input
98
98
}
99
99
@@ -105,7 +105,7 @@ func (input *notifyInput) WithPayload(payload api.Payloader) *notifyInput {
105
105
func (input * notifyInput ) WithPullRequest (pr * issues_model.PullRequest ) * notifyInput {
106
106
input .PullRequest = pr
107
107
if input .Ref == "" {
108
- input .Ref = pr .GetGitRefName ()
108
+ input .Ref = git . RefName ( pr .GetGitRefName () )
109
109
}
110
110
return input
111
111
}
@@ -148,20 +148,25 @@ func notify(ctx context.Context, input *notifyInput) error {
148
148
defer gitRepo .Close ()
149
149
150
150
ref := input .Ref
151
- if ref != input .Repo .DefaultBranch && actions_module .IsDefaultBranchWorkflow (input .Event ) {
151
+ if ref . BranchName () != input .Repo .DefaultBranch && actions_module .IsDefaultBranchWorkflow (input .Event ) {
152
152
if ref != "" {
153
153
log .Warn ("Event %q should only trigger workflows on the default branch, but its ref is %q. Will fall back to the default branch" ,
154
154
input .Event , ref )
155
155
}
156
- ref = input .Repo .DefaultBranch
156
+ ref = git . RefNameFromBranch ( input .Repo .DefaultBranch )
157
157
}
158
158
if ref == "" {
159
159
log .Warn ("Ref of event %q is empty, will fall back to the default branch" , input .Event )
160
- ref = input .Repo .DefaultBranch
160
+ ref = git .RefNameFromBranch (input .Repo .DefaultBranch )
161
+ }
162
+
163
+ commitID , err := gitRepo .GetRefCommitID (ref .String ())
164
+ if err != nil {
165
+ return fmt .Errorf ("gitRepo.GetRefCommitID: %w" , err )
161
166
}
162
167
163
168
// Get the commit object for the ref
164
- commit , err := gitRepo .GetCommit (ref )
169
+ commit , err := gitRepo .GetCommit (commitID )
165
170
if err != nil {
166
171
return fmt .Errorf ("gitRepo.GetCommit: %w" , err )
167
172
}
@@ -177,7 +182,7 @@ func notify(ctx context.Context, input *notifyInput) error {
177
182
178
183
var detectedWorkflows []* actions_module.DetectedWorkflow
179
184
actionsConfig := input .Repo .MustGetUnit (ctx , unit_model .TypeActions ).ActionsConfig ()
180
- shouldDetectSchedules := input .Event == webhook_module .HookEventPush && git . RefName ( input .Ref ) .BranchName () == input .Repo .DefaultBranch
185
+ shouldDetectSchedules := input .Event == webhook_module .HookEventPush && input .Ref .BranchName () == input .Repo .DefaultBranch
181
186
workflows , schedules , err := actions_module .DetectWorkflows (gitRepo , commit ,
182
187
input .Event ,
183
188
input .Payload ,
@@ -235,12 +240,12 @@ func notify(ctx context.Context, input *notifyInput) error {
235
240
}
236
241
237
242
if shouldDetectSchedules {
238
- if err := handleSchedules (ctx , schedules , commit , input , ref ); err != nil {
243
+ if err := handleSchedules (ctx , schedules , commit , input , ref . String () ); err != nil {
239
244
return err
240
245
}
241
246
}
242
247
243
- return handleWorkflows (ctx , detectedWorkflows , commit , input , ref )
248
+ return handleWorkflows (ctx , detectedWorkflows , commit , input , ref . String () )
244
249
}
245
250
246
251
func SkipPullRequestEvent (ctx context.Context , event webhook_module.HookEventType , repoID int64 , commitSHA string ) bool {
0 commit comments