use of jenkins.scm.api.metadata.ObjectMetadataAction in project gitea-plugin by jenkinsci.
the class GiteaSCMNavigator method retrieveActions.
@NonNull
@Override
protected List<Action> retrieveActions(@NonNull SCMNavigatorOwner owner, SCMNavigatorEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException {
if (this.giteaOwner == null) {
try (GiteaConnection c = gitea(owner).open()) {
this.giteaOwner = c.fetchUser(repoOwner);
if (StringUtils.isBlank(giteaOwner.getEmail())) {
this.giteaOwner = c.fetchOrganization(repoOwner);
}
}
}
List<Action> result = new ArrayList<>();
String objectUrl = UriTemplate.buildFromTemplate(serverUrl).path("owner").build().set("owner", repoOwner).expand();
result.add(new ObjectMetadataAction(Util.fixEmpty(giteaOwner.getFullName()), null, objectUrl));
if (StringUtils.isNotBlank(giteaOwner.getAvatarUrl())) {
result.add(new GiteaAvatar(giteaOwner.getAvatarUrl()));
}
result.add(new GiteaLink("icon-gitea-org", objectUrl));
if (giteaOwner instanceof GiteaOrganization) {
String website = ((GiteaOrganization) giteaOwner).getWebsite();
if (StringUtils.isBlank(website)) {
listener.getLogger().println("Organization URL: unspecified");
listener.getLogger().printf("Organization URL: %s%n", HyperlinkNote.encodeTo(website, StringUtils.defaultIfBlank(giteaOwner.getFullName(), website)));
}
}
return result;
}
use of jenkins.scm.api.metadata.ObjectMetadataAction in project gitea-plugin by jenkinsci.
the class GiteaSCMSource method retrieveActions.
@NonNull
@Override
protected List<Action> retrieveActions(SCMSourceEvent 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<>();
result.add(new ObjectMetadataAction(null, giteaRepository.getDescription(), giteaRepository.getWebsite()));
result.add(new GiteaLink("icon-gitea-repo", UriTemplate.buildFromTemplate(serverUrl).path(UriTemplateBuilder.var("owner")).path(UriTemplateBuilder.var("repository")).build().set("owner", repoOwner).set("repository", repository).expand()));
return result;
}
use of jenkins.scm.api.metadata.ObjectMetadataAction 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.ObjectMetadataAction 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.ObjectMetadataAction in project blueocean-plugin by jenkinsci.
the class CachesTest method testBranchCacheLoader.
@Test
public void testBranchCacheLoader() throws Exception {
ObjectMetadataAction metadataAction = new ObjectMetadataAction("A cool branch", "A very cool change", "http://example.com/branches/cool-branch");
PrimaryInstanceMetadataAction instanceMetadataAction = new PrimaryInstanceMetadataAction();
when(job.getAction(ObjectMetadataAction.class)).thenReturn(metadataAction);
when(job.getAction(PrimaryInstanceMetadataAction.class)).thenReturn(instanceMetadataAction);
Caches.BranchCacheLoader loader = new Caches.BranchCacheLoader(jenkins);
BranchImpl.Branch branch = loader.load(job.getFullName());
assertNotNull(branch);
assertTrue(branch.isPrimary());
assertEquals("http://example.com/branches/cool-branch", branch.getUrl());
}
Aggregations