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