Skip to content
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

Add option to not send the "hello!" message to non-whitelisted pull request submissions #276

Open
wants to merge 81 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
9c48fd7
Adding functionality to not post commit status for children jobs
Mar 24, 2016
4c3ba5e
Improved logic flow
Mar 25, 2016
08e5a06
Fixed spacing
Mar 25, 2016
230a57f
Fixed logic, and now checking for null pointers # Please enter the co…
Mar 25, 2016
4b4fdb9
add one-line test output for upstream status
May 3, 2016
d718055
Updated showMatrixStatus with DSL and better code organization
May 4, 2016
601d2f4
Add option to avoid managing of webhooks
mmitche May 11, 2016
92303bd
Reduce API calls
mmitche Apr 28, 2016
a1bf23c
Skip Build Phrase Fix and Improvements
rsennewald May 14, 2016
b685ba3
Merge pull request #337 from mmitche/reduce-api-calls-2
DavidTanner May 20, 2016
2545683
Merge pull request #335 from mmitche/no-manage-webhooks
DavidTanner May 20, 2016
a3fa509
Merge pull request #333 from Eriten/ghprb
DavidTanner May 20, 2016
69addec
Merge pull request #331 from kyhavlov/master
DavidTanner May 20, 2016
31d5765
Update code to accomodate security fix 170
DavidTanner May 20, 2016
4acb231
Update for webhook secret
DavidTanner May 20, 2016
582a7ce
Upstream Status Listener fix to post statuses with current names for …
May 21, 2016
04b5315
Merge pull request #340 from rsennewald/339
DavidTanner May 21, 2016
07c034a
Merge pull request #344 from DavidTanner/security-170
DavidTanner May 21, 2016
95d09a9
Check if skipBuild is empty or null
DavidTanner May 21, 2016
41ee356
Merge pull request #346 from Eriten/upstreamStatusFix
DavidTanner May 21, 2016
cc6cfed
Merge pull request #347 from DavidTanner/fixes
DavidTanner May 21, 2016
d1940a7
[maven-release-plugin] prepare release ghprb-1.32.1
DavidTanner May 21, 2016
3004149
[maven-release-plugin] prepare for next development iteration
DavidTanner May 21, 2016
baee0e3
Remove adding parameters action from teh env contributor, and move it…
DavidTanner May 25, 2016
842f9c7
Just add all of the parameters
DavidTanner May 25, 2016
df3e735
Merge pull request #351 from DavidTanner/parameters
DavidTanner May 25, 2016
abbbf99
[maven-release-plugin] prepare release ghprb-1.32.2
DavidTanner May 25, 2016
8201de1
[maven-release-plugin] prepare for next development iteration
DavidTanner May 25, 2016
eff442f
Set the parameters again
DavidTanner Jun 6, 2016
5470670
Merge pull request #359 from DavidTanner/params
DavidTanner Jun 7, 2016
94c61bd
[maven-release-plugin] prepare release ghprb-1.32.3
DavidTanner Jun 7, 2016
5eba92b
[maven-release-plugin] prepare for next development iteration
DavidTanner Jun 7, 2016
2f2570d
Avoid comments check if there are no comments
mmitche Jun 7, 2016
dfee03e
Merge pull request #361 from mmitche/avoid-comments-check
DavidTanner Jun 9, 2016
bd0d210
Grab the envVars from the run
DavidTanner Jun 9, 2016
1967d36
[maven-release-plugin] prepare release ghprb-1.32.4
DavidTanner Jun 9, 2016
ea9403c
[maven-release-plugin] prepare for next development iteration
DavidTanner Jun 9, 2016
84a46cd
Pull PR data if necessary when determining mergeability
mmitche Jun 9, 2016
2a21f43
Merge pull request #365 from mmitche/mergeability-fix
DavidTanner Jun 11, 2016
6dc0795
[maven-release-plugin] prepare release ghprb-1.32.5
DavidTanner Jun 13, 2016
c82fffa
[maven-release-plugin] prepare for next development iteration
DavidTanner Jun 13, 2016
ec18ea0
Set the pull request after updating the updated timestamp
DavidTanner Jun 21, 2016
b342d67
Merge pull request #368 from DavidTanner/comments
DavidTanner Jun 21, 2016
6c0ef78
[maven-release-plugin] prepare release ghprb-1.32.6
DavidTanner Jun 21, 2016
3ff7638
[maven-release-plugin] prepare for next development iteration
DavidTanner Jun 21, 2016
4862672
Fix NullPointerException
muhqu Jun 23, 2016
9222149
update 'mergeGithubPullRequest' to 'mergePullRequest' in Job DSL sect…
Jun 29, 2016
ec6b1ed
Merge pull request #372 from taoistmath/update-dsl-publisher-name
DavidTanner Jun 30, 2016
609662f
Merge pull request #369 from muhqu/patch-1
DavidTanner Jun 30, 2016
a73bcf2
Merge pull request #362 from DavidTanner/envvars
DavidTanner Jun 30, 2016
d59a9d0
[maven-release-plugin] prepare release ghprb-1.32.7
DavidTanner Jun 30, 2016
5ac37cf
[maven-release-plugin] prepare for next development iteration
DavidTanner Jun 30, 2016
9c46eab
GetCommentsCount always returns 0 so comments never work
DavidTanner Jun 30, 2016
4e30d43
Revert "update 'mergeGithubPullRequest' to 'mergePullRequest' in Job …
taoistmath Jun 30, 2016
3935a76
Revert "update 'githubPullRequest' to 'pullRequest' in Job DSL sectio…
taoistmath Jun 30, 2016
a36a10d
Merge pull request #373 from DavidTanner/comments
DavidTanner Jun 30, 2016
5c33b1d
[maven-release-plugin] prepare release ghprb-1.32.8
DavidTanner Jun 30, 2016
f2967aa
[maven-release-plugin] prepare for next development iteration
DavidTanner Jun 30, 2016
88f8f64
Merge pull request #376 from taoistmath/revert-276-update-dsl-trigger…
DavidTanner Jun 30, 2016
4ace835
Merge pull request #375 from taoistmath/revert-372-update-dsl-publish…
DavidTanner Jun 30, 2016
f5ebb3a
Revert "update 'githubPullRequest' to 'pullRequest' in Job DSL sectio…
taoistmath Jun 30, 2016
13c2ec7
Revert "update 'mergeGithubPullRequest' to 'mergePullRequest' in Job …
taoistmath Jun 30, 2016
7ba4b76
initial Added checkbox for allowing merge without trigger phrase
dulvac Jul 6, 2016
18e97de
reverted pom changes
dulvac Jul 12, 2016
93b3a01
Allow for blacklisting of target branches
mmitche Jun 15, 2016
a1f4ab2
Add build description template to Job DSL extension
pdalpra Jul 19, 2016
46b9ebf
Merge pull request #381 from dulvac/master
DavidTanner Jul 19, 2016
f39bb0a
Merge pull request #384 from pdalpra/jobdsl-build-description-template
DavidTanner Jul 19, 2016
6239345
Merge pull request #367 from mmitche/blacklist-target-branches
DavidTanner Jul 19, 2016
b8a3f62
[maven-release-plugin] prepare release ghprb-1.33.0
DavidTanner Jul 19, 2016
f30dcc8
[maven-release-plugin] prepare for next development iteration
DavidTanner Jul 19, 2016
290481c
Add DS_Store
fbelzunc Jul 28, 2016
adfab1f
Merge pull request #390 from fbelzunc/gitignore
DavidTanner Jul 28, 2016
5913f63
Handle "edited" pull-request hooks
Jul 26, 2016
6ada2cf
Merge pull request #391 from callebjorkell/edited-hook
DavidTanner Jul 29, 2016
b99c41c
Fix comment for release check
DavidTanner Aug 4, 2016
de2b68e
Avoid null pointer exception when creating hooks
DavidTanner Aug 4, 2016
ca0a995
Merge pull request #392 from DavidTanner/nullPointer
DavidTanner Aug 4, 2016
fa3ad05
[maven-release-plugin] prepare release ghprb-1.33.1
DavidTanner Aug 4, 2016
c8e4f80
github -> GitHub
ssk2 Jun 1, 2016
f0daaf6
Rebase comment suppressor against 1.31
Sep 7, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ bin/
*.ipr
*.iws
.idea/

# OS X
.DS_Store
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build.

A new build can also be started with a comment: ``retest this please``.

You can extend the standard build comment message on github
You can extend the standard build comment message on GitHub
creating a comment file from shell console or any other
jenkins plugin. Contents of that file will be added to the comment on GitHub.
This is useful for posting some build dependent urls for users without
Expand Down Expand Up @@ -93,7 +93,7 @@ For more details, see https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+re
* If you want to use the actual commit in the pull request, use ``${ghprbActualCommit}`` instead of ``${sha1}``
* Under ``Build Triggers``, check ``GitHub pull requests builder``.
* Add admins for this specific job.
* If you want to use GitHub hooks for automatic testing, read the help for ``Use github hooks for build triggering`` in job configuration. Then you can check the checkbox.
* If you want to use GitHub hooks for automatic testing, read the help for ``Use GitHub hooks for build triggering`` in job configuration. Then you can check the checkbox.
* In Advanced, you can modify:
* The crontab line for this specific job. This schedules polling to GitHub for new changes in Pull Requests.
* The whitelisted users for this specific job.
Expand Down Expand Up @@ -128,7 +128,7 @@ job('upstreamJob') {
}

triggers {
pullRequest {
githubPullRequest {
admin('user_1')
admins(['user_2', 'user_3'])
userWhitelist('[email protected]')
Expand All @@ -143,6 +143,7 @@ job('upstreamJob') {
autoCloseFailedPullRequests()
displayBuildErrorsOnDownstreamBuilds()
whiteListTargetBranches(['master','test', 'test2'])
blackListListTargetBranches(['master','test', 'test2'])
allowMembersOfWhitelistedOrgsAsAdmin()
extensions {
commitStatus {
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<artifactId>ghprb</artifactId>
<name>GitHub Pull Request Builder</name>
<version>1.31.5-SNAPSHOT</version>
<version>1.33.1</version>
<packaging>hpi</packaging>

<url>https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin</url>
Expand All @@ -26,13 +26,13 @@
<name>Valdis Rigdon</name>
</developer>
</developers>

<scm>
<connection>scm:git:ssh://github.com/jenkinsci/ghprb-plugin.git</connection>
<developerConnection>scm:git:ssh://[email protected]/jenkinsci/ghprb-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/ghprb-plugin</url>
<tag>HEAD</tag>
</scm>
<tag>ghprb-1.33.1</tag>
</scm>


<issueManagement>
<system>GitHub</system>
Expand Down
41 changes: 35 additions & 6 deletions src/main/java/org/jenkinsci/plugins/ghprb/Ghprb.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,48 @@ private Pattern retestPhrasePattern() {
* @return skip build phrases
*/
public Set<String> getSkipBuildPhrases() {
return new HashSet<String>(Arrays.asList(GhprbTrigger.getDscp().getSkipBuildPhrase().split("[\\r\\n]+")));
return new HashSet<String>(Arrays.asList(getTrigger().getSkipBuildPhrase().split("[\\r\\n]+")));
}

/**
* Checks for skip build phrase in pull request comment. If present it updates shouldRun as false.
* Checks for skip build phrase in pull request title and body. If present it updates shouldRun as false.
*
* @param issue The GitHub issue
* @return the skip phrase or null if should not skip
*/
public String checkSkipBuild(GHIssue issue) {
// check for skip build phrase.
// check in title
String pullRequestTitle = issue.getTitle();
String skipBuildPhrase = checkSkipBuildInString(pullRequestTitle);
if (StringUtils.isNotBlank(skipBuildPhrase)) {
return skipBuildPhrase;
}
// not found in title, check in body
String pullRequestBody = issue.getBody();
if (StringUtils.isNotBlank(pullRequestBody)) {
pullRequestBody = pullRequestBody.trim();
skipBuildPhrase = checkSkipBuildInString(pullRequestBody);
if (StringUtils.isNotBlank(skipBuildPhrase)) {
return skipBuildPhrase;
}
return null;
}

/**
* Checks for skip build phrase in the passed string
*
* @param string The string we're looking for the phrase in
* @return the skip phrase or null if we don't find it
*/
private String checkSkipBuildInString( String string ) {
// check for skip build phrase in the passed string
if (StringUtils.isNotBlank(string)) {
string = string.trim();
Set<String> skipBuildPhrases = getSkipBuildPhrases();
skipBuildPhrases.remove("");

for (String skipBuildPhrase : skipBuildPhrases) {
skipBuildPhrase = skipBuildPhrase.trim();
Pattern skipBuildPhrasePattern = compilePattern(skipBuildPhrase);
if (skipBuildPhrasePattern != null && skipBuildPhrasePattern.matcher(pullRequestBody).matches()) {
if (skipBuildPhrasePattern != null && skipBuildPhrasePattern.matcher(string).matches()) {
return skipBuildPhrase;
}
}
Expand Down Expand Up @@ -188,6 +209,10 @@ public boolean isTriggerPhrase(String comment) {
public boolean ifOnlyTriggerPhrase() {
return trigger.getOnlyTriggerPhrase();
}

public boolean suppressTestingRequest() {
return trigger.getSuppressTestingRequest();
}

public boolean isWhitelisted(GHUser user) {
return trigger.getPermitAll()
Expand Down Expand Up @@ -215,6 +240,10 @@ private boolean isInWhitelistedOrganisation(GHUser user) {
return false;
}

List<GhprbBranch> getBlackListTargetBranches() {
return trigger.getBlackListTargetBranches();
}

List<GhprbBranch> getWhiteListTargetBranches() {
return trigger.getWhiteListTargetBranches();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.jenkinsci.plugins.ghprb;

import hudson.EnvVars;
import hudson.Extension;
import hudson.model.EnvironmentContributor;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.Run;
import hudson.model.StringParameterValue;
import hudson.model.TaskListener;

import javax.annotation.Nonnull;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

@Extension
public class GhprbAdditionalParameterEnvironmentContributor extends EnvironmentContributor {

private static Set<String> params =
new HashSet<String>(Arrays.asList("sha1",
"ghprbCredentialsId",
"ghprbActualCommit",
"ghprbPullId",
"ghprbPullDescription",
"ghprbPullTitle",
"ghprbPullLink",
"ghprbPullLongDescription",
"ghprbTargetBranch",
"ghprbSourceBranch",
"ghprbCommentBody",
"ghprbGhRepository",
"ghprbTriggerAuthor",
"ghprbTriggerAuthorEmail",
"ghprbTriggerAuthorLogin",
"ghprbTriggerAuthorLoginMention",
"GIT_BRANCH",
"ghprbPullAuthorEmail",
"ghprbPullAuthorLogin",
"ghprbPullAuthorLoginMention",
"ghprbAuthorRepoGitUrl",
"ghprbActualCommitAuthor",
"ghprbActualCommitAuthorEmail"));

@Override
@SuppressWarnings("rawtypes")
public void buildEnvironmentFor(@Nonnull Run run,
@Nonnull EnvVars envs,
@Nonnull TaskListener listener) throws IOException, InterruptedException {
GhprbCause cause = (GhprbCause) ((Run<?, ?>) run).getCause(GhprbCause.class);
if (cause == null || envs.containsKey(params.iterator().next())) {
return;
}

ParametersAction pa = run.getAction(ParametersAction.class);
for (String param : params) {
addParameter(param, pa, envs);
}
}

private static void addParameter(String key,
ParametersAction pa,
EnvVars envs) {
ParameterValue pv = pa.getParameter(key);
if (pv == null || !(pv instanceof StringParameterValue)) {
return;
}
StringParameterValue value = (StringParameterValue) pa.getParameter(key);
envs.put(key, getString(value.value, ""));
}

private static String getString(String actual,
String d) {
return actual == null ? d : actual;
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/jenkinsci/plugins/ghprb/GhprbBuilds.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public void build(GhprbPullRequest pr, GHUser triggerSender, String commentBody)
pr.getCommitAuthor(),
prAuthor,
pr.getDescription(),
pr.getAuthorRepoGitUrl());
pr.getAuthorRepoGitUrl(),
repo.getName(),
trigger.getGitHubApiAuth().getCredentialsId());

for (GhprbExtension ext : Ghprb.getJobExtensions(trigger, GhprbCommitStatus.class)) {
if (ext instanceof GhprbCommitStatus) {
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/jenkinsci/plugins/ghprb/GhprbCause.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class GhprbCause extends Cause {
private final GHUser pullRequestAuthor;
private final String description;
private final String authorRepoGitUrl;
private final String repoName;
private final String credentialsId;

public GhprbCause(String commit,
int pullID,
Expand All @@ -40,7 +42,9 @@ public GhprbCause(String commit,
GitUser commitAuthor,
GHUser pullRequestAuthor,
String description,
String authorRepoGitUrl) {
String authorRepoGitUrl,
String repoName,
String credentialsId) {

this.commit = commit;
this.pullID = pullID;
Expand All @@ -57,6 +61,8 @@ public GhprbCause(String commit,
this.commitAuthor = commitAuthor;
this.pullRequestAuthor = pullRequestAuthor;
this.authorRepoGitUrl = authorRepoGitUrl;
this.repoName = repoName;
this.credentialsId = credentialsId;
}

@Override
Expand Down Expand Up @@ -132,4 +138,12 @@ public String getDescription() {
public String getAuthorRepoGitUrl() {
return authorRepoGitUrl;
}

public String getRepositoryName() {
return repoName;
}

public String getCredentialsId() {
return credentialsId;
}
}
11 changes: 6 additions & 5 deletions src/main/java/org/jenkinsci/plugins/ghprb/GhprbGitHubAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import hudson.security.ACL;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import hudson.util.Secret;

public class GhprbGitHubAuth extends AbstractDescribableImpl<GhprbGitHubAuth> {
private static final Logger logger = Logger.getLogger(GhprbGitHubAuth.class.getName());
Expand All @@ -61,7 +62,7 @@ public class GhprbGitHubAuth extends AbstractDescribableImpl<GhprbGitHubAuth> {
private final String credentialsId;
private final String id;
private final String description;
private final String secret;
private final Secret secret;

private transient GitHub gh;

Expand All @@ -72,7 +73,7 @@ public GhprbGitHubAuth(
String credentialsId,
String description,
String id,
String secret
Secret secret
) {
if (StringUtils.isEmpty(serverAPIUrl)) {
serverAPIUrl = "https://api.github.com";
Expand Down Expand Up @@ -116,21 +117,21 @@ public String getId() {


@Exported
public String getSecret() {
public Secret getSecret() {
return secret;
}


public boolean checkSignature(String body, String signature) {
if (StringUtils.isEmpty(secret)) {
if (secret == null || StringUtils.isEmpty(secret.getPlainText())) {
return true;
}

if (signature != null && signature.startsWith("sha1=")) {
String expected = signature.substring(5);
String algorithm = "HmacSHA1";
try {
SecretKeySpec keySpec = new SecretKeySpec(secret.getBytes(), algorithm);
SecretKeySpec keySpec = new SecretKeySpec(secret.getPlainText().getBytes(), algorithm);
Mac mac = Mac.getInstance(algorithm);
mac.init(keySpec);
byte[] localSignatureBytes = mac.doFinal(body.getBytes("UTF-8"));
Expand Down
Loading