Skip to content

Commit

Permalink
don't trigger event when pull request close
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Mar 14, 2023
1 parent 6884d54 commit ffa3571
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions modules/actions/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
return false
}

// with no special filter parameters
if len(evt.Acts) == 0 {
return true
}

switch triggedEvent {
case webhook_module.HookEventCreate,
webhook_module.HookEventDelete,
Expand All @@ -126,6 +121,9 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
webhook_module.HookEventRepository,
webhook_module.HookEventRelease,
webhook_module.HookEventPackage:
if len(evt.Acts) != 0 {
log.Warn("Ignore unsupported %s event arguments %q", triggedEvent, evt.Acts)
}
// no special filter parameters for these events, just return true if name matched
return true

Expand All @@ -142,12 +140,17 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
return matchIssueCommentEvent(commit, payload.(*api.IssueCommentPayload), evt)

default:
log.Warn("unsupported event %q", triggedEvent.Event())
log.Warn("unsupported event %q", triggedEvent)
return false
}
}

func matchPushEvent(commit *git.Commit, pushPayload *api.PushPayload, evt *jobparser.Event) bool {
// with no special filter parameters
if len(evt.Acts) == 0 {
return true
}

matchTimes := 0
// all acts conditions should be satisfied
for cond, vals := range evt.Acts {
Expand Down Expand Up @@ -180,13 +183,18 @@ func matchPushEvent(commit *git.Commit, pushPayload *api.PushPayload, evt *jobpa
}
}
default:
log.Warn("unsupported condition %q", cond)
log.Warn("push event unsupported condition %q", cond)
}
}
return matchTimes == len(evt.Acts)
}

func matchIssuesEvent(commit *git.Commit, issuePayload *api.IssuePayload, evt *jobparser.Event) bool {
// with no special filter parameters
if len(evt.Acts) == 0 {
return true
}

matchTimes := 0
// all acts conditions should be satisfied
for cond, vals := range evt.Acts {
Expand All @@ -199,13 +207,19 @@ func matchIssuesEvent(commit *git.Commit, issuePayload *api.IssuePayload, evt *j
}
}
default:
log.Warn("unsupported condition %q", cond)
log.Warn("issue event unsupported condition %q", cond)
}
}
return matchTimes == len(evt.Acts)
}

func matchPullRequestEvent(commit *git.Commit, prPayload *api.PullRequestPayload, evt *jobparser.Event) bool {
// with no special filter parameters
if len(evt.Acts) == 0 {
// defautly, only pull request opened and synchronized will not trigger workflow
return prPayload.Action == api.HookIssueSynchronized || prPayload.Action == api.HookIssueOpened
}

matchTimes := 0
// all acts conditions should be satisfied
for cond, vals := range evt.Acts {
Expand Down Expand Up @@ -250,13 +264,18 @@ func matchPullRequestEvent(commit *git.Commit, prPayload *api.PullRequestPayload
}
}
default:
log.Warn("unsupported condition %q", cond)
log.Warn("pull request event unsupported condition %q", cond)
}
}
return matchTimes == len(evt.Acts)
}

func matchIssueCommentEvent(commit *git.Commit, issueCommentPayload *api.IssueCommentPayload, evt *jobparser.Event) bool {
// with no special filter parameters
if len(evt.Acts) == 0 {
return true
}

matchTimes := 0
// all acts conditions should be satisfied
for cond, vals := range evt.Acts {
Expand All @@ -269,7 +288,7 @@ func matchIssueCommentEvent(commit *git.Commit, issueCommentPayload *api.IssueCo
}
}
default:
log.Warn("unsupported condition %q", cond)
log.Warn("issue comment unsupported condition %q", cond)
}
}
return matchTimes == len(evt.Acts)
Expand Down

0 comments on commit ffa3571

Please sign in to comment.