Search in sources :

Example 1 with ChangeRequestSCMHead

use of jenkins.scm.api.mixin.ChangeRequestSCMHead in project blueocean-plugin by jenkinsci.

the class BranchImpl method getPullRequest.

@Exported(name = PULL_REQUEST, inline = true)
public PullRequest getPullRequest() {
    // TODO probably want to be using SCMHeadCategory instances to categorize them instead of hard-coding for PRs
    SCMHead head = SCMHead.HeadByItem.findHead(job);
    if (head instanceof ChangeRequestSCMHead) {
        ChangeRequestSCMHead cr = (ChangeRequestSCMHead) head;
        ObjectMetadataAction om = job.getAction(ObjectMetadataAction.class);
        ContributorMetadataAction cm = job.getAction(ContributorMetadataAction.class);
        return new PullRequest(cr.getId(), om != null ? om.getObjectUrl() : null, om != null ? om.getObjectDisplayName() : null, cm != null ? cm.getContributor() : null);
    }
    return null;
}
Also used : ChangeRequestSCMHead(jenkins.scm.api.mixin.ChangeRequestSCMHead) SCMHead(jenkins.scm.api.SCMHead) ChangeRequestSCMHead(jenkins.scm.api.mixin.ChangeRequestSCMHead) ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) ContributorMetadataAction(jenkins.scm.api.metadata.ContributorMetadataAction) Exported(org.kohsuke.stapler.export.Exported)

Example 2 with ChangeRequestSCMHead

use of jenkins.scm.api.mixin.ChangeRequestSCMHead 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)

Aggregations

ContributorMetadataAction (jenkins.scm.api.metadata.ContributorMetadataAction)2 ObjectMetadataAction (jenkins.scm.api.metadata.ObjectMetadataAction)2 ChangeRequestSCMHead (jenkins.scm.api.mixin.ChangeRequestSCMHead)2 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 GitLabMergeRequest (argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest)1 GitLabSCMBranchHead (argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMBranchHead)1 GitLabSCMMergeRequestHead (argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead)1 Action (hudson.model.Action)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 SCMHead (jenkins.scm.api.SCMHead)1 PrimaryInstanceMetadataAction (jenkins.scm.api.metadata.PrimaryInstanceMetadataAction)1 TagSCMHead (jenkins.scm.api.mixin.TagSCMHead)1 Exported (org.kohsuke.stapler.export.Exported)1