Add convenience static getClient method to GitLabConnectionProperty that retrieves the GitLab client for a given build

This commit is contained in:
Robin Müller 2016-09-04 16:41:29 +02:00
parent d11d0525c1
commit 1164b2f8bf
5 changed files with 17 additions and 36 deletions

View File

@ -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<Job<?, ?>> {
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 {

View File

@ -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<Run<?, ?>> {
}
}
}
private GitLabApi getClient(Run<?, ?> run) {
GitLabConnectionProperty connectionProperty = run.getParent().getProperty(GitLabConnectionProperty.class);
if (connectionProperty != null) {
return connectionProperty.getClient();
}
return null;
}
}

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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<String> retrieveGitlabProjectIds(Run<?, ?> build, EnvVars environment) {
LOGGER.log(Level.INFO, "Retrieving gitlab project ids");