From 1164b2f8bf25600ba6b293f3b90bf5755b5cc0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Sun, 4 Sep 2016 16:41:29 +0200 Subject: [PATCH] Add convenience static getClient method to GitLabConnectionProperty that retrieves the GitLab client for a given build --- .../connection/GitLabConnectionProperty.java | 9 +++++++++ .../listener/GitLabMergeRequestRunListener.java | 11 ++--------- .../publisher/GitLabMessagePublisher.java | 11 ++--------- .../gitlabjenkins/publisher/GitLabVotePublisher.java | 11 ++--------- .../gitlabjenkins/util/CommitStatusUpdater.java | 11 ++--------- 5 files changed, 17 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/dabsquared/gitlabjenkins/connection/GitLabConnectionProperty.java b/src/main/java/com/dabsquared/gitlabjenkins/connection/GitLabConnectionProperty.java index e6f47a2..3f53512 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/connection/GitLabConnectionProperty.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/connection/GitLabConnectionProperty.java @@ -5,6 +5,7 @@ import hudson.Extension; import hudson.model.Job; import hudson.model.JobProperty; import hudson.model.JobPropertyDescriptor; +import hudson.model.Run; import hudson.util.ListBoxModel; import jenkins.model.Jenkins; import net.sf.json.JSONObject; @@ -36,6 +37,14 @@ public class GitLabConnectionProperty extends JobProperty> { return null; } + public static GitLabApi getClient(Run build) { + final GitLabConnectionProperty connectionProperty = build.getParent().getProperty(GitLabConnectionProperty.class); + if (connectionProperty != null) { + return connectionProperty.getClient(); + } + return null; + } + @Extension public static class DescriptorImpl extends JobPropertyDescriptor { diff --git a/src/main/java/com/dabsquared/gitlabjenkins/listener/GitLabMergeRequestRunListener.java b/src/main/java/com/dabsquared/gitlabjenkins/listener/GitLabMergeRequestRunListener.java index 26fdc87..69df781 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/listener/GitLabMergeRequestRunListener.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/listener/GitLabMergeRequestRunListener.java @@ -3,7 +3,6 @@ package com.dabsquared.gitlabjenkins.listener; import com.dabsquared.gitlabjenkins.GitLabPushTrigger; import com.dabsquared.gitlabjenkins.cause.CauseData; import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause; -import com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty; import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi; import hudson.Extension; import hudson.model.Result; @@ -16,6 +15,8 @@ import javax.annotation.Nonnull; import javax.ws.rs.ProcessingException; import javax.ws.rs.WebApplicationException; +import static com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.getClient; + /** * @author Robin Müller */ @@ -55,12 +56,4 @@ public class GitLabMergeRequestRunListener extends RunListener> { } } } - - private GitLabApi getClient(Run run) { - GitLabConnectionProperty connectionProperty = run.getParent().getProperty(GitLabConnectionProperty.class); - if (connectionProperty != null) { - return connectionProperty.getClient(); - } - return null; - } } diff --git a/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabMessagePublisher.java b/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabMessagePublisher.java index b862146..140bc67 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabMessagePublisher.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabMessagePublisher.java @@ -1,7 +1,6 @@ package com.dabsquared.gitlabjenkins.publisher; import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause; -import com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty; import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi; import hudson.Extension; import hudson.Launcher; @@ -28,6 +27,8 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import static com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.getClient; + /** * @author Nikolay Ustinov */ @@ -144,14 +145,6 @@ public class GitLabMessagePublisher extends Notifier { } } - private static GitLabApi getClient(Run build) { - GitLabConnectionProperty connectionProperty = build.getParent().getProperty(GitLabConnectionProperty.class); - if (connectionProperty != null) { - return connectionProperty.getClient(); - } - return null; - } - private static String replaceMacros(Run build, TaskListener listener, String inputString) { String returnString = inputString; if (build != null && inputString != null) { diff --git a/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabVotePublisher.java b/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabVotePublisher.java index 2852e9c..1d6cd2b 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabVotePublisher.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabVotePublisher.java @@ -1,7 +1,6 @@ package com.dabsquared.gitlabjenkins.publisher; import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause; -import com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty; import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi; import hudson.Extension; import hudson.Launcher; @@ -23,6 +22,8 @@ import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import static com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.getClient; + /** * @author Robin Müller */ @@ -91,12 +92,4 @@ public class GitLabVotePublisher extends Notifier { return ":-1:"; } } - - private static GitLabApi getClient(Run build) { - GitLabConnectionProperty connectionProperty = build.getParent().getProperty(GitLabConnectionProperty.class); - if (connectionProperty != null) { - return connectionProperty.getClient(); - } - return null; - } } diff --git a/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java b/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java index f67e88b..2e27eb1 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java @@ -1,7 +1,6 @@ package com.dabsquared.gitlabjenkins.util; import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause; -import com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty; import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi; import com.dabsquared.gitlabjenkins.gitlab.api.model.BuildState; import hudson.EnvVars; @@ -23,6 +22,8 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import static com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.getClient; + /** * @author Robin Müller */ @@ -110,14 +111,6 @@ public class CommitStatusUpdater { return Jenkins.getInstance().getRootUrl() + build.getUrl(); } - private static GitLabApi getClient(Run build) { - final GitLabConnectionProperty connectionProperty = build.getParent().getProperty(GitLabConnectionProperty.class); - if (connectionProperty != null) { - return connectionProperty.getClient(); - } - return null; - } - private static List retrieveGitlabProjectIds(Run build, EnvVars environment) { LOGGER.log(Level.INFO, "Retrieving gitlab project ids");