Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 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
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
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
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ job('upstreamJob') {
}

triggers {
pullRequest {
githubPullRequest {
admin('user_1')
admins(['user_2', 'user_3'])
userWhitelist('you@you.com')
Expand Down
5 changes: 2 additions & 3 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.32.9-SNAPSHOT</version>
<packaging>hpi</packaging>

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

<scm>
<connection>scm:git:ssh://github.com/jenkinsci/ghprb-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/jenkinsci/ghprb-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/ghprb-plugin</url>
<tag>HEAD</tag>
</scm>


<issueManagement>
<system>GitHub</system>
<url>https://github.com/janinko/ghprb/issues</url>
Expand Down
33 changes: 27 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
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