Search in sources :

Example 1 with ObjectMetadataAction

use of jenkins.scm.api.metadata.ObjectMetadataAction 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 ObjectMetadataAction

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

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

the class MultiBranchTest method testGetURL.

@Test
public void testGetURL() {
    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());
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Job(hudson.model.Job) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 4 with ObjectMetadataAction

use of jenkins.scm.api.metadata.ObjectMetadataAction in project gitea-plugin by jenkinsci.

the class GiteaSCMSource method retrieveActions.

@NonNull
@Override
protected List<Action> retrieveActions(@NonNull SCMHead head, SCMHeadEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException {
    if (giteaRepository == null) {
        try (GiteaConnection c = gitea().open()) {
            listener.getLogger().format("Looking up repository %s/%s%n", repoOwner, repository);
            giteaRepository = c.fetchRepository(repoOwner, repository);
        }
    }
    List<Action> result = new ArrayList<>();
    if (head instanceof BranchSCMHead) {
        String branchUrl = UriTemplate.buildFromTemplate(serverUrl).path(UriTemplateBuilder.var("owner")).path(UriTemplateBuilder.var("repository")).path("src").path(UriTemplateBuilder.var("branch")).build().set("owner", repoOwner).set("repository", repository).set("branch", head.getName()).expand();
        result.add(new ObjectMetadataAction(null, null, branchUrl));
        result.add(new GiteaLink("icon-gitea-branch", branchUrl));
        if (head.getName().equals(giteaRepository.getDefaultBranch())) {
            result.add(new PrimaryInstanceMetadataAction());
        }
    } else if (head instanceof PullRequestSCMHead) {
        String pullUrl = UriTemplate.buildFromTemplate(serverUrl).path(UriTemplateBuilder.var("owner")).path(UriTemplateBuilder.var("repository")).path("pulls").path(UriTemplateBuilder.var("id")).build().set("owner", repoOwner).set("repository", repository).set("id", ((PullRequestSCMHead) head).getId()).expand();
        result.add(new ObjectMetadataAction(null, null, pullUrl));
        result.add(new GiteaLink("icon-gitea-branch", pullUrl));
    }
    return result;
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) Action(hudson.model.Action) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) NamedArrayList(jenkins.scm.impl.form.NamedArrayList) ArrayList(java.util.ArrayList) GiteaConnection(org.jenkinsci.plugin.gitea.client.api.GiteaConnection) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 5 with ObjectMetadataAction

use of jenkins.scm.api.metadata.ObjectMetadataAction 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)13 Test (org.junit.Test)8 PrimaryInstanceMetadataAction (jenkins.scm.api.metadata.PrimaryInstanceMetadataAction)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 NonNull (edu.umd.cs.findbugs.annotations.NonNull)3 Action (hudson.model.Action)3 ArrayList (java.util.ArrayList)3 SCMHead (jenkins.scm.api.SCMHead)3 ContributorMetadataAction (jenkins.scm.api.metadata.ContributorMetadataAction)3 NamedArrayList (jenkins.scm.impl.form.NamedArrayList)3 GiteaConnection (org.jenkinsci.plugin.gitea.client.api.GiteaConnection)3 Job (hudson.model.Job)2 Link (io.jenkins.blueocean.rest.hal.Link)2 MockChangeRequestSCMHead (jenkins.scm.impl.mock.MockChangeRequestSCMHead)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 Exported (org.kohsuke.stapler.export.Exported)2 ChangeRequestSCMHead (jenkins.scm.api.mixin.ChangeRequestSCMHead)1 GiteaOrganization (org.jenkinsci.plugin.gitea.client.api.GiteaOrganization)1