Search in sources :

Example 1 with PrimaryInstanceMetadataAction

use of jenkins.scm.api.metadata.PrimaryInstanceMetadataAction in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testBranchInfo.

@Test
public void testBranchInfo() {
    Job job = mock(Job.class);
    BranchImpl branch = new BranchImpl(job, new Link("foo"));
    assertNotNull(branch.getBranch());
    assertNull(branch.getBranch().getUrl());
    assertFalse(branch.getBranch().isPrimary());
    ObjectMetadataAction oma = new ObjectMetadataAction("My Branch", "A feature branch", "https://path/to/branch");
    when(job.getAction(ObjectMetadataAction.class)).thenReturn(oma);
    assertEquals("https://path/to/branch", branch.getBranch().getUrl());
    assertFalse(branch.getBranch().isPrimary());
    when(job.getAction(PrimaryInstanceMetadataAction.class)).thenReturn(new PrimaryInstanceMetadataAction());
    assertTrue(branch.getBranch().isPrimary());
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Job(hudson.model.Job) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 2 with PrimaryInstanceMetadataAction

use of jenkins.scm.api.metadata.PrimaryInstanceMetadataAction 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 3 with PrimaryInstanceMetadataAction

use of jenkins.scm.api.metadata.PrimaryInstanceMetadataAction in project blueocean-plugin by jenkinsci.

the class BranchImpl method getBranch.

@Exported(name = BRANCH, inline = true)
public Branch getBranch() {
    ObjectMetadataAction om = job.getAction(ObjectMetadataAction.class);
    PrimaryInstanceMetadataAction pima = job.getAction(PrimaryInstanceMetadataAction.class);
    String url = om != null && om.getObjectUrl() != null ? om.getObjectUrl() : null;
    return new Branch(url, pima != null);
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) Exported(org.kohsuke.stapler.export.Exported)

Aggregations

ObjectMetadataAction (jenkins.scm.api.metadata.ObjectMetadataAction)3 PrimaryInstanceMetadataAction (jenkins.scm.api.metadata.PrimaryInstanceMetadataAction)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 GitLabMergeRequest (argelbargel.jenkins.plugins.gitlab_branch_source.api.GitLabMergeRequest)1 GitLabSCMBranchHead (argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMBranchHead)1 Action (hudson.model.Action)1 Job (hudson.model.Job)1 Link (io.jenkins.blueocean.rest.hal.Link)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 ChangeRequestSCMHead (jenkins.scm.api.mixin.ChangeRequestSCMHead)1 TagSCMHead (jenkins.scm.api.mixin.TagSCMHead)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 Test (org.junit.Test)1 Exported (org.kohsuke.stapler.export.Exported)1