Search in sources :

Example 1 with GitLabSCMMergeRequestHead

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;
}
Also used : GitLabSCMPublishAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMPublishAction) GitLabSCMCauseAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMCauseAction) ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) GitLabSCMAcceptMergeRequestAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMAcceptMergeRequestAction) Action(hudson.model.Action) GitLabProjectAvatarMetadataAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabProjectAvatarMetadataAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) GitLabSCMHeadMetadataAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMHeadMetadataAction) GitLabLinkAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabLinkAction) ContributorMetadataAction(jenkins.scm.api.metadata.ContributorMetadataAction) ChangeRequestSCMHead(jenkins.scm.api.mixin.ChangeRequestSCMHead) GitLabMergeRequest(argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest) GitLabSCMAcceptMergeRequestAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMAcceptMergeRequestAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) ArrayList(java.util.ArrayList) TagSCMHead(jenkins.scm.api.mixin.TagSCMHead) GitLabSCMBranchHead(argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMBranchHead) GitLabSCMPublishAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMPublishAction) GitLabSCMMergeRequestHead(argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead) Nonnull(javax.annotation.Nonnull)

Example 2 with GitLabSCMMergeRequestHead

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());
    }
}
Also used : GitLabSCMMergeRequestHead(argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead)

Example 3 with GitLabSCMMergeRequestHead

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;
}
Also used : GitLabSCMPublishAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMPublishAction) GitLabSCMCauseAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMCauseAction) ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) GitLabSCMAcceptMergeRequestAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMAcceptMergeRequestAction) Action(hudson.model.Action) GitLabProjectAvatarMetadataAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabProjectAvatarMetadataAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) GitLabSCMHeadMetadataAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMHeadMetadataAction) GitLabLinkAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabLinkAction) ContributorMetadataAction(jenkins.scm.api.metadata.ContributorMetadataAction) TagSCMHead(jenkins.scm.api.mixin.TagSCMHead) SCMHead(jenkins.scm.api.SCMHead) ChangeRequestSCMHead(jenkins.scm.api.mixin.ChangeRequestSCMHead) GitLabSCMHead(argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMHead) GitLabSCMCauseAction(argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMCauseAction) ArrayList(java.util.ArrayList) GitLabSCMMergeRequestHead(argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead) GitLabSCMHead(argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMHead) GitLabSCMEvent(argelbargel.jenkins.plugins.gitlab_branch_source.events.GitLabSCMEvent) Nonnull(javax.annotation.Nonnull)

Example 4 with GitLabSCMMergeRequestHead

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;
}
Also used : ArrayList(java.util.ArrayList) MergeRequestObjectAttributes(com.dabsquared.gitlabjenkins.gitlab.hook.model.MergeRequestObjectAttributes) GitLabSCMMergeRequestHead(argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead) GitLabSCMHead(argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMHead)

Aggregations

GitLabSCMMergeRequestHead (argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead)4 ArrayList (java.util.ArrayList)3 GitLabLinkAction (argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabLinkAction)2 GitLabProjectAvatarMetadataAction (argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabProjectAvatarMetadataAction)2 GitLabSCMAcceptMergeRequestAction (argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMAcceptMergeRequestAction)2 GitLabSCMCauseAction (argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMCauseAction)2 GitLabSCMHeadMetadataAction (argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMHeadMetadataAction)2 GitLabSCMPublishAction (argelbargel.jenkins.plugins.gitlab_branch_source.actions.GitLabSCMPublishAction)2 GitLabSCMHead (argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMHead)2 Action (hudson.model.Action)2 Nonnull (javax.annotation.Nonnull)2 ContributorMetadataAction (jenkins.scm.api.metadata.ContributorMetadataAction)2 ObjectMetadataAction (jenkins.scm.api.metadata.ObjectMetadataAction)2 PrimaryInstanceMetadataAction (jenkins.scm.api.metadata.PrimaryInstanceMetadataAction)2 ChangeRequestSCMHead (jenkins.scm.api.mixin.ChangeRequestSCMHead)2 TagSCMHead (jenkins.scm.api.mixin.TagSCMHead)2 GitLabMergeRequest (argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest)1 GitLabSCMEvent (argelbargel.jenkins.plugins.gitlab_branch_source.events.GitLabSCMEvent)1 GitLabSCMBranchHead (argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMBranchHead)1 MergeRequestObjectAttributes (com.dabsquared.gitlabjenkins.gitlab.hook.model.MergeRequestObjectAttributes)1