Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Commit

Permalink
WIP: Bump gitlab plugin (#53)
Browse files Browse the repository at this point in the history
* pom.xml: Bump version of gitlab-plugin

gitlab-plugin used in jenkins has been bumped upstream and this project should be compiled with it

Signed-off-by: Oscar Andreasson <oscar.andreasson@pelagicore.com>

* pom.xml: workflow-step-api required for normal build

Without workflow-step-api build breaks during a normal compilation.

Signed-off-by: Oscar Andreasson <oscar.andreasson@pelagicore.com>

* GitLabConnectionProperty.getClient returns GitLabClient

The GitLabConnectionProperty.getClient method now returns a GitLabClient
instead of a GitLabApi meaning that several of the usages of the class needs to
be rewritten slightly.

Signed-off-by: Oscar Andreasson <oscar.andreasson@pelagicore.com>
  • Loading branch information
frznlogic authored and Argelbargel committed Feb 27, 2018
1 parent 79d9e27 commit a5357e2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>gitlab-plugin</artifactId>
<version>1.4.5</version>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -118,7 +118,6 @@
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>2.4</version>
<scope>test</scope>
</dependency>

<!-- by default 1.4 is installed which causes an StackOverflowError -->
Expand Down Expand Up @@ -269,4 +268,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private List<Action> retrieve(@Nonnull GitLabSCMHead head, @CheckForNull SCMHead
linkAction = GitLabLinkAction.toMergeRequest(mr.getWebUrl());
if (acceptMergeRequest(head)) {
boolean removeSourceBranch = mr.getRemoveSourceBranch() || removeSourceBranch(head);
actions.add(new GitLabSCMAcceptMergeRequestAction(mr.getProjectId(), mr.getId(), mr.getIid(), source.getSourceSettings().getMergeCommitMessage(), removeSourceBranch));
actions.add(new GitLabSCMAcceptMergeRequestAction(mr, mr.getIid(), source.getSourceSettings().getMergeCommitMessage(), removeSourceBranch));
}
} else {
linkAction = (head instanceof TagSCMHead) ? GitLabLinkAction.toTag(source.getProject(), head.getName()) : GitLabLinkAction.toBranch(source.getProject(), head.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


import com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty;
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi;
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
import argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest;
import com.dabsquared.gitlabjenkins.gitlab.api.model.MergeRequest;
import hudson.model.InvisibleAction;
import hudson.model.Run;
import hudson.model.TaskListener;
Expand All @@ -17,27 +19,30 @@
public final class GitLabSCMAcceptMergeRequestAction extends InvisibleAction implements Serializable {
private static final Logger LOGGER = Logger.getLogger(GitLabSCMAcceptMergeRequestAction.class.getName());

private final int projectId;
private final int mergeRequestId;
private final int mergeRequestID;
private final int mergeRequestPID;
private final int mergeRequestScopedId;
private final String commitMessage;
private final boolean removeSourceBranch;

public GitLabSCMAcceptMergeRequestAction(int projectId, int mergeRequestId, int mergeRequestScopedId, String commitMessage, boolean removeSourceBranch) {
this.projectId = projectId;
this.mergeRequestId = mergeRequestId;
public GitLabSCMAcceptMergeRequestAction(GitLabMergeRequest MR, int mergeRequestScopedId, String commitMessage, boolean removeSourceBranch) {
this.mergeRequestPID = MR.getProjectId();
this.mergeRequestID = MR.getId();
this.mergeRequestScopedId = mergeRequestScopedId;
this.commitMessage = commitMessage;
this.removeSourceBranch = removeSourceBranch;
}

public void acceptMergeRequest(Run<?, ?> build, TaskListener listener) {
GitLabApi client = GitLabConnectionProperty.getClient(build);
MergeRequest mergeRequest = new MergeRequest();
mergeRequest.setProjectId(mergeRequestPID);
mergeRequest.setId(mergeRequestID);
GitLabClient client = GitLabConnectionProperty.getClient(build);
if (client == null) {
listener.getLogger().format("cannot publish build-status pending as no gitlab-connection is configured!");
} else {
try {
client.acceptMergeRequest(projectId, mergeRequestId, MessageFormat.format(commitMessage, mergeRequestScopedId, build.getFullDisplayName()), removeSourceBranch);
client.acceptMergeRequest(mergeRequest, MessageFormat.format(commitMessage, mergeRequestScopedId, build.getFullDisplayName()), removeSourceBranch);
} catch (Exception e) {
listener.getLogger().format("failed to accept merge-request: " + e.getMessage());
LOGGER.log(SEVERE, "failed to accept merge-request", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import com.dabsquared.gitlabjenkins.connection.GitLabConnectionConfig;
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi;
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
import com.dabsquared.gitlabjenkins.gitlab.api.model.BuildState;
import hudson.init.Terminator;
import hudson.model.Run;
Expand Down Expand Up @@ -86,7 +86,7 @@ private Message(String connectionName, Run<?, ?> run, int projectId, String hash

@Override
public void run() {
GitLabApi client = getClient(connectionName);
GitLabClient client = getClient(connectionName);
if (client == null) {
LOGGER.log(WARNING, "cannot publish build-status pending as no gitlab-connection is configured!");
} else {
Expand All @@ -98,7 +98,7 @@ public void run() {
}
}

private GitLabApi getClient(String connectionName) {
private GitLabClient getClient(String connectionName) {
GitLabConnectionConfig config = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class);
return config != null ? config.getClient(connectionName) : null;
}
Expand Down

0 comments on commit a5357e2

Please sign in to comment.