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;
}
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);
}
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());
}
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());
}
Aggregations