Search in sources :

Example 1 with GitLabMergeRequest

use of argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest 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());
        if (acceptMergeRequest(head)) {
            boolean removeSourceBranch = mr.getRemoveSourceBranch() || removeSourceBranch(head);
            actions.add(new GitLabSCMAcceptMergeRequestAction(mr.getProjectId(), mr.getId(), 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) 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) Nonnull(javax.annotation.Nonnull)

Example 2 with GitLabMergeRequest

use of argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest in project gitlab-branch-source-plugin by Argelbargel.

the class SourceHeads method retrieveMergeRequests.

private void retrieveMergeRequests(@CheckForNull SCMSourceCriteria criteria, @Nonnull SCMHeadObserver observer, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    branchesWithMergeRequestsCache = new HashMap<>();
    if (source.getProject().isMergeRequestsEnabled() && source.getSourceSettings().shouldMonitorMergeRequests()) {
        log(listener, Messages.GitLabSCMSource_retrievingMergeRequests());
        GitLabMergeRequestFilter filter = source.getSourceSettings().createMergeRequestFilter(listener);
        for (GitLabMergeRequest mr : filter.filter(api().getMergeRequests(source.getProjectId()))) {
            checkInterrupt();
            if (!source.isExcluded(mr.getTargetBranch())) {
                observe(criteria, observer, mr, listener);
            }
        }
    }
}
Also used : GitLabMergeRequestFilter(argelbargel.jenkins.plugins.gitlab_branch_source.api.filters.GitLabMergeRequestFilter) GitLabMergeRequest(argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest)

Example 3 with GitLabMergeRequest

use of argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest in project gitlab-branch-source-plugin by Argelbargel.

the class SourceHeads method retrieveMergeRequest.

private void retrieveMergeRequest(SCMSourceCriteria criteria, @Nonnull SCMHeadObserver observer, @Nonnull GitLabSCMMergeRequestEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    MergeRequestObjectAttributes attributes = event.getPayload().getObjectAttributes();
    String targetBranch = attributes.getTargetBranch();
    if (!source.isExcluded(targetBranch)) {
        int mrId = attributes.getId();
        log(listener, Messages.GitLabSCMSource_retrievingMergeRequest(mrId));
        try {
            GitLabMergeRequest mr = api().getMergeRequest(source.getProjectId(), mrId);
            observe(criteria, observer, mr, listener);
        } catch (NoSuchElementException e) {
            log(listener, Messages.GitLabSCMSource_removedMergeRequest(mrId));
            branchesWithMergeRequests(listener).remove(mrId);
        }
        int sourceProjectId = attributes.getSourceProjectId();
        if (sourceProjectId == source.getProjectId()) {
            observe(criteria, observer, createBranch(source.getProjectId(), attributes.getSourceBranch(), attributes.getLastCommit().getId()), listener);
        }
    }
}
Also used : GitLabMergeRequest(argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest) MergeRequestObjectAttributes(com.dabsquared.gitlabjenkins.gitlab.hook.model.MergeRequestObjectAttributes) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

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