aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-12-19 10:52:51 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-12-19 10:53:12 +0300
commit541f877f3d7a8b1cf9ca3c0cf080a9695887bfc2 (patch)
tree8dab7dab3301eb1257231c50d8c539e6568ffd3e
parent5fa1952a2e582f2c428584c5ccc1800132559df0 (diff)
downloadbbprb-541f877f3d7a8b1cf9ca3c0cf080a9695887bfc2.tar.gz
Refactor Environment Contributor
Use `bbprb` prefix for environment variables, export more of them.
-rw-r--r--src/main/java/org/jenkinsci/plugins/bbprb/BitbucketAdditionalParameterEnvironmentContributor.java39
-rw-r--r--src/main/java/org/jenkinsci/plugins/bbprb/BitbucketCause.java10
-rw-r--r--src/main/java/org/jenkinsci/plugins/bbprb/BitbucketEnv.java41
3 files changed, 46 insertions, 44 deletions
diff --git a/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketAdditionalParameterEnvironmentContributor.java b/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketAdditionalParameterEnvironmentContributor.java
deleted file mode 100644
index 2e9d8bc..0000000
--- a/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketAdditionalParameterEnvironmentContributor.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.jenkinsci.plugins.bbprb;
-
-import hudson.EnvVars;
-import hudson.Extension;
-import hudson.model.*;
-
-import java.io.IOException;
-
-@Extension
-public class BitbucketAdditionalParameterEnvironmentContributor
- extends EnvironmentContributor {
- @Override
- public void buildEnvironmentFor(Run run, EnvVars envVars,
- TaskListener taskListener)
- throws IOException, InterruptedException {
-
- BitbucketCause cause = (BitbucketCause)run.getCause(BitbucketCause.class);
- if (cause == null) {
- return;
- }
-
- putEnvVar(envVars, "destinationRepository",
- cause.getDestinationRepository());
- putEnvVar(envVars, "pullRequestAuthor", cause.getPullRequestAuthor());
- putEnvVar(envVars, "pullRequestId", cause.getPullRequestId());
- putEnvVar(envVars, "pullRequestTitle", cause.getPullRequestTitle());
- putEnvVar(envVars, "sourceBranch", cause.getSourceBranch());
- putEnvVar(envVars, "sourceRepository", cause.getSourceRepository());
- putEnvVar(envVars, "targetBranch", cause.getTargetBranch());
- }
-
- private static void putEnvVar(EnvVars envs, String name, String value) {
- envs.put(name, getString(value, ""));
- }
-
- private static String getString(String actual, String d) {
- return actual == null ? d : actual;
- }
-}
diff --git a/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketCause.java b/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketCause.java
index a4a20a6..026b9d4 100644
--- a/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketCause.java
+++ b/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketCause.java
@@ -7,7 +7,7 @@ import hudson.model.Cause;
*/
public class BitbucketCause extends Cause {
private final String sourceBranch;
- private final String targetBranch;
+ private final String destinationBranch;
private final String sourceRepository;
private final String pullRequestId;
private final String destinationRepository;
@@ -17,13 +17,13 @@ public class BitbucketCause extends Cause {
private final String pullRequestAuthor;
public static final String BITBUCKET_URL = "https://bitbucket.org/";
- public BitbucketCause(String sourceBranch, String targetBranch,
+ public BitbucketCause(String sourceBranch, String destinationBranch,
String sourceRepository, String pullRequestId,
String destinationRepository, String pullRequestTitle,
String sourceCommitHash, String destinationCommitHash,
String pullRequestAuthor) {
this.sourceBranch = sourceBranch;
- this.targetBranch = targetBranch;
+ this.destinationBranch = destinationBranch;
this.sourceRepository = sourceRepository;
this.pullRequestId = pullRequestId;
this.destinationRepository = destinationRepository;
@@ -36,8 +36,8 @@ public class BitbucketCause extends Cause {
public String getSourceBranch() {
return sourceBranch;
}
- public String getTargetBranch() {
- return targetBranch;
+ public String getDestinationBranch() {
+ return destinationBranch;
}
public String getSourceRepository() {
diff --git a/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketEnv.java b/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketEnv.java
new file mode 100644
index 0000000..816f57d
--- /dev/null
+++ b/src/main/java/org/jenkinsci/plugins/bbprb/BitbucketEnv.java
@@ -0,0 +1,41 @@
+package org.jenkinsci.plugins.bbprb;
+
+import hudson.EnvVars;
+import hudson.Extension;
+import hudson.model.*;
+
+import java.io.IOException;
+
+@Extension
+public class BitbucketEnv extends EnvironmentContributor {
+ @Override
+ public void buildEnvironmentFor(Run run, EnvVars envVars,
+ TaskListener taskListener)
+ throws IOException, InterruptedException {
+
+ BitbucketCause cause = (BitbucketCause)run.getCause(BitbucketCause.class);
+ if (cause == null) {
+ return;
+ }
+
+ putEnvVar(envVars, "bbprbDestinationBranch", cause.getDestinationBranch());
+ putEnvVar(envVars, "bbprbDestinationCommitHash",
+ cause.getDestinationCommitHash());
+ putEnvVar(envVars, "bbprbDestinationRepository",
+ cause.getDestinationRepository());
+ putEnvVar(envVars, "bbprbPullRequestAuthor", cause.getPullRequestAuthor());
+ putEnvVar(envVars, "bbprbPullRequestId", cause.getPullRequestId());
+ putEnvVar(envVars, "bbprbPullRequestTitle", cause.getPullRequestTitle());
+ putEnvVar(envVars, "bbprbSourceBranch", cause.getSourceBranch());
+ putEnvVar(envVars, "bbprbSourceCommitHash", cause.getSourceCommitHash());
+ putEnvVar(envVars, "bbprbSourceRepository", cause.getSourceRepository());
+ }
+
+ private static void putEnvVar(EnvVars envs, String name, String value) {
+ envs.put(name, getString(value, ""));
+ }
+
+ private static String getString(String actual, String d) {
+ return actual == null ? d : actual;
+ }
+}