use of argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead in project gitlab-branch-source-plugin by Argelbargel.
the class SourceActions method retrieve.
@Nonnull
private List<Action> retrieve(@Nonnull GitLabSCMHead head, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
List<Action> actions = new ArrayList<>();
actions.add(new GitLabSCMPublishAction(head, source.getSourceSettings()));
Action linkAction;
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));
}
} else {
linkAction = (head instanceof TagSCMHead) ? GitLabLinkAction.toTag(source.getProject(), head.getName()) : GitLabLinkAction.toBranch(source.getProject(), head.getName());
if (head instanceof GitLabSCMBranchHead && StringUtils.equals(source.getProject().getDefaultBranch(), head.getName())) {
actions.add(new PrimaryInstanceMetadataAction());
}
}
actions.add(linkAction);
return actions;
}
use of argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead in project gitlab-branch-source-plugin by Argelbargel.
the class SourceHeads method observe.
private void observe(SCMSourceCriteria criteria, @Nonnull SCMHeadObserver observer, GitLabMergeRequest mergeRequest, @Nonnull TaskListener listener) throws IOException, InterruptedException {
log(listener, Messages.GitLabSCMSource_monitoringMergeRequest(mergeRequest.getIid()));
String targetBranch = mergeRequest.getTargetBranch();
GitLabSCMMergeRequestHead head = createMergeRequest(mergeRequest.getIid(), mergeRequest.getTitle(), mergeRequest.getIid(), createBranch(mergeRequest.getSourceProjectId(), mergeRequest.getSourceBranch(), mergeRequest.getSha()), createBranch(mergeRequest.getTargetProjectId(), targetBranch, retrieveBranchRevision(targetBranch)), Objects.equals(mergeRequest.getMergeStatus(), CAN_BE_MERGED));
if (source.getSourceSettings().buildUnmerged(head)) {
observe(criteria, observer, head, listener);
}
if (source.getSourceSettings().buildMerged(head)) {
if (!head.isMergeable() && buildOnlyMergeableRequests(head)) {
log(listener, Messages.GitLabSCMSource_willNotBuildUnmergeableRequest(mergeRequest.getIid(), mergeRequest.getTargetBranch(), mergeRequest.getMergeStatus()));
}
observe(criteria, observer, head.merged(), listener);
}
if (!source.getSourceSettings().getBranchMonitorStrategy().getBuildBranchesWithMergeRequests() && head.fromOrigin()) {
branchesWithMergeRequests(listener).put(mergeRequest.getIid(), mergeRequest.getSourceBranch());
}
}
use of argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead in project gitlab-branch-source-plugin by Argelbargel.
the class SourceActions method retrieve.
@Nonnull
private List<Action> retrieve(@Nonnull SCMRevisionImpl revision, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
List<Action> actions = new ArrayList<>();
String hash = revision.getHash();
Action linkAction = GitLabLinkAction.toCommit(source.getProject(), hash);
actions.add(linkAction);
SCMHead head = revision.getHead();
if (head instanceof GitLabSCMMergeRequestHead) {
actions.add(createHeadMetadataAction(head.getName(), ((GitLabSCMMergeRequestHead) head).getSource(), hash, linkAction.getUrlName()));
} else if (head instanceof GitLabSCMHead) {
actions.add(createHeadMetadataAction(head.getName(), (GitLabSCMHead) head, hash, linkAction.getUrlName()));
}
if (event instanceof GitLabSCMEvent) {
actions.add(new GitLabSCMCauseAction(((GitLabSCMEvent) event).getCause()));
}
return actions;
}
use of argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead in project gitlab-branch-source-plugin by Argelbargel.
the class GitLabSCMMergeRequestEvent method heads.
@Override
Collection<? extends GitLabSCMHead> heads(@Nonnull GitLabSCMSource source) throws IOException, InterruptedException {
Collection<GitLabSCMHead> heads = new ArrayList<>();
MergeRequestObjectAttributes attributes = getAttributes();
Integer sourceProjectId = attributes.getSourceProjectId();
String sourceBranch = attributes.getSourceBranch();
String hash = attributes.getLastCommit().getId();
GitLabSCMMergeRequestHead head = createMergeRequest(attributes.getIid(), attributes.getTitle(), attributes.getIid(), createBranch(sourceProjectId, sourceBranch, hash), createBranch(attributes.getTargetProjectId(), attributes.getTargetBranch(), REVISION_HEAD));
if (source.getSourceSettings().buildUnmerged(head)) {
heads.add(head);
}
if (source.getSourceSettings().buildMerged(head)) {
heads.add(head.merged());
}
if (head.fromOrigin()) {
heads.add(createBranch(sourceProjectId, sourceBranch, hash));
}
return heads;
}
Aggregations