parent
558502510e
commit
b9efc8ac91
|
@ -1,5 +1,6 @@
|
|||
package com.dabsquared.gitlabjenkins.cause;
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import hudson.markup.EscapedMarkupFormatter;
|
||||
import jenkins.model.Jenkins;
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
|
@ -298,6 +299,15 @@ public final class CauseData {
|
|||
return mergeRequestAssignee;
|
||||
}
|
||||
|
||||
public MergeRequest getMergeRequest() {
|
||||
if (mergeRequestId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MergeRequest(mergeRequestId, mergeRequestIid, sourceBranch, targetBranch, mergeRequestTitle,
|
||||
sourceProjectId, targetProjectId, mergeRequestDescription, mergeRequestState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
@ -506,7 +516,7 @@ public final class CauseData {
|
|||
|
||||
private final Map<K, V> map;
|
||||
|
||||
public MapWrapper(Map<K, V> map) {
|
||||
MapWrapper(Map<K, V> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
|
@ -520,7 +530,7 @@ public final class CauseData {
|
|||
return map.entrySet();
|
||||
}
|
||||
|
||||
public void pufIfNotNull(K key, V value) {
|
||||
void pufIfNotNull(K key, V value) {
|
||||
if (value != null) {
|
||||
map.put(key, value);
|
||||
}
|
||||
|
|
|
@ -1,125 +1,50 @@
|
|||
package com.dabsquared.gitlabjenkins.gitlab.api;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.*;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.State;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GitLabClient {
|
||||
String getHostUrl();
|
||||
|
||||
public final class GitLabClient implements GitLabApi {
|
||||
private final String hostUrl;
|
||||
private final GitLabApi api;
|
||||
Project createProject(String projectName);
|
||||
|
||||
@Restricted(NoExternalUse.class)
|
||||
public GitLabClient(String hostUrl, GitLabApi api) {
|
||||
this.hostUrl = hostUrl;
|
||||
this.api = api;
|
||||
}
|
||||
MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title);
|
||||
|
||||
public final String getHostUrl() {
|
||||
return hostUrl;
|
||||
}
|
||||
Project getProject(String projectName);
|
||||
|
||||
@Override
|
||||
public Project createProject(String projectName) {
|
||||
return api.createProject(projectName);
|
||||
}
|
||||
Project updateProject(String projectId, String name, String path);
|
||||
|
||||
@Override
|
||||
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title) {
|
||||
return api.createMergeRequest(projectId, sourceBranch, targetBranch, title);
|
||||
}
|
||||
void deleteProject(String projectId);
|
||||
|
||||
@Override
|
||||
public Project getProject(String projectName) {
|
||||
return api.getProject(projectName);
|
||||
}
|
||||
void addProjectHook(String projectId, String url, Boolean pushEvents, Boolean mergeRequestEvents, Boolean noteEvents);
|
||||
|
||||
@Override
|
||||
public Project updateProject(String projectId, String name, String path) {
|
||||
return api.updateProject(projectId, name, path);
|
||||
}
|
||||
void changeBuildStatus(String projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description);
|
||||
|
||||
@Override
|
||||
public void deleteProject(String projectId) {
|
||||
api.deleteProject(projectId);
|
||||
}
|
||||
void changeBuildStatus(Integer projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description);
|
||||
|
||||
@Override
|
||||
public void addProjectHook(String projectId, String url, Boolean pushEvents, Boolean mergeRequestEvents, Boolean noteEvents) {
|
||||
api.addProjectHook(projectId, url, pushEvents, mergeRequestEvents, noteEvents);
|
||||
}
|
||||
void getCommit(String projectId, String sha);
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(String projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
api.changeBuildStatus(projectId, sha, state, ref, context, targetUrl, description);
|
||||
}
|
||||
void acceptMergeRequest(MergeRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch);
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(Integer projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
api.changeBuildStatus(projectId, sha, state, ref, context, targetUrl, description);
|
||||
}
|
||||
void createMergeRequestNote(MergeRequest mr, String body);
|
||||
|
||||
@Override
|
||||
public void getCommit(String projectId, String sha) {
|
||||
api.getCommit(projectId, sha);
|
||||
}
|
||||
List<MergeRequest> getMergeRequests(String projectId, State state, int page, int perPage);
|
||||
|
||||
@Override
|
||||
public void acceptMergeRequest(Integer projectId, Integer mergeRequestId, String mergeCommitMessage, boolean shouldRemoveSourceBranch) {
|
||||
api.acceptMergeRequest(projectId, mergeRequestId, mergeCommitMessage, shouldRemoveSourceBranch);
|
||||
}
|
||||
List<Branch> getBranches(String projectId);
|
||||
|
||||
@Override
|
||||
public void createMergeRequestNote(Integer projectId, Integer mergeRequestId, String body) {
|
||||
api.createMergeRequestNote(projectId, mergeRequestId, body);
|
||||
}
|
||||
Branch getBranch(String projectId, String branch);
|
||||
|
||||
@Override
|
||||
public List<MergeRequest> getMergeRequests(String projectId, State state, int page, int perPage) {
|
||||
return api.getMergeRequests(projectId, state, page, perPage);
|
||||
}
|
||||
void headCurrentUser();
|
||||
|
||||
@Override
|
||||
public List<Branch> getBranches(String projectId) {
|
||||
return api.getBranches(projectId);
|
||||
}
|
||||
User getCurrentUser();
|
||||
|
||||
@Override
|
||||
public Branch getBranch(String projectId, String branch) {
|
||||
return api.getBranch(projectId, branch);
|
||||
}
|
||||
User addUser(String email, String username, String name, String password);
|
||||
|
||||
@Override
|
||||
public void headCurrentUser() {
|
||||
api.headCurrentUser();
|
||||
}
|
||||
User updateUser(String userId, String email, String username, String name, String password);
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return api.getCurrentUser();
|
||||
}
|
||||
List<Label> getLabels(String projectId);
|
||||
|
||||
@Override
|
||||
public User addUser(String email, String username, String name, String password) {
|
||||
return api.addUser(email, username, name, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User updateUser(String userId, String email, String username, String name, String password) {
|
||||
return api.updateUser(userId, email, username, name, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Label> getLabels(String projectId) {
|
||||
return api.getLabels(projectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pipeline> getPipelines(String projectName) {
|
||||
return api.getPipelines(projectName);
|
||||
}
|
||||
List<Pipeline> getPipelines(String projectName);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,6 @@ public final class AutodetectGitLabClientBuilder extends GitLabClientBuilder {
|
|||
public GitLabClient buildClient(String url, String token, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
Collection<GitLabClientBuilder> candidates = new ArrayList<>(getAllGitLabClientBuilders());
|
||||
candidates.remove(this);
|
||||
return new GitLabClient(url, new AutodetectingGitlabApi(candidates, url, token, ignoreCertificateErrors, connectionTimeout, readTimeout));
|
||||
return new AutodetectingGitLabClient(candidates, url, token, ignoreCertificateErrors, connectionTimeout, readTimeout);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClientBuilder;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Branch;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.BuildState;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Label;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Pipeline;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Project;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.User;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.*;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.State;
|
||||
|
||||
import javax.ws.rs.NotFoundException;
|
||||
|
@ -18,17 +11,17 @@ import java.util.List;
|
|||
import java.util.NoSuchElementException;
|
||||
|
||||
|
||||
final class AutodetectingGitlabApi implements GitLabApi {
|
||||
final class AutodetectingGitLabClient implements GitLabClient {
|
||||
private final Iterable<GitLabClientBuilder> builders;
|
||||
private final String url;
|
||||
private final String token;
|
||||
private final boolean ignoreCertificateErrors;
|
||||
private final int connectionTimeout;
|
||||
private final int readTimeout;
|
||||
private GitLabApi delegate;
|
||||
private GitLabClient delegate;
|
||||
|
||||
|
||||
AutodetectingGitlabApi(Iterable<GitLabClientBuilder> builders, String url, String token, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
AutodetectingGitLabClient(Iterable<GitLabClientBuilder> builders, String url, String token, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
this.builders = builders;
|
||||
this.url = url;
|
||||
this.token = token;
|
||||
|
@ -37,13 +30,18 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project createProject(final String projectName) {
|
||||
return execute(
|
||||
new GitLabOperation<Project>() {
|
||||
@Override
|
||||
Project execute(GitLabApi api) {
|
||||
return api.createProject(projectName);
|
||||
Project execute(GitLabClient client) {
|
||||
return client.createProject(projectName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -53,8 +51,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<MergeRequest>() {
|
||||
@Override
|
||||
MergeRequest execute(GitLabApi api) {
|
||||
return api.createMergeRequest(projectId, sourceBranch, targetBranch, title);
|
||||
MergeRequest execute(GitLabClient client) {
|
||||
return client.createMergeRequest(projectId, sourceBranch, targetBranch, title);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -64,8 +62,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<Project>() {
|
||||
@Override
|
||||
Project execute(GitLabApi api) {
|
||||
return api.getProject(projectName);
|
||||
Project execute(GitLabClient client) {
|
||||
return client.getProject(projectName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -75,8 +73,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<Project>() {
|
||||
@Override
|
||||
Project execute(GitLabApi api) {
|
||||
return api.updateProject(projectId, name, path);
|
||||
Project execute(GitLabClient client) {
|
||||
return client.updateProject(projectId, name, path);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -86,8 +84,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
execute(
|
||||
new GitLabOperation<Void>() {
|
||||
@Override
|
||||
Void execute(GitLabApi api) {
|
||||
api.deleteProject(projectId);
|
||||
Void execute(GitLabClient client) {
|
||||
client.deleteProject(projectId);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -98,8 +96,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
execute(
|
||||
new GitLabOperation<Void>() {
|
||||
@Override
|
||||
Void execute(GitLabApi api) {
|
||||
api.addProjectHook(projectId, url, pushEvents, mergeRequestEvents, noteEvents);
|
||||
Void execute(GitLabClient client) {
|
||||
client.addProjectHook(projectId, url, pushEvents, mergeRequestEvents, noteEvents);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -110,8 +108,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
execute(
|
||||
new GitLabOperation<Void>() {
|
||||
@Override
|
||||
Void execute(GitLabApi api) {
|
||||
api.changeBuildStatus(projectId, sha, state, ref, context, targetUrl, description);
|
||||
Void execute(GitLabClient client) {
|
||||
client.changeBuildStatus(projectId, sha, state, ref, context, targetUrl, description);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -122,8 +120,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
execute(
|
||||
new GitLabOperation<Void>() {
|
||||
@Override
|
||||
Void execute(GitLabApi api) {
|
||||
api.changeBuildStatus(projectId, sha, state, ref, context, targetUrl, description);
|
||||
Void execute(GitLabClient client) {
|
||||
client.changeBuildStatus(projectId, sha, state, ref, context, targetUrl, description);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -134,35 +132,37 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
execute(
|
||||
new GitLabOperation<Void>() {
|
||||
@Override
|
||||
Void execute(GitLabApi api) {
|
||||
api.getCommit(projectId, sha);
|
||||
Void execute(GitLabClient client) {
|
||||
client.getCommit(projectId, sha);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptMergeRequest(final Integer projectId, final Integer mergeRequestId, final String mergeCommitMessage, final boolean shouldRemoveSourceBranch) {
|
||||
public void acceptMergeRequest(final MergeRequest mr, final String mergeCommitMessage, final boolean shouldRemoveSourceBranch) {
|
||||
execute(
|
||||
new GitLabOperation<Void>() {
|
||||
@Override
|
||||
Void execute(GitLabApi api) {
|
||||
api.acceptMergeRequest(projectId, mergeRequestId, mergeCommitMessage, shouldRemoveSourceBranch);
|
||||
Void execute(GitLabClient client) {
|
||||
client.acceptMergeRequest(mr, mergeCommitMessage, shouldRemoveSourceBranch);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMergeRequestNote(final Integer projectId, final Integer mergeRequestId, final String body) {
|
||||
public void createMergeRequestNote(final MergeRequest mr, final String body) {
|
||||
execute(
|
||||
new GitLabOperation<Void>() {
|
||||
@Override
|
||||
Void execute(GitLabApi api) {
|
||||
api.createMergeRequestNote(projectId, mergeRequestId, body);
|
||||
Void execute(GitLabClient client) {
|
||||
client.createMergeRequestNote(mr, body);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,8 +170,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<List<MergeRequest>>() {
|
||||
@Override
|
||||
List<MergeRequest> execute(GitLabApi api) {
|
||||
return api.getMergeRequests(projectId, state, page, perPage);
|
||||
List<MergeRequest> execute(GitLabClient client) {
|
||||
return client.getMergeRequests(projectId, state, page, perPage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -181,8 +181,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<List<Branch>>() {
|
||||
@Override
|
||||
List<Branch> execute(GitLabApi api) {
|
||||
return api.getBranches(projectId);
|
||||
List<Branch> execute(GitLabClient client) {
|
||||
return client.getBranches(projectId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -192,8 +192,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<Branch>() {
|
||||
@Override
|
||||
Branch execute(GitLabApi api) {
|
||||
return api.getBranch(projectId, branch);
|
||||
Branch execute(GitLabClient client) {
|
||||
return client.getBranch(projectId, branch);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -203,8 +203,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
execute(
|
||||
new GitLabOperation<Void>() {
|
||||
@Override
|
||||
Void execute(GitLabApi api) {
|
||||
api.headCurrentUser();
|
||||
Void execute(GitLabClient client) {
|
||||
client.headCurrentUser();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -215,8 +215,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<User>() {
|
||||
@Override
|
||||
User execute(GitLabApi api) {
|
||||
return api.getCurrentUser();
|
||||
User execute(GitLabClient client) {
|
||||
return client.getCurrentUser();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -226,8 +226,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<User>() {
|
||||
@Override
|
||||
User execute(GitLabApi api) {
|
||||
return api.addUser(email, username, name, password);
|
||||
User execute(GitLabClient client) {
|
||||
return client.addUser(email, username, name, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -237,8 +237,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<User>() {
|
||||
@Override
|
||||
User execute(GitLabApi api) {
|
||||
return api.updateUser(userId, email, username, name, password);
|
||||
User execute(GitLabClient client) {
|
||||
return client.updateUser(userId, email, username, name, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -248,8 +248,8 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<List<Label>>() {
|
||||
@Override
|
||||
List<Label> execute(GitLabApi api) {
|
||||
return api.getLabels(projectId);
|
||||
List<Label> execute(GitLabClient client) {
|
||||
return client.getLabels(projectId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -259,14 +259,14 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
return execute(
|
||||
new GitLabOperation<List<Pipeline>>() {
|
||||
@Override
|
||||
List<Pipeline> execute(GitLabApi api) {
|
||||
return api.getPipelines(projectName);
|
||||
List<Pipeline> execute(GitLabClient client) {
|
||||
return client.getPipelines(projectName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private GitLabApi delegate(boolean reset) {
|
||||
private GitLabClient delegate(boolean reset) {
|
||||
if (reset || delegate == null) {
|
||||
delegate = autodetectOrDie();
|
||||
}
|
||||
|
@ -316,6 +316,6 @@ final class AutodetectingGitlabApi implements GitLabApi {
|
|||
}
|
||||
|
||||
|
||||
abstract R execute(GitLabApi api);
|
||||
abstract R execute(GitLabClient client);
|
||||
}
|
||||
}
|
|
@ -1,22 +1,13 @@
|
|||
package com.dabsquared.gitlabjenkins.gitlab.api;
|
||||
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Branch;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.BuildState;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Label;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Pipeline;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Project;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.User;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.*;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.State;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Restricted(NoExternalUse.class)
|
||||
public interface GitLabApi {
|
||||
interface GitLabApiProxy {
|
||||
Project createProject(String projectName);
|
||||
|
||||
MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title);
|
|
@ -0,0 +1,127 @@
|
|||
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.*;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.State;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
final class ResteasyGitLabClient implements GitLabClient {
|
||||
private final String hostUrl;
|
||||
private final GitLabApiProxy api;
|
||||
private final Function<MergeRequest, Integer> mergeRequestIdProvider;
|
||||
|
||||
ResteasyGitLabClient(String hostUrl, GitLabApiProxy api, Function<MergeRequest, Integer> mergeRequestIdProvider) {
|
||||
this.hostUrl = hostUrl;
|
||||
this.api = api;
|
||||
this.mergeRequestIdProvider = mergeRequestIdProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getHostUrl() {
|
||||
return hostUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project createProject(String projectName) {
|
||||
return api.createProject(projectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title) {
|
||||
return api.createMergeRequest(projectId, sourceBranch, targetBranch, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject(String projectName) {
|
||||
return api.getProject(projectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project updateProject(String projectId, String name, String path) {
|
||||
return api.updateProject(projectId, name, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProject(String projectId) {
|
||||
api.deleteProject(projectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProjectHook(String projectId, String url, Boolean pushEvents, Boolean mergeRequestEvents, Boolean noteEvents) {
|
||||
api.addProjectHook(projectId, url, pushEvents, mergeRequestEvents, noteEvents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(String projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
api.changeBuildStatus(projectId, sha, state, ref, context, targetUrl, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(Integer projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
api.changeBuildStatus(projectId, sha, state, ref, context, targetUrl, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getCommit(String projectId, String sha) {
|
||||
api.getCommit(projectId, sha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptMergeRequest(MergeRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch) {
|
||||
api.acceptMergeRequest(mr.getProjectId(), mergeRequestIdProvider.apply(mr), mergeCommitMessage, shouldRemoveSourceBranch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMergeRequestNote(MergeRequest mr, String body) {
|
||||
api.createMergeRequestNote(mr.getProjectId(), mergeRequestIdProvider.apply(mr), body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MergeRequest> getMergeRequests(String projectId, State state, int page, int perPage) {
|
||||
return api.getMergeRequests(projectId, state, page, perPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Branch> getBranches(String projectId) {
|
||||
return api.getBranches(projectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Branch getBranch(String projectId, String branch) {
|
||||
return api.getBranch(projectId, branch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headCurrentUser() {
|
||||
api.headCurrentUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return api.getCurrentUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User addUser(String email, String username, String name, String password) {
|
||||
return api.addUser(email, username, name, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User updateUser(String userId, String email, String username, String name, String password) {
|
||||
return api.updateUser(userId, email, username, name, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Label> getLabels(String projectId) {
|
||||
return api.getLabels(projectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pipeline> getPipelines(String projectName) {
|
||||
return api.getPipelines(projectName);
|
||||
}
|
||||
}
|
|
@ -2,9 +2,9 @@ package com.dabsquared.gitlabjenkins.gitlab.api.impl;
|
|||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.JacksonConfig;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClientBuilder;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import com.dabsquared.gitlabjenkins.util.JsonUtil;
|
||||
import com.dabsquared.gitlabjenkins.util.LoggerUtil;
|
||||
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
|
||||
|
@ -66,24 +66,21 @@ public class ResteasyGitLabClientBuilder extends GitLabClientBuilder {
|
|||
RuntimeDelegate.setInstance(new ResteasyProviderFactory());
|
||||
}
|
||||
|
||||
private final Class<? extends GitLabApi> apiProxyClass;
|
||||
private final Class<? extends GitLabApiProxy> apiProxyClass;
|
||||
private final Function<MergeRequest, Integer> mergeRequestIdProvider;
|
||||
|
||||
ResteasyGitLabClientBuilder(String id, int ordinal, Class<? extends GitLabApi> apiProxyClass) {
|
||||
ResteasyGitLabClientBuilder(String id, int ordinal, Class<? extends GitLabApiProxy> apiProxyClass, Function<MergeRequest, Integer> mergeRequestIdProvider) {
|
||||
super(id, ordinal);
|
||||
this.apiProxyClass = apiProxyClass;
|
||||
this.mergeRequestIdProvider = mergeRequestIdProvider;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final GitLabClient buildClient(String url, String token, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
return buildClient(url, token, apiProxyClass, ignoreCertificateErrors, connectionTimeout, readTimeout);
|
||||
}
|
||||
|
||||
private GitLabClient buildClient(String url, String apiToken, Class<? extends GitLabApi> proxyClass, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
public final GitLabClient buildClient(String url, String apiToken, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
return buildClient(
|
||||
url,
|
||||
apiToken,
|
||||
proxyClass,
|
||||
Jenkins.getActiveInstance().proxy,
|
||||
ignoreCertificateErrors,
|
||||
connectionTimeout,
|
||||
|
@ -91,7 +88,7 @@ public class ResteasyGitLabClientBuilder extends GitLabClientBuilder {
|
|||
);
|
||||
}
|
||||
|
||||
private GitLabClient buildClient(String url, String apiToken, Class<? extends GitLabApi> proxyClass, ProxyConfiguration httpProxyConfig, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
private GitLabClient buildClient(String url, String apiToken, ProxyConfiguration httpProxyConfig, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
ResteasyClientBuilder builder = new ResteasyClientBuilder();
|
||||
if (ignoreCertificateErrors) {
|
||||
builder.hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY);
|
||||
|
@ -108,7 +105,7 @@ public class ResteasyGitLabClientBuilder extends GitLabClientBuilder {
|
|||
httpProxyConfig.getPassword());
|
||||
}
|
||||
|
||||
GitLabApi apiProxy = builder
|
||||
GitLabApiProxy apiProxy = builder
|
||||
.connectionPoolSize(60)
|
||||
.maxPooledPerRoute(30)
|
||||
.establishConnectionTimeout(connectionTimeout, TimeUnit.SECONDS)
|
||||
|
@ -120,10 +117,10 @@ public class ResteasyGitLabClientBuilder extends GitLabClientBuilder {
|
|||
.register(new RemoveAcceptEncodingFilter())
|
||||
.register(new JaxrsFormProvider())
|
||||
.build().target(url)
|
||||
.proxyBuilder(proxyClass)
|
||||
.classloader(proxyClass.getClassLoader())
|
||||
.proxyBuilder(apiProxyClass)
|
||||
.classloader(apiProxyClass.getClassLoader())
|
||||
.build();
|
||||
return new GitLabClient(url, apiProxy);
|
||||
return new ResteasyGitLabClient(url, apiProxy, mergeRequestIdProvider);
|
||||
}
|
||||
|
||||
private String getHost(String url) {
|
||||
|
@ -231,6 +228,7 @@ public class ResteasyGitLabClientBuilder extends GitLabClientBuilder {
|
|||
private static class ResteasyClientBuilder extends org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder {
|
||||
private CredentialsProvider proxyCredentials;
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
ResteasyClientBuilder defaultProxy(String hostname, int port, final String scheme, String username, String password) {
|
||||
super.defaultProxy(hostname, port, scheme);
|
||||
if (username != null && password != null) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.*;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.State;
|
||||
|
||||
|
@ -26,7 +25,7 @@ import static com.dabsquared.gitlabjenkins.gitlab.api.impl.V3GitLabApiProxy.ID;
|
|||
* @author Robin Müller
|
||||
*/
|
||||
@Path("/api/" + ID)
|
||||
interface V3GitLabApiProxy extends GitLabApi {
|
||||
interface V3GitLabApiProxy extends GitLabApiProxy {
|
||||
String ID = "v3";
|
||||
|
||||
@POST
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import com.google.common.base.Function;
|
||||
import hudson.Extension;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
@ -10,8 +12,14 @@ import org.kohsuke.accmod.restrictions.NoExternalUse;
|
|||
@Restricted(NoExternalUse.class)
|
||||
public final class V3GitLabClientBuilder extends ResteasyGitLabClientBuilder {
|
||||
private static final int ORDINAL = 2;
|
||||
private static final Function<MergeRequest, Integer> MERGE_REQUEST_ID_PROVIDER = new Function<MergeRequest, Integer>() {
|
||||
@Override
|
||||
public Integer apply(MergeRequest mergeRequest) {
|
||||
return mergeRequest.getId();
|
||||
}
|
||||
};
|
||||
|
||||
public V3GitLabClientBuilder() {
|
||||
super(V3GitLabApiProxy.ID, ORDINAL, V3GitLabApiProxy.class);
|
||||
super(V3GitLabApiProxy.ID, ORDINAL, V3GitLabApiProxy.class, MERGE_REQUEST_ID_PROVIDER);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.*;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.State;
|
||||
|
||||
|
@ -26,7 +25,7 @@ import static com.dabsquared.gitlabjenkins.gitlab.api.impl.V4GitLabApiProxy.ID;
|
|||
* @author Robin Müller
|
||||
*/
|
||||
@Path("/api/" + ID)
|
||||
interface V4GitLabApiProxy extends GitLabApi {
|
||||
interface V4GitLabApiProxy extends GitLabApiProxy {
|
||||
String ID = "v4";
|
||||
|
||||
@POST
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import com.google.common.base.Function;
|
||||
import hudson.Extension;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
@ -10,8 +12,14 @@ import org.kohsuke.accmod.restrictions.NoExternalUse;
|
|||
@Restricted(NoExternalUse.class)
|
||||
public final class V4GitLabClientBuilder extends ResteasyGitLabClientBuilder {
|
||||
private static final int ORDINAL = 1;
|
||||
private static final Function<MergeRequest, Integer> MERGE_REQUEST_ID_PROVIDER = new Function<MergeRequest, Integer>() {
|
||||
@Override
|
||||
public Integer apply(MergeRequest mergeRequest) {
|
||||
return mergeRequest.getIid();
|
||||
}
|
||||
};
|
||||
|
||||
public V4GitLabClientBuilder() {
|
||||
super(V4GitLabApiProxy.ID, ORDINAL, V4GitLabApiProxy.class);
|
||||
super(V4GitLabApiProxy.ID, ORDINAL, V4GitLabApiProxy.class, MERGE_REQUEST_ID_PROVIDER);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.List;
|
|||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class MergeRequest {
|
||||
|
||||
private Integer id;
|
||||
private Integer iid;
|
||||
private String sourceBranch;
|
||||
|
@ -33,6 +32,22 @@ public class MergeRequest {
|
|||
private Boolean mergeWhenBuildSucceeds;
|
||||
private String mergeStatus;
|
||||
|
||||
public MergeRequest() { /* default-constructor for Resteasy-based-api-proxies */ }
|
||||
|
||||
public MergeRequest(int id, int iid, String sourceBranch, String targetBranch, String title,
|
||||
int sourceProjectId, int targetProjectId,
|
||||
String description, String mergeStatus) {
|
||||
this.id = id;
|
||||
this.iid= iid;
|
||||
this.sourceBranch = sourceBranch;
|
||||
this.targetBranch = targetBranch;
|
||||
this.title = title;
|
||||
this.sourceProjectId = sourceProjectId;
|
||||
this.projectId = targetProjectId;
|
||||
this.description = description;
|
||||
this.mergeStatus = mergeStatus;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.dabsquared.gitlabjenkins.publisher;
|
|||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import hudson.Extension;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.Result;
|
||||
|
@ -45,14 +46,14 @@ public class GitLabAcceptMergeRequestPublisher extends MergeRequestNotifier {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, Integer projectId, Integer mergeRequestId) {
|
||||
protected void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, MergeRequest mergeRequest) {
|
||||
try {
|
||||
if (build.getResult() == Result.SUCCESS) {
|
||||
client.acceptMergeRequest(projectId, mergeRequestId, "Merge Request accepted by jenkins build success", false);
|
||||
client.acceptMergeRequest(mergeRequest, "Merge Request accepted by jenkins build success", false);
|
||||
}
|
||||
} catch (WebApplicationException | ProcessingException e) {
|
||||
listener.getLogger().printf("Failed to accept merge request for project '%s': %s%n", projectId, e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to accept merge request for project '%s'", projectId), e);
|
||||
listener.getLogger().printf("Failed to accept merge request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to accept merge request for project '%s'", mergeRequest.getProjectId()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.dabsquared.gitlabjenkins.publisher;
|
|||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import hudson.Extension;
|
||||
import hudson.Util;
|
||||
import hudson.model.AbstractProject;
|
||||
|
@ -108,14 +109,14 @@ public class GitLabMessagePublisher extends MergeRequestNotifier {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, Integer projectId, Integer mergeRequestId) {
|
||||
protected void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, MergeRequest mergeRequest) {
|
||||
try {
|
||||
if (!onlyForFailure || build.getResult() == Result.FAILURE || build.getResult() == Result.UNSTABLE) {
|
||||
client.createMergeRequestNote(projectId, mergeRequestId, getNote(build, listener));
|
||||
client.createMergeRequestNote(mergeRequest, getNote(build, listener));
|
||||
}
|
||||
} catch (WebApplicationException | ProcessingException e) {
|
||||
listener.getLogger().printf("Failed to add comment on Merge Request for project '%s': %s%n", projectId, e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", projectId), e);
|
||||
listener.getLogger().printf("Failed to add comment on Merge Request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", mergeRequest.getProjectId()), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.dabsquared.gitlabjenkins.publisher;
|
|||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import hudson.Extension;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.Result;
|
||||
|
@ -45,12 +46,12 @@ public class GitLabVotePublisher extends MergeRequestNotifier {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, Integer projectId, Integer mergeRequestId) {
|
||||
protected void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, MergeRequest mergeRequest) {
|
||||
try {
|
||||
client.createMergeRequestNote(projectId, mergeRequestId, getResultIcon(build.getResult()));
|
||||
client.createMergeRequestNote(mergeRequest, getResultIcon(build.getResult()));
|
||||
} catch (WebApplicationException | ProcessingException e) {
|
||||
listener.getLogger().printf("Failed to add vote on Merge Request for project '%s': %s%n", projectId, e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to add vote on Merge Request for project '%s'", projectId), e);
|
||||
listener.getLogger().printf("Failed to add vote on Merge Request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to add vote on Merge Request for project '%s'", mergeRequest.getProjectId()), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.dabsquared.gitlabjenkins.publisher;
|
|||
|
||||
import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import hudson.Launcher;
|
||||
import hudson.matrix.MatrixAggregatable;
|
||||
import hudson.matrix.MatrixAggregator;
|
||||
|
@ -32,10 +33,10 @@ public abstract class MergeRequestNotifier extends Notifier implements MatrixAgg
|
|||
listener.getLogger().println("No GitLab connection configured");
|
||||
return true;
|
||||
}
|
||||
Integer projectId = getProjectId(build);
|
||||
Integer mergeRequestId = getMergeRequestId(build);
|
||||
if (projectId != null && mergeRequestId != null) {
|
||||
perform(build, listener, client, projectId, mergeRequestId);
|
||||
|
||||
MergeRequest mergeRequest = getMergeRequest(build);
|
||||
if (mergeRequest != null) {
|
||||
perform(build, listener, client, mergeRequest);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -50,15 +51,11 @@ public abstract class MergeRequestNotifier extends Notifier implements MatrixAgg
|
|||
};
|
||||
}
|
||||
|
||||
protected abstract void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, Integer projectId, Integer mergeRequestId);
|
||||
protected abstract void perform(Run<?, ?> build, TaskListener listener, GitLabClient client, MergeRequest mergeRequest);
|
||||
|
||||
Integer getProjectId(Run<?, ?> build) {
|
||||
GitLabWebHookCause cause = build.getCause(GitLabWebHookCause.class);
|
||||
return cause == null ? null : cause.getData().getTargetProjectId();
|
||||
}
|
||||
MergeRequest getMergeRequest(Run<?, ?> run) {
|
||||
GitLabWebHookCause cause = run.getCause(GitLabWebHookCause.class);
|
||||
return cause == null ? null : cause.getData().getMergeRequest();
|
||||
|
||||
Integer getMergeRequestId(Run<?, ?> build) {
|
||||
GitLabWebHookCause cause = build.getCause(GitLabWebHookCause.class);
|
||||
return cause == null ? null : cause.getData().getMergeRequestId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,12 @@ package com.dabsquared.gitlabjenkins.workflow;
|
|||
|
||||
import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.TaskListener;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
|
||||
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
|
||||
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepContext;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;
|
||||
import org.jenkinsci.plugins.workflow.steps.*;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.DataBoundSetter;
|
||||
import org.kohsuke.stapler.export.ExportedBean;
|
||||
|
@ -60,18 +57,17 @@ public class AcceptGitLabMergeRequestStep extends AbstractStepImpl {
|
|||
protected Void run() throws Exception {
|
||||
GitLabWebHookCause cause = run.getCause(GitLabWebHookCause.class);
|
||||
if (cause != null) {
|
||||
Integer projectId = cause.getData().getTargetProjectId();
|
||||
Integer mergeRequestId = cause.getData().getMergeRequestId();
|
||||
if (projectId != null && mergeRequestId != null) {
|
||||
MergeRequest mergeRequest = cause.getData().getMergeRequest();
|
||||
if (mergeRequest != null) {
|
||||
GitLabClient client = getClient(run);
|
||||
if (client == null) {
|
||||
println("No GitLab connection configured");
|
||||
} else {
|
||||
try {
|
||||
client.acceptMergeRequest(projectId, mergeRequestId, step.mergeCommitMessage, false);
|
||||
client.acceptMergeRequest(mergeRequest, step.mergeCommitMessage, false);
|
||||
} catch (WebApplicationException | ProcessingException e) {
|
||||
printf("Failed to accept merge request for project '%s': %s%n", projectId, e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to accept merge request for project '%s'", projectId), e);
|
||||
printf("Failed to accept merge request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to accept merge request for project '%s'", mergeRequest.getProjectId()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.dabsquared.gitlabjenkins.workflow;
|
|||
|
||||
import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.TaskListener;
|
||||
|
@ -60,18 +61,17 @@ public class AddGitLabMergeRequestCommentStep extends AbstractStepImpl {
|
|||
protected Void run() throws Exception {
|
||||
GitLabWebHookCause cause = run.getCause(GitLabWebHookCause.class);
|
||||
if (cause != null) {
|
||||
Integer projectId = cause.getData().getTargetProjectId();
|
||||
Integer mergeRequestId = cause.getData().getMergeRequestId();
|
||||
if (projectId != null && mergeRequestId != null) {
|
||||
MergeRequest mergeRequest = cause.getData().getMergeRequest();
|
||||
if (mergeRequest != null) {
|
||||
GitLabClient client = getClient(run);
|
||||
if (client == null) {
|
||||
println("No GitLab connection configured");
|
||||
} else {
|
||||
try {
|
||||
client.createMergeRequestNote(projectId, mergeRequestId, step.getComment());
|
||||
client.createMergeRequestNote(mergeRequest, step.getComment());
|
||||
} catch (WebApplicationException | ProcessingException e) {
|
||||
printf("Failed to add comment on Merge Request for project '%s': %s%n", projectId, e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", projectId), e);
|
||||
printf("Failed to add comment on Merge Request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage());
|
||||
LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", mergeRequest.getProjectId()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClientBuilder;
|
||||
import com.trilead.ssh2.util.TimeoutService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockserver.client.server.MockServerClient;
|
||||
import org.mockserver.junit.MockServerRule;
|
||||
import org.mockserver.matchers.Times;
|
||||
import org.mockserver.model.HttpRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -21,7 +19,7 @@ import static org.junit.Assert.fail;
|
|||
import static org.mockserver.matchers.Times.exactly;
|
||||
import static org.mockserver.matchers.Times.once;
|
||||
|
||||
public class AutodetectingGitLabApiTest {
|
||||
public class AutodetectingGitLabClientTest {
|
||||
@Rule
|
||||
public MockServerRule mockServer = new MockServerRule(this);
|
||||
@Rule
|
||||
|
@ -29,7 +27,7 @@ public class AutodetectingGitLabApiTest {
|
|||
private MockServerClient mockServerClient;
|
||||
private String gitLabUrl;
|
||||
private GitLabClientBuilder clientBuilder;
|
||||
private AutodetectingGitlabApi api;
|
||||
private AutodetectingGitLabClient api;
|
||||
private HttpRequest v3Request;
|
||||
private HttpRequest v4Request;
|
||||
|
||||
|
@ -39,7 +37,7 @@ public class AutodetectingGitLabApiTest {
|
|||
addGitLabApiToken();
|
||||
|
||||
List<GitLabClientBuilder> builders = Arrays.<GitLabClientBuilder>asList(new V3GitLabClientBuilder(), new V4GitLabClientBuilder());
|
||||
api = new AutodetectingGitlabApi(builders, gitLabUrl, API_TOKEN, true, 10, 10);
|
||||
api = new AutodetectingGitLabClient(builders, gitLabUrl, API_TOKEN, true, 10, 10);
|
||||
|
||||
v3Request = versionRequest(V3GitLabApiProxy.ID);
|
||||
v4Request = versionRequest(V4GitLabApiProxy.ID);
|
|
@ -21,14 +21,14 @@ public class ResteasyGitLabClientBuilderTest {
|
|||
|
||||
@Test
|
||||
public void buildClient() throws Exception {
|
||||
GitLabClientBuilder clientBuilder = new ResteasyGitLabClientBuilder("test", 0, V3GitLabApiProxy.class);
|
||||
GitLabClientBuilder clientBuilder = new ResteasyGitLabClientBuilder("test", 0, V3GitLabApiProxy.class, null);
|
||||
assertApiImpl(buildClientWithDefaults(clientBuilder, "http://localhost/"), V3GitLabApiProxy.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildClientWithProxy() throws Exception {
|
||||
jenkins.getInstance().proxy = new ProxyConfiguration("example.com", 8080, "test", "test", "*localhost*");
|
||||
GitLabClientBuilder clientBuilder = new ResteasyGitLabClientBuilder("test", 0, V3GitLabApiProxy.class);
|
||||
GitLabClientBuilder clientBuilder = new ResteasyGitLabClientBuilder("test", 0, V3GitLabApiProxy.class, null);
|
||||
assertNotNull(buildClientWithDefaults(clientBuilder, "http://localhost"));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.cloudbees.plugins.credentials.CredentialsScope;
|
|||
import com.cloudbees.plugins.credentials.CredentialsStore;
|
||||
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
|
||||
import com.cloudbees.plugins.credentials.domains.Domain;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClientBuilder;
|
||||
import hudson.util.Secret;
|
||||
|
@ -23,7 +22,6 @@ import java.util.List;
|
|||
import static javax.ws.rs.HttpMethod.HEAD;
|
||||
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
|
||||
import static javax.ws.rs.core.Response.Status.OK;
|
||||
import static javax.ws.rs.core.Response.Status.UNAUTHORIZED;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
|
@ -67,13 +65,13 @@ class TestUtility {
|
|||
return clientBuilder.buildClient(url, API_TOKEN, IGNORE_CERTIFICATE_ERRORS, CONNECTION_TIMEOUT, READ_TIMEOUT);
|
||||
}
|
||||
|
||||
static void assertApiImpl(GitLabClient client, Class<? extends GitLabApi> apiImplClass) throws Exception {
|
||||
Field apiField = client.getClass().getDeclaredField("api");
|
||||
static void assertApiImpl(GitLabClient client, Class<? extends GitLabApiProxy> apiImplClass) throws Exception {
|
||||
Field apiField = ((ResteasyGitLabClient) client).getClass().getDeclaredField("api");
|
||||
apiField.setAccessible(true);
|
||||
assertThat(apiField.get(client), instanceOf(apiImplClass));
|
||||
}
|
||||
|
||||
static void assertApiImpl(AutodetectingGitlabApi api, Class<? extends GitLabApi> apiImplClass) throws Exception {
|
||||
static void assertApiImpl(AutodetectingGitLabClient api, Class<? extends GitLabApiProxy> apiImplClass) throws Exception {
|
||||
Field delegate = api.getClass().getDeclaredField("delegate");
|
||||
delegate.setAccessible(true);
|
||||
assertApiImpl((GitLabClient) delegate.get(api), apiImplClass);
|
||||
|
|
|
@ -19,15 +19,7 @@ import java.io.IOException;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.GITLAB_CONNECTION_V3;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.GITLAB_CONNECTION_V4;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.MERGE_REQUEST_ID;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.PROJECT_ID;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.mockSimpleBuild;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.setupGitLabConnections;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.verifyMatrixAggregatable;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.*;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
import static org.mockserver.model.HttpResponse.response;
|
||||
|
||||
|
@ -71,8 +63,8 @@ public class GitLabAcceptMergeRequestPublisherTest {
|
|||
publish(mockSimpleBuild(GITLAB_CONNECTION_V4, Result.SUCCESS));
|
||||
|
||||
mockServerClient.verify(
|
||||
prepareAcceptMergeRequestWithSuccessResponse("v3"),
|
||||
prepareAcceptMergeRequestWithSuccessResponse("v4"));
|
||||
prepareAcceptMergeRequestWithSuccessResponse("v3", MERGE_REQUEST_ID),
|
||||
prepareAcceptMergeRequestWithSuccessResponse("v4", MERGE_REQUEST_IID));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -84,21 +76,19 @@ public class GitLabAcceptMergeRequestPublisherTest {
|
|||
}
|
||||
|
||||
private void publish(AbstractBuild build) throws InterruptedException, IOException {
|
||||
GitLabAcceptMergeRequestPublisher publisher = spy(new GitLabAcceptMergeRequestPublisher());
|
||||
doReturn(PROJECT_ID).when(publisher).getProjectId(build);
|
||||
doReturn(MERGE_REQUEST_ID).when(publisher).getMergeRequestId(build);
|
||||
GitLabAcceptMergeRequestPublisher publisher = preparePublisher(new GitLabAcceptMergeRequestPublisher(), build);
|
||||
publisher.perform(build, null, listener);
|
||||
}
|
||||
|
||||
private HttpRequest prepareAcceptMergeRequestWithSuccessResponse(String apiLevel) throws UnsupportedEncodingException {
|
||||
HttpRequest updateCommitStatus = prepareAcceptMergeRequest(apiLevel);
|
||||
private HttpRequest prepareAcceptMergeRequestWithSuccessResponse(String apiLevel, int mergeRequestId) throws UnsupportedEncodingException {
|
||||
HttpRequest updateCommitStatus = prepareAcceptMergeRequest(apiLevel, mergeRequestId);
|
||||
mockServerClient.when(updateCommitStatus).respond(response().withStatusCode(200));
|
||||
return updateCommitStatus;
|
||||
}
|
||||
|
||||
private HttpRequest prepareAcceptMergeRequest(String apiLevel) throws UnsupportedEncodingException {
|
||||
private HttpRequest prepareAcceptMergeRequest(String apiLevel, int mergeRequestId) throws UnsupportedEncodingException {
|
||||
return request()
|
||||
.withPath("/gitlab/api/" + apiLevel + "/projects/" + PROJECT_ID + "/merge_requests/" + MERGE_REQUEST_ID + "/merge")
|
||||
.withPath("/gitlab/api/" + apiLevel + "/projects/" + PROJECT_ID + "/merge_requests/" + mergeRequestId + "/merge")
|
||||
.withMethod("PUT")
|
||||
.withHeader("PRIVATE-TOKEN", "secret")
|
||||
.withBody("merge_commit_message=Merge+Request+accepted+by+jenkins+build+success&should_remove_source_branch=false");
|
||||
|
|
|
@ -29,20 +29,10 @@ import java.nio.charset.Charset;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.BUILD_NUMBER;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.BUILD_URL;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.GITLAB_CONNECTION_V3;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.GITLAB_CONNECTION_V4;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.MERGE_REQUEST_ID;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.PROJECT_ID;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.formatNote;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.setupGitLabConnections;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.verifyMatrixAggregatable;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
import static org.mockserver.model.HttpResponse.response;
|
||||
|
@ -88,7 +78,7 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v3", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v3", MERGE_REQUEST_ID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -98,7 +88,7 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,18 +99,18 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v3", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v3", MERGE_REQUEST_ID, defaultNote));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void success() throws IOException, InterruptedException {
|
||||
public void success_v4() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITLAB_CONNECTION_V4, Result.SUCCESS);
|
||||
String defaultNote = formatNote(build, ":white_check_mark: Jenkins Build {0}\n\nResults available at: [Jenkins [{1} #{2}]]({3})");
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -137,7 +127,7 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v3", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v3", MERGE_REQUEST_ID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -147,7 +137,7 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
|
||||
|
@ -158,7 +148,7 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, true, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -168,7 +158,7 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, true, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -178,7 +168,7 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, true, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -188,7 +178,7 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, true, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -198,7 +188,7 @@ public class GitLabMessagePublisherTest {
|
|||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, true,
|
||||
prepareSendMessageWithSuccessResponse("v4", defaultNote));
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
private void performAndVerify(AbstractBuild build, String note, boolean onlyForFailure, boolean replaceSuccessNote, boolean replaceFailureNote, boolean replaceAbortNote, boolean replaceUnstableNote, HttpRequest... requests) throws InterruptedException, IOException {
|
||||
|
@ -206,9 +196,7 @@ public class GitLabMessagePublisherTest {
|
|||
String failureNoteText = replaceFailureNote ? note : null;
|
||||
String abortNoteText = replaceAbortNote ? note : null;
|
||||
String unstableNoteText = replaceUnstableNote ? note : null;
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(onlyForFailure, replaceSuccessNote, replaceFailureNote, replaceAbortNote, replaceUnstableNote, successNoteText, failureNoteText, abortNoteText, unstableNoteText));
|
||||
doReturn(PROJECT_ID).when(publisher).getProjectId(build);
|
||||
doReturn(MERGE_REQUEST_ID).when(publisher).getMergeRequestId(build);
|
||||
GitLabMessagePublisher publisher = preparePublisher(new GitLabMessagePublisher(onlyForFailure, replaceSuccessNote, replaceFailureNote, replaceAbortNote, replaceUnstableNote, successNoteText, failureNoteText, abortNoteText, unstableNoteText), build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
||||
if (requests.length > 0) {
|
||||
|
@ -218,15 +206,15 @@ public class GitLabMessagePublisherTest {
|
|||
}
|
||||
}
|
||||
|
||||
private HttpRequest prepareSendMessageWithSuccessResponse(String apiLevel, String body) throws UnsupportedEncodingException {
|
||||
HttpRequest updateCommitStatus = prepareSendMessageStatus(apiLevel, body);
|
||||
private HttpRequest prepareSendMessageWithSuccessResponse(String apiLevel, int mergeRequestId, String body) throws UnsupportedEncodingException {
|
||||
HttpRequest updateCommitStatus = prepareSendMessageStatus(apiLevel, mergeRequestId, body);
|
||||
mockServerClient.when(updateCommitStatus).respond(response().withStatusCode(200));
|
||||
return updateCommitStatus;
|
||||
}
|
||||
|
||||
private HttpRequest prepareSendMessageStatus(final String apiLevel, String body) throws UnsupportedEncodingException {
|
||||
private HttpRequest prepareSendMessageStatus(final String apiLevel, int mergeRequestId, String body) throws UnsupportedEncodingException {
|
||||
return request()
|
||||
.withPath("/gitlab/api/" + apiLevel + "/projects/" + PROJECT_ID + "/merge_requests/" + MERGE_REQUEST_ID + "/notes")
|
||||
.withPath("/gitlab/api/" + apiLevel + "/projects/" + PROJECT_ID + "/merge_requests/" + mergeRequestId + "/notes")
|
||||
.withMethod("POST")
|
||||
.withHeader("PRIVATE-TOKEN", "secret")
|
||||
.withBody("body=" + URLEncoder.encode(body, "UTF-8"));
|
||||
|
|
|
@ -20,15 +20,7 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.GITLAB_CONNECTION_V3;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.GITLAB_CONNECTION_V4;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.MERGE_REQUEST_ID;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.PROJECT_ID;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.formatNote;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.setupGitLabConnections;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.verifyMatrixAggregatable;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static com.dabsquared.gitlabjenkins.publisher.TestUtility.*;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
import static org.mockserver.model.HttpResponse.response;
|
||||
|
||||
|
@ -68,43 +60,41 @@ public class GitLabVotePublisherTest {
|
|||
|
||||
@Test
|
||||
public void success_v3() throws IOException, InterruptedException {
|
||||
performAndVerify(TestUtility.mockSimpleBuild(GITLAB_CONNECTION_V3, Result.SUCCESS), "v3", ":+1:");
|
||||
performAndVerify(mockSimpleBuild(GITLAB_CONNECTION_V3, Result.SUCCESS), "v3", MERGE_REQUEST_ID, ":+1:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void success_v4() throws IOException, InterruptedException {
|
||||
performAndVerify(TestUtility.mockSimpleBuild(GITLAB_CONNECTION_V4, Result.SUCCESS), "v4", ":+1:");
|
||||
performAndVerify(mockSimpleBuild(GITLAB_CONNECTION_V4, Result.SUCCESS), "v4", MERGE_REQUEST_IID, ":+1:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failed_v3() throws IOException, InterruptedException {
|
||||
performAndVerify(TestUtility.mockSimpleBuild(GITLAB_CONNECTION_V3, Result.FAILURE), "v3", ":-1:");
|
||||
performAndVerify(mockSimpleBuild(GITLAB_CONNECTION_V3, Result.FAILURE), "v3", MERGE_REQUEST_ID, ":-1:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failed_v4() throws IOException, InterruptedException {
|
||||
performAndVerify(TestUtility.mockSimpleBuild(GITLAB_CONNECTION_V4, Result.FAILURE), "v4", ":-1:");
|
||||
performAndVerify(mockSimpleBuild(GITLAB_CONNECTION_V4, Result.FAILURE), "v4", MERGE_REQUEST_IID, ":-1:");
|
||||
}
|
||||
|
||||
|
||||
private void performAndVerify(AbstractBuild build, String apiLevel, String defaultNote) throws InterruptedException, IOException {
|
||||
GitLabVotePublisher publisher = spy(new GitLabVotePublisher());
|
||||
doReturn(PROJECT_ID).when(publisher).getProjectId(build);
|
||||
doReturn(MERGE_REQUEST_ID).when(publisher).getMergeRequestId(build);
|
||||
private void performAndVerify(AbstractBuild build, String apiLevel, int mergeRequestId, String defaultNote) throws InterruptedException, IOException {
|
||||
GitLabVotePublisher publisher = preparePublisher(new GitLabVotePublisher(), build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
||||
mockServerClient.verify(prepareSendMessageWithSuccessResponse(build, apiLevel, defaultNote));
|
||||
mockServerClient.verify(prepareSendMessageWithSuccessResponse(build, apiLevel, mergeRequestId, defaultNote));
|
||||
}
|
||||
|
||||
private HttpRequest prepareSendMessageWithSuccessResponse(AbstractBuild build, String apiLevel, String body) throws UnsupportedEncodingException {
|
||||
HttpRequest updateCommitStatus = prepareSendMessageStatus(apiLevel, formatNote(build, body));
|
||||
private HttpRequest prepareSendMessageWithSuccessResponse(AbstractBuild build, String apiLevel, int mergeRequestId, String body) throws UnsupportedEncodingException {
|
||||
HttpRequest updateCommitStatus = prepareSendMessageStatus(apiLevel, mergeRequestId, formatNote(build, body));
|
||||
mockServerClient.when(updateCommitStatus).respond(response().withStatusCode(200));
|
||||
return updateCommitStatus;
|
||||
}
|
||||
|
||||
private HttpRequest prepareSendMessageStatus(final String apiLevel, String body) throws UnsupportedEncodingException {
|
||||
private HttpRequest prepareSendMessageStatus(final String apiLevel, int mergeRequestId, String body) throws UnsupportedEncodingException {
|
||||
return request()
|
||||
.withPath("/gitlab/api/" + apiLevel + "/projects/" + PROJECT_ID + "/merge_requests/" + MERGE_REQUEST_ID + "/notes")
|
||||
.withPath("/gitlab/api/" + apiLevel + "/projects/" + PROJECT_ID + "/merge_requests/" + mergeRequestId + "/notes")
|
||||
.withMethod("POST")
|
||||
.withHeader("PRIVATE-TOKEN", "secret")
|
||||
.withBody("body=" + URLEncoder.encode(body, "UTF-8"));
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.dabsquared.gitlabjenkins.connection.GitLabConnectionConfig;
|
|||
import com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.impl.V3GitLabClientBuilder;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.impl.V4GitLabClientBuilder;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
|
||||
import hudson.Launcher;
|
||||
import hudson.matrix.MatrixAggregatable;
|
||||
import hudson.matrix.MatrixAggregator;
|
||||
|
@ -35,9 +36,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
|
||||
final class TestUtility {
|
||||
|
@ -47,6 +46,7 @@ final class TestUtility {
|
|||
static final int BUILD_NUMBER = 1;
|
||||
static final int PROJECT_ID = 3;
|
||||
static final int MERGE_REQUEST_ID = 1;
|
||||
static final int MERGE_REQUEST_IID = 2;
|
||||
|
||||
private static final String API_TOKEN = "secret";
|
||||
|
||||
|
@ -103,5 +103,12 @@ final class TestUtility {
|
|||
return MessageFormat.format(note, build.getResult(), build.getParent().getDisplayName(), BUILD_NUMBER, buildUrl);
|
||||
}
|
||||
|
||||
static <P extends MergeRequestNotifier> P preparePublisher(P publisher, AbstractBuild build) {
|
||||
P spyPublisher = spy(publisher);
|
||||
MergeRequest mergeRequest = new MergeRequest(MERGE_REQUEST_ID, MERGE_REQUEST_IID, "", "", "", PROJECT_ID, PROJECT_ID, "", "");
|
||||
doReturn(mergeRequest).when(spyPublisher).getMergeRequest(build);
|
||||
return spyPublisher;
|
||||
}
|
||||
|
||||
private TestUtility() { /* contains only static utility-methods */ }
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.dabsquared.gitlabjenkins.service;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.*;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.State;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
@ -14,15 +14,20 @@ import java.util.Map;
|
|||
import static java.util.Collections.emptyList;
|
||||
|
||||
|
||||
class GitLabApiStub implements GitLabApi {
|
||||
class GitLabClientStub implements GitLabClient {
|
||||
private final Map<Pair<String, Class>, List<?>> data;
|
||||
private final Map<Pair<String, Class>, Integer> calls;
|
||||
|
||||
GitLabApiStub() {
|
||||
GitLabClientStub() {
|
||||
data = new HashMap<>();
|
||||
calls = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostUrl() {
|
||||
return "";
|
||||
}
|
||||
|
||||
void addBranches(String project, List<Branch> branches) {
|
||||
addData(project, Branch.class, branches);
|
||||
}
|
||||
|
@ -115,12 +120,12 @@ class GitLabApiStub implements GitLabApi {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void acceptMergeRequest(Integer projectId, Integer mergeRequestId, String mergeCommitMessage, boolean shouldRemoveSourceBranch) {
|
||||
public void acceptMergeRequest(MergeRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMergeRequestNote(Integer projectId, Integer mergeRequestId, String body) {
|
||||
public void createMergeRequestNote(MergeRequest mr, String body) {
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package com.dabsquared.gitlabjenkins.service;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Branch;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -22,16 +21,14 @@ public class GitLabProjectBranchesServiceTest {
|
|||
|
||||
private GitLabProjectBranchesService branchesService;
|
||||
|
||||
private GitLabApiStub apiStub;
|
||||
private GitLabClient gitlabClient;
|
||||
private GitLabClientStub clientStub;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
apiStub = new GitLabApiStub();
|
||||
apiStub.addBranches("groupOne/A", convert(asList("master", "A-branch-1")));
|
||||
apiStub.addBranches("groupOne/B", convert(BRANCH_NAMES_PROJECT_B));
|
||||
clientStub = new GitLabClientStub();
|
||||
clientStub.addBranches("groupOne/A", convert(asList("master", "A-branch-1")));
|
||||
clientStub.addBranches("groupOne/B", convert(BRANCH_NAMES_PROJECT_B));
|
||||
|
||||
gitlabClient = new GitLabClient("", apiStub);
|
||||
|
||||
// never expire cache for tests
|
||||
branchesService = new GitLabProjectBranchesService();
|
||||
|
@ -40,7 +37,7 @@ public class GitLabProjectBranchesServiceTest {
|
|||
@Test
|
||||
public void shouldReturnBranchNamesFromGitlabApi() {
|
||||
// when
|
||||
List<String> actualBranchNames = branchesService.getBranches(gitlabClient, "git@git.example.com:groupOne/B.git");
|
||||
List<String> actualBranchNames = branchesService.getBranches(clientStub, "git@git.example.com:groupOne/B.git");
|
||||
|
||||
// then
|
||||
assertThat(actualBranchNames, is(BRANCH_NAMES_PROJECT_B));
|
||||
|
@ -49,11 +46,11 @@ public class GitLabProjectBranchesServiceTest {
|
|||
@Test
|
||||
public void shouldNotMakeUnnecessaryCallsToGitlabApiGetBranches() {
|
||||
// when
|
||||
branchesService.getBranches(gitlabClient, "git@git.example.com:groupOne/A.git");
|
||||
branchesService.getBranches(clientStub, "git@git.example.com:groupOne/A.git");
|
||||
|
||||
// then
|
||||
assertEquals(1, apiStub.calls("groupOne/A", Branch.class));
|
||||
assertEquals(0, apiStub.calls("groupOne/B", Branch.class));
|
||||
assertEquals(1, clientStub.calls("groupOne/A", Branch.class));
|
||||
assertEquals(0, clientStub.calls("groupOne/B", Branch.class));
|
||||
}
|
||||
|
||||
private List<Branch> convert(List<String> branchNames) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.dabsquared.gitlabjenkins.service;
|
||||
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.Label;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -23,17 +22,14 @@ public class GitLabProjectLabelsServiceTest {
|
|||
|
||||
private GitLabProjectLabelsService labelsService;
|
||||
|
||||
private GitLabApiStub apiStub;
|
||||
private GitLabClient gitlabClient;
|
||||
private GitLabClientStub clientStub;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
apiStub = new GitLabApiStub();
|
||||
apiStub.addLabels("groupOne/A", convert(asList("label1", "label2")));
|
||||
apiStub.addLabels("groupOne/B", convert(LABELS_PROJECT_B));
|
||||
clientStub = new GitLabClientStub();
|
||||
clientStub.addLabels("groupOne/A", convert(asList("label1", "label2")));
|
||||
clientStub.addLabels("groupOne/B", convert(LABELS_PROJECT_B));
|
||||
|
||||
gitlabClient = new GitLabClient("", apiStub);
|
||||
|
||||
// never expire cache for tests
|
||||
labelsService = new GitLabProjectLabelsService();
|
||||
}
|
||||
|
@ -41,7 +37,7 @@ public class GitLabProjectLabelsServiceTest {
|
|||
@Test
|
||||
public void shouldReturnLabelsFromGitlabApi() {
|
||||
// when
|
||||
List<String> actualLabels = labelsService.getLabels(gitlabClient, "git@git.example.com:groupOne/B.git");
|
||||
List<String> actualLabels = labelsService.getLabels(clientStub, "git@git.example.com:groupOne/B.git");
|
||||
|
||||
// then
|
||||
assertThat(actualLabels, is(LABELS_PROJECT_B));
|
||||
|
@ -50,11 +46,11 @@ public class GitLabProjectLabelsServiceTest {
|
|||
@Test
|
||||
public void shouldNotMakeUnnecessaryCallsToGitlabApiGetLabels() {
|
||||
// when
|
||||
labelsService.getLabels(gitlabClient, "git@git.example.com:groupOne/A.git");
|
||||
labelsService.getLabels(clientStub, "git@git.example.com:groupOne/A.git");
|
||||
|
||||
// then
|
||||
assertEquals(1, apiStub.calls("groupOne/A", Label.class));
|
||||
assertEquals(0, apiStub.calls("groupOne/B", Label.class));
|
||||
assertEquals(1, clientStub.calls("groupOne/A", Label.class));
|
||||
assertEquals(0, clientStub.calls("groupOne/B", Label.class));
|
||||
}
|
||||
|
||||
private List<Label> convert(List<String> labels) {
|
||||
|
|
|
@ -38,23 +38,18 @@ import java.util.UUID;
|
|||
*/
|
||||
public class GitLabRule implements TestRule {
|
||||
private static final String API_TOKEN_ID = "apiTokenId";
|
||||
private static final String PASSWORD = "integration-test";
|
||||
|
||||
private final String url;
|
||||
private final int postgresPort;
|
||||
private final GitLabClient client;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
private GitLabClient clientCache;
|
||||
|
||||
private List<String> projectIds = new ArrayList<>();
|
||||
|
||||
public GitLabRule(String url, int postgresPort) {
|
||||
this.url = url;
|
||||
this.postgresPort = postgresPort;
|
||||
client = new V3GitLabClientBuilder().buildClient(url, getApiToken(), false, -1, -1);
|
||||
User user = client.getCurrentUser();
|
||||
username = user.getUsername();
|
||||
password = "integration-test";
|
||||
client.updateUser(user.getId().toString(), user.getEmail(), user.getUsername(), user.getName(), password);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,11 +58,11 @@ public class GitLabRule implements TestRule {
|
|||
}
|
||||
|
||||
public Project getProject(final String projectName) {
|
||||
return client.getProject(projectName);
|
||||
return client().getProject(projectName);
|
||||
}
|
||||
|
||||
public List<Pipeline> getPipelines(int projectId) {
|
||||
return client.getPipelines(String.valueOf(projectId));
|
||||
return client().getPipelines(String.valueOf(projectId));
|
||||
}
|
||||
|
||||
public List<String> getProjectIds() {
|
||||
|
@ -75,10 +70,10 @@ public class GitLabRule implements TestRule {
|
|||
}
|
||||
|
||||
public String createProject(ProjectRequest request) {
|
||||
Project project = client.createProject(request.getName());
|
||||
Project project = client().createProject(request.getName());
|
||||
projectIds.add(project.getId().toString());
|
||||
if (request.getWebHookUrl() != null && (request.isPushHook() || request.isMergeRequestHook() || request.isNoteHook())) {
|
||||
client.addProjectHook(project.getId().toString(), request.getWebHookUrl(), request.isPushHook(), request.isMergeRequestHook(), request.isNoteHook());
|
||||
client().addProjectHook(project.getId().toString(), request.getWebHookUrl(), request.isPushHook(), request.isMergeRequestHook(), request.isNoteHook());
|
||||
}
|
||||
return project.getHttpUrlToRepo();
|
||||
}
|
||||
|
@ -103,27 +98,27 @@ public class GitLabRule implements TestRule {
|
|||
final String sourceBranch,
|
||||
final String targetBranch,
|
||||
final String title) {
|
||||
return client.createMergeRequest(projectId, sourceBranch, targetBranch, title);
|
||||
return client().createMergeRequest(projectId, sourceBranch, targetBranch, title);
|
||||
}
|
||||
|
||||
public void createMergeRequestNote(Integer projectId, Integer mergeRequestId, String body) {
|
||||
client.createMergeRequestNote(projectId, mergeRequestId, body);
|
||||
public void createMergeRequestNote(MergeRequest mr, String body) {
|
||||
client().createMergeRequestNote(mr, body);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
return client().getCurrentUser().getUsername();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
return PASSWORD;
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
for (String projectId : projectIds) {
|
||||
String randomProjectName = UUID.randomUUID().toString();
|
||||
// rename the project before deleting as the deletion will take a while
|
||||
client.updateProject(projectId, randomProjectName, randomProjectName);
|
||||
client.deleteProject(projectId);
|
||||
client().updateProject(projectId, randomProjectName, randomProjectName);
|
||||
client().deleteProject(projectId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,6 +135,15 @@ public class GitLabRule implements TestRule {
|
|||
}
|
||||
}
|
||||
|
||||
private GitLabClient client() {
|
||||
if (clientCache == null) {
|
||||
clientCache = new V3GitLabClientBuilder().buildClient(url, getApiToken(), false, -1, -1);
|
||||
User user = clientCache.getCurrentUser();
|
||||
client().updateUser(user.getId().toString(), user.getEmail(), user.getUsername(), user.getName(), PASSWORD);
|
||||
}
|
||||
return clientCache;
|
||||
}
|
||||
|
||||
private class GitlabStatement extends Statement {
|
||||
private final Statement next;
|
||||
|
||||
|
@ -156,16 +160,4 @@ public class GitLabRule implements TestRule {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ApiHeaderTokenFilter implements ClientRequestFilter {
|
||||
private final String gitlabApiToken;
|
||||
|
||||
ApiHeaderTokenFilter(String gitlabApiToken) {
|
||||
this.gitlabApiToken = gitlabApiToken;
|
||||
}
|
||||
|
||||
public void filter(ClientRequestContext requestContext) throws IOException {
|
||||
requestContext.getHeaders().putSingle("PRIVATE-TOKEN", gitlabApiToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import java.util.List;
|
|||
|
||||
import static com.dabsquared.gitlabjenkins.builder.generated.GitLabPushTriggerBuilder.gitLabPushTrigger;
|
||||
import static com.dabsquared.gitlabjenkins.testing.gitlab.rule.builder.generated.ProjectRequestBuilder.projectRequest;
|
||||
import static java.lang.Integer.parseInt;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
||||
import static org.hamcrest.collection.IsEmptyCollection.empty;
|
||||
|
@ -55,8 +56,7 @@ public class GitLabIT {
|
|||
private static final String GITLAB_URL = "http://localhost:" + System.getProperty("gitlab.http.port", "10080");
|
||||
|
||||
@Rule
|
||||
public GitLabRule gitlab = new GitLabRule(GITLAB_URL,
|
||||
Integer.parseInt(System.getProperty("postgres.port", "5432")));
|
||||
public GitLabRule gitlab = new GitLabRule(GITLAB_URL, parseInt(System.getProperty("postgres.port", "5432")));
|
||||
|
||||
@Rule
|
||||
public JenkinsRule jenkins = new JenkinsRule();
|
||||
|
@ -137,7 +137,7 @@ public class GitLabIT {
|
|||
project.addTrigger(trigger);
|
||||
trigger.start(project, true);
|
||||
|
||||
gitlab.createMergeRequestNote(gitlabData.getLeft(), mr.getId(), "this is a test note");
|
||||
gitlab.createMergeRequestNote(mr, "this is a test note");
|
||||
|
||||
buildTriggered.block(20000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
|
@ -224,7 +224,7 @@ public class GitLabIT {
|
|||
// Once the issue is resolved, replace this implementation.
|
||||
List<String> projectIds = gitlab.getProjectIds();
|
||||
assertSame(projectIds.size(), 1);
|
||||
return new ImmutablePair<>(Integer.parseInt(projectIds.get(0)), sha);
|
||||
return new ImmutablePair<>(parseInt(projectIds.get(0)), sha);
|
||||
}
|
||||
|
||||
private String initGitLabProject(String url, boolean addFeatureBranch) throws GitAPIException, IOException {
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
package com.dabsquared.gitlabjenkins.util;
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.*;
|
||||
import com.dabsquared.gitlabjenkins.gitlab.hook.model.State;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class GitLabClientStub implements GitLabClient {
|
||||
private final String url;
|
||||
|
||||
GitLabClientStub(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project createProject(String projectName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject(String projectName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project updateProject(String projectId, String name, String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProject(String projectId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProjectHook(String projectId, String url, Boolean pushEvents, Boolean mergeRequestEvents, Boolean noteEvents) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(String projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(Integer projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getCommit(String projectId, String sha) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptMergeRequest(MergeRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMergeRequestNote(MergeRequest mr, String body) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MergeRequest> getMergeRequests(String projectId, State state, int page, int perPage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Branch> getBranches(String projectId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Branch getBranch(String projectId, String branch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headCurrentUser() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User addUser(String email, String username, String name, String password) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User updateUser(String userId, String email, String username, String name, String password) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Label> getLabels(String projectId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pipeline> getPipelines(String projectName) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ public class ProjectIdUtilTest {
|
|||
|
||||
@Theory
|
||||
public void retrieveProjectId(TestData testData) throws ProjectIdUtil.ProjectIdResolutionException {
|
||||
GitLabClient client = new GitLabClient(testData.hostUrl, null);
|
||||
GitLabClient client = new GitLabClientStub(testData.hostUrl);
|
||||
|
||||
String projectId = ProjectIdUtil.retrieveProjectId(client, testData.remoteUrl);
|
||||
|
||||
|
|
|
@ -4,4 +4,4 @@ if [[ -d $DOCKER_CACHE_DIR ]]; then
|
|||
ls $DOCKER_CACHE_DIR/*.tar.gz | xargs -I {file} sh -c "zcat {file} | docker load";
|
||||
fi
|
||||
|
||||
./mvnw integration-test -P integration-test -Dgitlab.version=$GITLAB_VERSION -Dfindbugs.skip=true -Dmaven.javadoc.skip=true
|
||||
./mvnw integration-test -B -Pintegration-test -Dgitlab.version=$GITLAB_VERSION -Dfindbugs.skip=true -Dmaven.javadoc.skip=true
|
||||
|
|
Loading…
Reference in New Issue