jenkins.scm.api.metadata.PrimaryInstanceMetadataAction Java Examples
The following examples show how to use
jenkins.scm.api.metadata.PrimaryInstanceMetadataAction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BranchMetadataTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void testBranchInfo() { assertNull(branch.getBranch()); ObjectMetadataAction oma = new ObjectMetadataAction( "My Branch", "A feature branch", "https://path/to/branch" ); when(job.getAction(ObjectMetadataAction.class)).thenReturn(oma); when(job.getAction(PrimaryInstanceMetadataAction.class)).thenReturn(new PrimaryInstanceMetadataAction()); Caches.BRANCH_METADATA.invalidateAll(); assertEquals("https://path/to/branch", branch.getBranch().getUrl()); assertTrue(branch.getBranch().isPrimary()); }
Example #2
Source File: SourceActions.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 5 votes |
@Nonnull private List<Action> retrieve(@Nonnull GitLabSCMHead head, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException { List<Action> actions = new ArrayList<>(); actions.add(new GitLabSCMPublishAction(head, source.getSourceSettings())); Action linkAction; if (head instanceof ChangeRequestSCMHead) { GitLabMergeRequest mr = retrieveMergeRequest((ChangeRequestSCMHead) head, listener); linkAction = GitLabLinkAction.toMergeRequest(mr.getWebUrl()); actions.add(createAuthorMetadataAction(mr)); actions.add(createHeadMetadataAction(((GitLabSCMMergeRequestHead) head).getDescription(), ((GitLabSCMMergeRequestHead) head).getSource(), null, linkAction.getUrlName())); if (acceptMergeRequest(head)) { boolean removeSourceBranch = mr.getRemoveSourceBranch() || removeSourceBranch(head); actions.add(new GitLabSCMAcceptMergeRequestAction(mr, mr.getIid(), source.getSourceSettings().getMergeCommitMessage(), removeSourceBranch)); } } else { linkAction = (head instanceof TagSCMHead) ? GitLabLinkAction.toTag(source.getProject(), head.getName()) : GitLabLinkAction.toBranch(source.getProject(), head.getName()); if (head instanceof GitLabSCMBranchHead && StringUtils.equals(source.getProject().getDefaultBranch(), head.getName())) { actions.add(new PrimaryInstanceMetadataAction()); } } actions.add(linkAction); return actions; }
Example #3
Source File: Caches.java From blueocean-plugin with MIT License | 5 votes |
@Override public Optional<Branch> load(String key) throws Exception { Jenkins jenkins = Objects.firstNonNull(this.jenkins, Jenkins.getInstance()); Job job = jenkins.getItemByFullName(key, Job.class); if (job == null) { return Optional.absent(); } ObjectMetadataAction om = job.getAction(ObjectMetadataAction.class); PrimaryInstanceMetadataAction pima = job.getAction(PrimaryInstanceMetadataAction.class); String url = om != null && om.getObjectUrl() != null ? om.getObjectUrl() : null; if (StringUtils.isEmpty(url)) { /* * Borrowed from https://github.com/jenkinsci/branch-api-plugin/blob/c4d394415cf25b6890855a08360119313f1330d2/src/main/java/jenkins/branch/BranchNameContributor.java#L63 * for those that don't implement object metadata action */ ItemGroup parent = job.getParent(); if (parent instanceof MultiBranchProject) { BranchProjectFactory projectFactory = ((MultiBranchProject) parent).getProjectFactory(); if (projectFactory.isProject(job)) { SCMHead head = projectFactory.getBranch(job).getHead(); url = head.getName(); } } } if (StringUtils.isEmpty(url) && pima == null) { return Optional.absent(); } return Optional.of(new Branch(url, pima != null, BlueIssueFactory.resolve(job))); }
Example #4
Source File: CachesTest.java From blueocean-plugin with MIT License | 5 votes |
@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()).orNull(); assertNotNull(branch); assertTrue(branch.isPrimary()); assertEquals("http://example.com/branches/cool-branch", branch.getUrl()); }
Example #5
Source File: CachesTest.java From blueocean-plugin with MIT License | 5 votes |
@Test public void testBranchCacheLoaderWithNoObjectMetadataAction() throws Exception { PrimaryInstanceMetadataAction instanceMetadataAction = new PrimaryInstanceMetadataAction(); when(job.getAction(PrimaryInstanceMetadataAction.class)).thenReturn(instanceMetadataAction); when(job.getFullName()).thenReturn("cool-branch"); Caches.BranchCacheLoader loader = new Caches.BranchCacheLoader(jenkins); BranchImpl.Branch branch = loader.load(job.getFullName()).orNull(); assertNotNull(branch); assertTrue(branch.isPrimary()); assertNull(branch.getUrl()); }
Example #6
Source File: GitHubSCMSource.java From github-integration-plugin with MIT License | 5 votes |
@Nonnull @Override protected List<Action> retrieveActions(@Nonnull SCMHead head, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException { List<Action> actions = new ArrayList<>(); GHRepository remoteRepo = getRemoteRepo(); boolean primary = false; GitHubLinkAction link = null; String desc = null; if (head instanceof GitHubBranchSCMHead) { // mark default branch item as primary primary = remoteRepo.getDefaultBranch().equals(head.getName()); link = new GitHubBranchAction(remoteRepo, head.getName()); desc = null; } else if (head instanceof GitHubTagSCMHead) { link = new GitHubTagAction(remoteRepo, head.getName()); desc = null; } else if (head instanceof GitHubPRSCMHead) { GitHubPRSCMHead prHead = (GitHubPRSCMHead) head; link = new GitHubPRAction(remoteRepo, prHead.getPrNumber()); desc = remoteRepo.getPullRequest(prHead.getPrNumber()).getTitle(); } if (nonNull(link)) { actions.add(link); } actions.add(new ObjectMetadataAction(null, desc, isNull(link) ? null : link.getUrlName())); if (primary) { actions.add(new PrimaryInstanceMetadataAction()); } return actions; }
Example #7
Source File: GiteaSCMSource.java From gitea-plugin with MIT License | 4 votes |
@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")) .literal("/src/branch") .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 TagSCMHead) { String tagUrl = UriTemplate.buildFromTemplate(serverUrl) .path(UriTemplateBuilder.var("owner")) .path(UriTemplateBuilder.var("repository")) .literal("/src/tag") .path(UriTemplateBuilder.var("tag")) .build() .set("owner", repoOwner) .set("repository", repository) .set("tag", head.getName()) .expand(); result.add(new ObjectMetadataAction( null, null, tagUrl )); result.add(new GiteaLink("icon-gitea-branch", tagUrl)); 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")) .literal("/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; }
Example #8
Source File: GitLabBranchFilter.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 4 votes |
private boolean filter(Item item) { return !(item instanceof Actionable) || !defaultBranchOnly || ((Actionable) item).getAction(PrimaryInstanceMetadataAction.class) != null; }