Search in sources :

Example 6 with ObjectMetadataAction

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;
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) Action(hudson.model.Action) GiteaOrganization(org.jenkinsci.plugin.gitea.client.api.GiteaOrganization) ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) 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 7 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(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;
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) Action(hudson.model.Action) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) 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 8 with ObjectMetadataAction

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);
}
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 9 with ObjectMetadataAction

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());
}
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 10 with ObjectMetadataAction

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());
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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