Skip to content

Commit a983d34

Browse files
committed
fix workflow_run action event processing
1 parent 6df1854 commit a983d34

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

modules/actions/workflows.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ func detectMatched(gitRepo *git.Repository, commit *git.Commit, triggedEvent web
243243
webhook_module.HookEventPackage:
244244
return matchPackageEvent(payload.(*api.PackagePayload), evt)
245245

246+
case // registry_package
247+
webhook_module.HookEventWorkflowRun:
248+
return matchWorkflowRunEvent(payload.(*api.WorkflowRunPayload), evt)
249+
246250
default:
247251
log.Warn("unsupported event %q", triggedEvent)
248252
return false
@@ -698,3 +702,45 @@ func matchPackageEvent(payload *api.PackagePayload, evt *jobparser.Event) bool {
698702
}
699703
return matchTimes == len(evt.Acts())
700704
}
705+
706+
func matchWorkflowRunEvent(payload *api.WorkflowRunPayload, evt *jobparser.Event) bool {
707+
// with no special filter parameters
708+
if len(evt.Acts()) == 0 {
709+
return true
710+
}
711+
712+
matchTimes := 0
713+
// all acts conditions should be satisfied
714+
for cond, vals := range evt.Acts() {
715+
switch cond {
716+
case "types":
717+
action := payload.Action
718+
for _, val := range vals {
719+
if glob.MustCompile(val, '/').Match(string(action)) {
720+
matchTimes++
721+
break
722+
}
723+
}
724+
case "workflows":
725+
workflow := payload.Workflow
726+
patterns, err := workflowpattern.CompilePatterns(vals...)
727+
if err != nil {
728+
break
729+
}
730+
if !workflowpattern.Skip(patterns, []string{workflow.Name}, &workflowpattern.EmptyTraceWriter{}) {
731+
matchTimes++
732+
}
733+
case "branches":
734+
patterns, err := workflowpattern.CompilePatterns(vals...)
735+
if err != nil {
736+
break
737+
}
738+
if !workflowpattern.Skip(patterns, []string{payload.WorkflowRun.HeadBranch}, &workflowpattern.EmptyTraceWriter{}) {
739+
matchTimes++
740+
}
741+
default:
742+
log.Warn("package event unsupported condition %q", cond)
743+
}
744+
}
745+
return matchTimes == len(evt.Acts())
746+
}

services/actions/job_emitter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func checkJobsOfRun(ctx context.Context, runID int64) error {
7878
_ = job.LoadAttributes(ctx)
7979
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
8080
}
81-
if len(updatedjobs) > 0 {
81+
if len(jobs) > 0 {
8282
runUpdated := true
83-
run := updatedjobs[0].Run
83+
run := jobs[0].Run
8484
for _, job := range jobs {
8585
if !job.Status.IsDone() {
8686
runUpdated = false

0 commit comments

Comments
 (0)