Java Code Examples for jenkins.scm.api.SCMHead#getName()
The following examples show how to use
jenkins.scm.api.SCMHead#getName() .
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: NamedBranchBuildStrategyImpl.java From basic-branch-build-strategies-plugin with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision, @CheckForNull SCMRevision lastBuiltRevision, @CheckForNull SCMRevision lastSeenRevision, @NonNull TaskListener taskListener) { if (head instanceof ChangeRequestSCMHead) { return false; } if (head instanceof TagSCMHead) { return false; } String name = head.getName(); for (NameFilter filter: filters) { if (filter.isMatch(name)) { return true; } } return false; }
Example 2
Source File: GitLabSCMFileSystem.java From gitlab-branch-source-plugin with MIT License | 5 votes |
public SCMFileSystem build(@NonNull SCMHead head, @CheckForNull SCMRevision rev, @NonNull GitLabApi gitLabApi, @NonNull String projectPath) throws IOException, InterruptedException { String ref; if (head instanceof MergeRequestSCMHead) { ref = ((MergeRequestSCMHead) head).getOriginName(); } else if (head instanceof BranchSCMHead) { ref = head.getName(); } else if (head instanceof GitLabTagSCMHead) { ref = head.getName(); } else { return null; } return new GitLabSCMFileSystem(gitLabApi, projectPath, ref, rev); }
Example 3
Source File: GitLabSCMProbe.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 5 votes |
static GitLabSCMProbe create(GitLabSCMSource source, SCMHead head, SCMRevision revision) { if (!SCMRevisionImpl.class.isInstance(revision)) { return create(source, head, new SCMRevisionImpl(head, REVISION_HEAD)); } if (head instanceof GitLabSCMMergeRequestHead) { return create(source, ((GitLabSCMMergeRequestHead) head).getSource(), revision); } int projectId = (head instanceof GitLabSCMHead) ? ((GitLabSCMHead) head).getProjectId() : source.getProjectId(); return new GitLabSCMProbe(source.getSourceSettings().getConnectionName(), projectId, head.getName(), ((SCMRevisionImpl) revision).getHash()); }
Example 4
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 5
Source File: GitHubSCMProbe.java From github-branch-source-plugin with MIT License | 5 votes |
public GitHubSCMProbe(GitHub github, GHRepository repo, SCMHead head, SCMRevision revision) { this.gitHub = github; this.revision = revision; this.repo = repo; this.name = head.getName(); if (head instanceof PullRequestSCMHead) { PullRequestSCMHead pr = (PullRequestSCMHead) head; this.ref = "pull/" + pr.getNumber() + (pr.isMerge() ? "/merge" : "/head"); } else if (head instanceof GitHubTagSCMHead){ this.ref = "tags/" + head.getName(); } else { this.ref = "heads/" + head.getName(); } }
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: GiteaSCMFileSystem.java From gitea-plugin with MIT License | 4 votes |
@Override public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @CheckForNull SCMRevision rev) throws IOException, InterruptedException { GiteaSCMSource src = (GiteaSCMSource) source; String repoOwner; String repository; String ref; if (head instanceof PullRequestSCMHead) { repoOwner = ((PullRequestSCMHead) head).getOriginOwner(); repository = ((PullRequestSCMHead) head).getOriginRepository(); ref = ((PullRequestSCMHead) head).getOriginName(); } else if (head instanceof BranchSCMHead) { repoOwner = src.getRepoOwner(); repository = src.getRepository(); ref = head.getName(); } else if (head instanceof TagSCMHead) { repoOwner = src.getRepoOwner(); repository = src.getRepository(); ref = head.getName(); } else { return null; } SCMSourceOwner owner = source.getOwner(); String serverUrl = src.getServerUrl(); String credentialsId = src.getCredentialsId(); StandardCredentials credentials = StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardCredentials.class, owner, Jenkins.getAuthentication(), URIRequirementBuilder.fromUri(serverUrl).build() ), CredentialsMatchers.allOf( AuthenticationTokens.matcher(GiteaAuth.class), CredentialsMatchers.withId(credentialsId) ) ); if (owner != null) { CredentialsProvider.track(owner, credentials); } GiteaConnection connection = Gitea.server(serverUrl) .as(AuthenticationTokens.convert(GiteaAuth.class, credentials)) .open(); try { return new GiteaSCMFileSystem(connection, connection.fetchRepository(repoOwner, repository), ref, rev); } catch (IOException | InterruptedException e) { try { connection.close(); } catch (IOException ioe) { e.addSuppressed(ioe); } throw e; } }
Example 8
Source File: BranchSCMHead.java From github-branch-source-plugin with MIT License | 4 votes |
@Override public SCMHead migrate(@NonNull GitHubSCMSource source, @NonNull SCMHead head) { return new BranchSCMHead(head.getName()); }