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

Commit

Permalink
Blueocean support (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
grfullerton authored and Argelbargel committed May 7, 2019
1 parent 107ceb8 commit e8d1b66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.api.metadata.PrimaryInstanceMetadataAction;
import jenkins.scm.api.mixin.ChangeRequestSCMHead;
import jenkins.scm.api.metadata.ContributorMetadataAction;
import jenkins.scm.api.mixin.TagSCMHead;
import org.apache.commons.lang.StringUtils;

Expand Down Expand Up @@ -74,6 +75,8 @@ private List<Action> retrieve(@Nonnull GitLabSCMHead head, @CheckForNull SCMHead
if (head instanceof ChangeRequestSCMHead) {
GitLabMergeRequest mr = retrieveMergeRequest((ChangeRequestSCMHead) head, listener);
linkAction = GitLabLinkAction.toMergeRequest(mr.getWebUrl());
actions.add(createAuthorMetadataAction(mr));
actions.add(createHeadMetadataAction(((GitLabSCMMergeRequestHead) head).getDescription(), ((GitLabSCMMergeRequestHead) head).getSource(), null, linkAction.getUrlName()));
if (acceptMergeRequest(head)) {
boolean removeSourceBranch = mr.getRemoveSourceBranch() || removeSourceBranch(head);
actions.add(new GitLabSCMAcceptMergeRequestAction(mr, mr.getIid(), source.getSourceSettings().getMergeCommitMessage(), removeSourceBranch));
Expand Down Expand Up @@ -121,6 +124,10 @@ private List<Action> retrieve(@Nonnull SCMRevisionImpl revision, @CheckForNull S
return actions;
}

private Action createAuthorMetadataAction(GitLabMergeRequest mr) {
return new ContributorMetadataAction(mr.getAuthor().getName(), mr.getAuthor().getUsername(), mr.getAuthor().getEmail());
}

private Action createHeadMetadataAction(String name, GitLabSCMHead head, String hash, String url) {
return new GitLabSCMHeadMetadataAction(name, head.getProjectId(), head.getName(), hash, url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public static GitLabSCMMergeRequestHead createMergeRequest(int id, String name,
return createMergeRequest(id, name, iid, source, target, false);
}

public static GitLabSCMMergeRequestHead createMergeRequest(int id, String name, int iid, GitLabSCMHead source, GitLabSCMBranchHead target, boolean mergeable) {
return new GitLabSCMMergeRequestHead(id, "!" + iid + " - " + name, source, target, mergeable);
public static GitLabSCMMergeRequestHead createMergeRequest(int id, String description, int iid, GitLabSCMHead source, GitLabSCMBranchHead target, boolean mergeable) {
return new GitLabSCMMergeRequestHead(id, "MR-" + iid, description, source, target, mergeable);
}

public static GitLabSCMBranchHead createBranch(int projectId, String name, String hash, boolean hasMergeRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,32 @@
public final class GitLabSCMMergeRequestHead extends GitLabSCMHeadImpl implements ChangeRequestSCMHead {
private final int id;
private final String title;
private final String description;
private final GitLabSCMHead sourceBranch;
private final GitLabSCMBranchHead targetBranch;
private final boolean mergeable;
private final boolean merge;


GitLabSCMMergeRequestHead(int id, String title, GitLabSCMHead source, GitLabSCMBranchHead target, boolean mergeable) {
this(id, title, source, target, mergeable, false);
GitLabSCMMergeRequestHead(int id, String title, String description, GitLabSCMHead source, GitLabSCMBranchHead target, boolean mergeable) {
this(id, title, description, source, target, mergeable, false);
}

private GitLabSCMMergeRequestHead(int id, String title, GitLabSCMHead source, GitLabSCMBranchHead target, boolean mergeable, boolean merge) {
super(source.getProjectId(), title + (merge ? " (merge)" : ""), source.getRevision().getHash(), Messages.GitLabSCMMergeRequest_Pronoun(), MERGE_REQUESTS);
private GitLabSCMMergeRequestHead(int id, String title, String description, GitLabSCMHead source, GitLabSCMBranchHead target, boolean mergeable, boolean merge) {
super(source.getProjectId(), title + (merge ? "-merged" : ""), source.getRevision().getHash(), Messages.GitLabSCMMergeRequest_Pronoun(), MERGE_REQUESTS);
this.id = id;
this.title = title;
this.description = description;
this.sourceBranch = source;
this.targetBranch = target;
this.mergeable = mergeable;
this.merge = merge;
}

public String getDescription() {
return description;
}

@Nonnull
@Override
public String getId() {
Expand All @@ -65,7 +71,7 @@ public GitLabSCMHead getTarget() {
}

public GitLabSCMMergeRequestHead merged() {
return new GitLabSCMMergeRequestHead(id, title, sourceBranch, targetBranch, mergeable, true);
return new GitLabSCMMergeRequestHead(id, title, description, sourceBranch, targetBranch, mergeable, true);
}

public GitLabSCMHead getSource() {
Expand Down

0 comments on commit e8d1b66

Please sign in to comment.