Search in sources :

Example 1 with ContributorMetadataAction

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

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

the class CachesTest method testPullRequestCacheLoaderWithoutScmHead.

@Test
public void testPullRequestCacheLoaderWithoutScmHead() throws Exception {
    ObjectMetadataAction metadataAction = new ObjectMetadataAction("A cool PR", "A very cool change", "http://example.com/pr/1");
    when(job.getAction(ObjectMetadataAction.class)).thenReturn(metadataAction);
    ContributorMetadataAction contributorMetadataAction = new ContributorMetadataAction("Hates Cake", "He hates cake", "hc@example.com");
    when(job.getAction(ContributorMetadataAction.class)).thenReturn(contributorMetadataAction);
    PowerMockito.mockStatic(ExtensionList.class);
    ExtensionList<SCMHead.HeadByItem> extensionList = mock(ExtensionList.class);
    when(extensionList.iterator()).thenReturn(Collections.emptyIterator());
    when(ExtensionList.lookup(SCMHead.HeadByItem.class)).thenReturn(extensionList);
    Caches.PullRequestCacheLoader loader = new Caches.PullRequestCacheLoader(jenkins);
    BranchImpl.PullRequest pr = loader.load(job.getFullName());
    assertNull(pr);
}
Also used : MockChangeRequestSCMHead(jenkins.scm.impl.mock.MockChangeRequestSCMHead) SCMHead(jenkins.scm.api.SCMHead) ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) ContributorMetadataAction(jenkins.scm.api.metadata.ContributorMetadataAction) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ContributorMetadataAction

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

the class CachesTest method testPullRequestCacheLoader.

@Test
public void testPullRequestCacheLoader() throws Exception {
    ObjectMetadataAction metadataAction = new ObjectMetadataAction("A cool PR", "A very cool change", "http://example.com/pr/1");
    when(job.getAction(ObjectMetadataAction.class)).thenReturn(metadataAction);
    ContributorMetadataAction contributorMetadataAction = new ContributorMetadataAction("Hates Cake", "He hates cake", "hc@example.com");
    when(job.getAction(ContributorMetadataAction.class)).thenReturn(contributorMetadataAction);
    PowerMockito.mockStatic(ExtensionList.class);
    ExtensionList<SCMHead.HeadByItem> extensionList = mock(ExtensionList.class);
    when(extensionList.iterator()).thenReturn(Collections.<SCMHead.HeadByItem>singletonList(new HeadByItemForTest()).iterator());
    when(ExtensionList.lookup(SCMHead.HeadByItem.class)).thenReturn(extensionList);
    Caches.PullRequestCacheLoader loader = new Caches.PullRequestCacheLoader(jenkins);
    BranchImpl.PullRequest pr = loader.load(job.getFullName());
    assertNotNull(pr);
    assertEquals("Hates Cake", pr.getAuthor());
    assertEquals("1", pr.getId());
    assertEquals("A cool PR", pr.getTitle());
    assertEquals("http://example.com/pr/1", pr.getUrl());
}
Also used : MockChangeRequestSCMHead(jenkins.scm.impl.mock.MockChangeRequestSCMHead) SCMHead(jenkins.scm.api.SCMHead) ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) ContributorMetadataAction(jenkins.scm.api.metadata.ContributorMetadataAction) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ContributorMetadataAction

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

the class CachesTest method testPullRequestCacheLoaderWithoutObjectMetadataAction.

@Test
public void testPullRequestCacheLoaderWithoutObjectMetadataAction() throws Exception {
    ContributorMetadataAction contributorMetadataAction = new ContributorMetadataAction("Hates Cake", "He hates cake", "hc@example.com");
    when(job.getAction(ContributorMetadataAction.class)).thenReturn(contributorMetadataAction);
    PowerMockito.mockStatic(ExtensionList.class);
    ExtensionList<SCMHead.HeadByItem> extensionList = mock(ExtensionList.class);
    when(extensionList.iterator()).thenReturn(Collections.<SCMHead.HeadByItem>singletonList(new HeadByItemForTest()).iterator());
    when(ExtensionList.lookup(SCMHead.HeadByItem.class)).thenReturn(extensionList);
    Caches.PullRequestCacheLoader loader = new Caches.PullRequestCacheLoader(jenkins);
    BranchImpl.PullRequest pr = loader.load(job.getFullName());
    assertNotNull(pr);
    assertEquals("Hates Cake", pr.getAuthor());
    assertEquals("1", pr.getId());
    assertNull(pr.getTitle());
    assertNull(pr.getUrl());
}
Also used : MockChangeRequestSCMHead(jenkins.scm.impl.mock.MockChangeRequestSCMHead) SCMHead(jenkins.scm.api.SCMHead) ContributorMetadataAction(jenkins.scm.api.metadata.ContributorMetadataAction) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SCMHead (jenkins.scm.api.SCMHead)4 ContributorMetadataAction (jenkins.scm.api.metadata.ContributorMetadataAction)4 ObjectMetadataAction (jenkins.scm.api.metadata.ObjectMetadataAction)3 MockChangeRequestSCMHead (jenkins.scm.impl.mock.MockChangeRequestSCMHead)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 ChangeRequestSCMHead (jenkins.scm.api.mixin.ChangeRequestSCMHead)1 Exported (org.kohsuke.stapler.export.Exported)1