jenkinsci / pipeline-github-plugin

Pipeline: GitHub
https://plugins.jenkins.io/pipeline-github/
MIT License
159 stars 73 forks source link

GitHub Event Trigger #91

Open dclayton-godaddy opened 3 years ago

dclayton-godaddy commented 3 years ago

I'd love to submit a PR to create a GitHubEventTrigger to allow all events to be captured in pipeline. All events sent to the master can cause a build to be triggered if the pipeline has githubEventTrigger with the event name and a payloadFilter. This will save us from having to continuously update this plugin for future supported events of GitHub.

githubEventTrigger("pull_request", payloadFilter: ["action": "closed"])

or

githubEventTrigger("deployment", payloadFilter: ["action": "created"])
dclayton-godaddy commented 3 years ago

Before I get started, I want to make sure this is something that has an opportunity to get merged.

paschdan commented 3 years ago

I'd love this.

because with the current implementation, we have to define multiple Cause Objects, to find out, what has triggered the job:

def triggerCommentCause = currentBuild.rawBuild.getCause(org.jenkinsci.plugins.pipeline.github.trigger.IssueCommentCause)

if (triggerCommentCause) {
    echo("build was started by a github trigger")
} else {
    echo('Build was not started by a trigger')
}

def triggerReviewCause = currentBuild.rawBuild.getCause(org.jenkinsci.plugins.pipeline.github.trigger.PullRequestReviewCause)

if (triggerReviewCause) {
     echo("build was started by a github trigger")
} else {
    echo('Build was not started by a trigger')
}

for backwards ability you have to add the githubEventTrigger additionally to the existing triggers.

for the githubEventTriggerCause, i would suggest, that it should have the github events public properties (https://developer.github.com/v3/activity/event_types/#event-object-common-properties) maybe exluding the id

dclayton-godaddy commented 3 years ago

Sweet! We'll look at submitting a PR on this. You think it will get approved if it has unit tests, etc? Not a fan of maintaining forks as I've had with many other plugins.

paschdan commented 3 years ago

Sorry for the confusion, I'm no maintainer, was just giving my 2 ct :)

dclayton-godaddy commented 3 years ago

Sure. I was asking because you had successful commits. :)

paschdan commented 3 years ago

hehe, ok, @aaronjwhiteside was kind of fast in merging the PRs, and @aaronwalker did the main work for the latest trigger

aaronwalker commented 3 years ago

@dclayton-godaddy had exactly the same thought while implementing the PR review trigger. Happy to test and provide feedback and also work to get it merged as quickly as possible.

blundercon commented 3 years ago

Not sure what the status or progress here is. I can help out with this as well.

dclayton-godaddy commented 3 years ago

Hi all. Sorry, been super busy. I haven't started if someone else has the time. We've started looking at the Checks API plugin to handle checks which was one of the use-cases we wanted.

allout58 commented 7 months ago

I'd like to take a crack at this, should hopefully have a PR up in a week or two.

allout58 commented 7 months ago

Having some issues because it's so generic. Would the expectation be that

githubEventTrigger("pull_request", payloadFilter: ["action": "closed"])

would only run on the Pull Request Job that the event is about? What about events that aren't related to a particular branch or PR like deployment or gollumn or issues?

Should we add an optional "job name regex" option to the trigger that only trigger a branch/tag/pr with that name?

dclayton-godaddy commented 7 months ago

Ya, my thought was to allow for a full JSON filter. This would mean you could filter by branch as well, correct? Awesome you're working on that! Thanks