Skip to content

[JENKINS-33161] Customized PR build behavior #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jul 5, 2016

Conversation

jglick
Copy link
Member

@jglick jglick commented Jun 16, 2016

JENKINS-33161 and probably also fixes JENKINS-33237 by not relying on more exotic details of the GitHub API. Supersedes #36.

  • basic structure of selection of build types
  • fix representation of PR SCMRevisions
  • run an explicit merge when requested
  • basic UI
  • help files
  • full interactive testing (pending Test case for scanning a GitHub repo #55 this will be pretty laborious)
  • organization folder support
  • review indexing log appearance

@reviewbybees

} else if (revision instanceof PullRequestSCMRevision) {
return ((PullRequestSCMRevision) revision).getPullHash();
} else {
throw new IllegalArgumentException("did not recognize " + revision);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By keeping a reasonable representation of the SCMRevisions to begin with, we avoid the need to try to reconstruct what we just built.

private static final long serialVersionUID = 1;

private final PullRequestAction metadata;
private Boolean merge;
private final boolean trusted;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting to false for old settings to be on the safe side. Only practical impact should be that PRs filed before the upgrade will start using Jenkinsfile from the base branch if you upgrade and then push more commits, even when the PR should have been trusted. I think this is an acceptable price to pay for fixing up the metadata to store this field where it makes more sense, so that we do not need to recheck trusted status on every commit.

@jglick
Copy link
Member Author

jglick commented Jun 16, 2016

Combinations to be tested include:

  • organization vs. account
  • branch vs. origin PR vs. fork PR
  • merging vs. not vs. both
  • trusted vs. not
  • PR up to date w/ base branch vs. needs merge vs. has merge conflict

continue; // not doing this combination
}
if (buildForkPRUnmerged) {
branchName += "-merged"; // make sure they are distinct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contrary seems more natural (as most users will want the merged commit to be built). PR-23 for merged, and PR-23-head for unmerged, for example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion about naming (in particular whether -head is more or less intuitive than -unmerged), but felt that having one job mention the merge flag and the other not mention it would be confusing.

Copy link
Member

@KostyaSha KostyaSha Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't invent custom termins like ghprb did, just name as it is in API, head merge

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

head vs. merge would be OK too. I am not particularly moved by the argument of consistency with the terminology used in the API because (AFAICT) there is no mention in user documentation of virtual merge commits or the like.

“Head branch” vs. “base branch” are used (briefly), so users could probably guess that merge refers to a merge of the two, whereas head does not.

@amuniz
Copy link
Member

amuniz commented Jun 21, 2016

Log messages seems misleading when using merged and unmerged PRs:

Checking pull request #3
    ‘Jenkinsfile’ does not exist in this pull request
Does not meet criteria
    ‘Jenkinsfile’ exists in this pull request
Met criteria

This is for this PR: amuniz/maven-helloworld#3

I understand that the first log is for the unmerged state and the second one for the merged state. But Adding some additional information would be nice.

LGTM so far.

@jglick
Copy link
Member Author

jglick commented Jun 21, 2016

I understand that the first log is for the unmerged state and the second one for the merged state. But Adding some additional information would be nice.

Yeah the indexing log needs some fine-tuning after this change.

I take it you tried running this? And did not find any serious bugs so far? Unfortunately it is time-consuming to try different combinations by hand. For example, IIRC prior to this PR, if a PR were unmergeable Jenkins would actually build a merge commit—between the branch head and the last base branch commit it merged cleanly with! Which certainly smells like a bug, albeit arguably in the GitHub API. But without an automated test suite (like #55) these kinds of corner cases are likely to regress and stay broken for months.

@amuniz
Copy link
Member

amuniz commented Jun 21, 2016

I take it you tried running this?

Yes, I did.

And did not find any serious bugs so far?

Nop, it worked fine, however I didn't test all corner cases, only the ones that came to my mind in that moment.

@KostyaSha
Copy link
Member

@jglick how you got such number imports?

@chinshr
Copy link

chinshr commented Jun 21, 2016

Looks promising /cc @rguevara84

/** Whether to build PRs filed from a fork, where the build is of the merge with the base branch. */
private @Nonnull Boolean buildForkPRMerge = DescriptorImpl.defaultBuildForkPRMerge;
/** Whether to build PRs filed from a fork, where the build is of the branch head. */
private @Nonnull Boolean buildForkPRHead = DescriptorImpl.defaultBuildForkPRHead;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT ... I'm after seeing these build* flags together in a few places in the PR. Seems like they are all closely related and could be encapsulated into a type of some sort.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the TODO comment in GitHubSCMNavigator.

@tfennelly
Copy link
Member

🐝 insofar as I get it

Made a few minor comments.

@erik-am
Copy link

erik-am commented Jun 24, 2016

Nice! Do you have any estimate when this will be in the stable release?
We've just upgraded to Jenkins 2 and wanted to build pipelines, but then found out that we can't build origin Pull Requests.
Good to hear that that functionality is on its way! 😄

@jglick
Copy link
Member Author

jglick commented Jun 24, 2016

Do you have any estimate when this will be in the stable release?

Well technically nothing is blocking me from releasing it in the next hour, though @recena expressed interest in doing some manual testing and I suspect he has no time to do it today because of other obligations.

@tfennelly saw your comments, some would be good topics for cleanups, though I am hesitant to do nonessential code changes now since it would require another round of sanity checks.

@recena
Copy link
Contributor

recena commented Jun 24, 2016

@jglick Is it urgent to merge this PR?

@shauvik
Copy link

shauvik commented Jun 24, 2016

@recena This PR is very important. Especially because pipeline is not compatible with the ghprb plugin. This will allow people to build PRs with pipelines enabled without essentially building all the branches all the time, which is a waste of resources (for most non-trivial repos).

@jglick Thanks for all the awesome work!

@recena
Copy link
Contributor

recena commented Jun 24, 2016

@shauvik I know what the PR means 😄 I'm co-maintainer of this plugin.

@KostyaSha
Copy link
Member

Especially because pipeline is not compatible with the ghprb plugin.

JFYI https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Integration+Plugin compatible long time ago even when there no branch-source-plugin.

@shauvik
Copy link

shauvik commented Jun 24, 2016

@recena Sorry, I didn't mean to offend you. Just that I'm very excited for this PR to make it in :-)

@recena
Copy link
Contributor

recena commented Jun 25, 2016

@shauvik Don't worry. What I meant is this change is important and needs to be tested and documented.

@kloarubeek
Copy link

Great work! @recena did you have time to test? We also want to build origin Pull Requests so it would be great if this moves to the stable release 😎

@jglick
Copy link
Member Author

jglick commented Jul 5, 2016

This seems to also fix JENKINS-34728.

LOGGER.log(Level.FINE, "{0}/commit/{1} {2} from {3}", new Object[] {repo.getHtmlUrl(), revision, state, url});
repo.createCommitStatus(revision, state, url, message, "Jenkins");
repo.createCommitStatus(revision, state, url, message, "Jenkins job " + job.getName());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes issues right now as it's not possible to require Jenkins status checks to pass anymore without GitHub. It relies on the name being consistent across checks, which isn't possible when the check name is always changing.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this issue has already been filed as JENKINS-36574.

@eamonnfaherty
Copy link

Can this be released? It looks like the work has been completed.

dubrsl pushed a commit to dubrsl/github-branch-source-plugin that referenced this pull request Oct 17, 2020
* Log warnings for caught GitLabApiExceptions

* Switch class loggers from org.slf4j to java.util.logging

* Fix more exception logging
dubrsl pushed a commit to dubrsl/github-branch-source-plugin that referenced this pull request Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.