Skip to content

Commit bb85519

Browse files
committed
allow workflow_run for recusive depth of 5
1 parent 956556d commit bb85519

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

models/actions/run.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ func (run *ActionRun) GetPullRequestEventPayload() (*api.PullRequestPayload, err
164164
return nil, fmt.Errorf("event %s is not a pull request event", run.Event)
165165
}
166166

167+
func (run *ActionRun) GetWorkflowRunEventPayload() (*api.WorkflowRunPayload, error) {
168+
if run.Event == webhook_module.HookEventWorkflowRun {
169+
var payload api.WorkflowRunPayload
170+
if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
171+
return nil, err
172+
}
173+
return &payload, nil
174+
}
175+
return nil, fmt.Errorf("event %s is not a pull request event", run.Event)
176+
}
177+
167178
func (run *ActionRun) IsSchedule() bool {
168179
return run.ScheduleID > 0
169180
}

services/actions/notifier_helper.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func notify(ctx context.Context, input *notifyInput) error {
178178
return fmt.Errorf("gitRepo.GetCommit: %w", err)
179179
}
180180

181-
if skipWorkflows(input, commit) {
181+
if skipWorkflows(ctx, input, commit) {
182182
return nil
183183
}
184184

@@ -243,7 +243,7 @@ func notify(ctx context.Context, input *notifyInput) error {
243243
return handleWorkflows(ctx, detectedWorkflows, commit, input, ref.String())
244244
}
245245

246-
func skipWorkflows(input *notifyInput, commit *git.Commit) bool {
246+
func skipWorkflows(ctx context.Context, input *notifyInput, commit *git.Commit) bool {
247247
// skip workflow runs with a configured skip-ci string in commit message or pr title if the event is push or pull_request(_sync)
248248
// https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
249249
skipWorkflowEvents := []webhook_module.HookEventType{
@@ -265,12 +265,21 @@ func skipWorkflows(input *notifyInput, commit *git.Commit) bool {
265265
}
266266
if input.Event == webhook_module.HookEventWorkflowRun {
267267
wrun, ok := input.Payload.(*api.WorkflowRunPayload)
268-
if ok && wrun.WorkflowRun != nil && wrun.WorkflowRun.Event == "workflow_run" {
269-
// skip workflow runs triggered by another workflow run
270-
// TODO GitHub allows chaining up to 5 of them
271-
log.Debug("repo %s: skipped workflow_run because of recursive event", input.Repo.RepoPath())
272-
return true
268+
for i := 0; i < 5 && ok && wrun.WorkflowRun != nil; i++ {
269+
if wrun.WorkflowRun.Event != "workflow_run" {
270+
return false
271+
}
272+
r, _ := actions_model.GetRunByID(ctx, wrun.WorkflowRun.ID)
273+
var err error
274+
wrun, err = r.GetWorkflowRunEventPayload()
275+
if err != nil {
276+
log.Error("GetWorkflowRunEventPayload: %v", err)
277+
return true
278+
}
273279
}
280+
// skip workflow runs events exceeding the maxiumum of 5 recursive events
281+
log.Debug("repo %s: skipped workflow_run because of recursive event of 5", input.Repo.RepoPath())
282+
return true
274283
}
275284
return false
276285
}

0 commit comments

Comments
 (0)