jenkins.scm.api.SCMRevision Java Examples
The following examples show how to use
jenkins.scm.api.SCMRevision.
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: GitLabSCMSource.java From gitlab-branch-source-plugin with MIT License | 6 votes |
@NonNull @Override public SCMRevision getTrustedRevision(@NonNull SCMRevision revision, @NonNull TaskListener listener) { if (revision instanceof MergeRequestSCMRevision) { MergeRequestSCMHead head = (MergeRequestSCMHead) revision.getHead(); try (GitLabSCMSourceRequest request = new GitLabSCMSourceContext(null, SCMHeadObserver.none()) .withTraits(traits).newRequest(this, listener)) { request.setMembers(getMembers()); boolean isTrusted = request.isTrusted(head); LOGGER.log(Level.FINEST, String.format("Trusted Revision: %s -> %s", head.getOriginOwner(), isTrusted)); if (isTrusted) { return revision; } } catch (IOException | InterruptedException e) { LOGGER.log(Level.SEVERE, "Exception caught: " + e, e); } MergeRequestSCMRevision rev = (MergeRequestSCMRevision) revision; listener.getLogger().format("Loading trusted files from target branch %s at %s rather than %s%n", head.getTarget().getName(), rev.getBaseHash(), rev.getHeadHash()); return new SCMRevisionImpl(head.getTarget(), rev.getBaseHash()); } return revision; }
Example #2
Source File: AnyBranchBuildStrategyImpl.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(strategies.isEmpty()){ return false; } for (BranchBuildStrategy strategy: strategies) { if(strategy.automaticBuild( source, head, currRevision, lastBuiltRevision, lastSeenRevision, taskListener )){ return true; }; } return false; }
Example #3
Source File: TagBuildStrategyImpl.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 TagSCMHead)) { return false; } if (atLeastMillis >= 0L || atMostMillis >= 0L) { if (atMostMillis >= 0L && atLeastMillis > atMostMillis) { // stupid configuration that corresponds to never building anything, why did the user add it against // our advice? return false; } long tagAge = System.currentTimeMillis() - ((TagSCMHead)head).getTimestamp(); if (atMostMillis >= 0L && tagAge > atMostMillis) { return false; } if (atLeastMillis >= 0L && tagAge < atLeastMillis) { return false; } } return true; }
Example #4
Source File: GitLabPipelineStatusNotifier.java From gitlab-branch-source-plugin with MIT License | 6 votes |
private static String getStatusName(final GitLabSCMSourceContext sourceContext, final String fullDisplayName, final SCMRevision revision) { final String type; if (revision instanceof BranchSCMRevision) { type = "branch"; } else if (revision instanceof MergeRequestSCMRevision) { type = getMrBuildName(fullDisplayName); } else if (revision instanceof GitTagSCMRevision) { type = "tag"; } else { type = "UNKNOWN"; LOGGER.log(Level.WARNING, () -> "Unknown SCMRevision implementation " + revision.getClass().getName() + ", append" + type + " to status name"); } String customPrefix = sourceContext.getBuildStatusNameCustomPart(); if (!customPrefix.isEmpty()) { customPrefix = customPrefix + GITLAB_PIPELINE_STATUS_DELIMITER; } final String statusName = GITLAB_PIPELINE_STATUS_PREFIX + GITLAB_PIPELINE_STATUS_DELIMITER + customPrefix + type; LOGGER.log(Level.FINEST, () -> "Retrieved status name is: " + statusName); return statusName; }
Example #5
Source File: BranchNameIssueKeyExtractor.java From atlassian-jira-software-cloud-plugin with Apache License 2.0 | 6 votes |
@Override public Set<String> extractIssueKeys(final WorkflowRun build) { // The action is only injected for Multibranch Pipeline jobs // The action is not injected for Pipeline (single branch) jobs final SCMRevisionAction scmAction = build.getAction(SCMRevisionAction.class); if (scmAction == null) { logger.debug("SCMRevisionAction is null"); return Collections.emptySet(); } final SCMRevision revision = scmAction.getRevision(); final ScmRevision scmRevision = new ScmRevision(revision.getHead().getName()); return extractIssueKeys(scmRevision); }
Example #6
Source File: GitLabSCMSource.java From gitlab-branch-source-plugin with MIT License | 6 votes |
@NonNull @Override protected List<Action> retrieveActions(@NonNull SCMRevision revision, SCMHeadEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException { List<Action> actions = new ArrayList<>(); if (revision instanceof SCMRevisionImpl) { String hash = ((SCMRevisionImpl) revision).getHash(); String commitUrl = commitUriTemplate(serverName).set("project", splitPath(projectPath)).set("hash", hash) .expand(); actions.add(GitLabLink.toCommit(commitUrl)); } if (event instanceof AbstractGitLabSCMHeadEvent) { actions.add(new GitLabSCMCauseAction(((AbstractGitLabSCMHeadEvent) event).getCause())); } return actions; }
Example #7
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 #8
Source File: AbstractMultiBranchCreateRequest.java From blueocean-plugin with MIT License | 6 votes |
/** * Certain SCMSource can tell whether it can detect presence of Jenkinsfile across all branches * @param scmSource scm source * @return true as default. false if it can determine there is no Jenkinsfile in all branches */ protected boolean repoHasJenkinsFile(@Nonnull SCMSource scmSource) { final AbstractMultiBranchCreateRequest.JenkinsfileCriteria criteria = new AbstractMultiBranchCreateRequest.JenkinsfileCriteria(); try { scmSource.fetch(criteria, new SCMHeadObserver() { @Override public void observe(@Nonnull SCMHead head, @Nonnull SCMRevision revision) throws IOException, InterruptedException { //do nothing } @Override public boolean isObserving() { //if jenkinsfile is found stop observing return !criteria.isJenkinsfileFound(); } }, TaskListener.NULL); } catch (IOException | InterruptedException e) { logger.warn("Error detecting Jenkinsfile: "+e.getMessage(), e); } return criteria.isJenkinsfileFound(); }
Example #9
Source File: GiteaSCMFileSystem.java From gitea-plugin with MIT License | 6 votes |
protected GiteaSCMFileSystem(GiteaConnection connection, GiteaRepository repo, String ref, @CheckForNull SCMRevision rev) throws IOException { super(rev); this.connection = connection; this.repo = repo; if (rev != null) { if (rev.getHead() instanceof PullRequestSCMHead) { this.ref = ((PullRequestSCMRevision) rev).getOrigin().getHash(); } else if (rev instanceof BranchSCMRevision) { this.ref = ((BranchSCMRevision) rev).getHash(); } else if (rev instanceof TagSCMRevision) { this.ref = ((TagSCMRevision) rev).getHash(); } else { this.ref = ref; } } else { this.ref = ref; } }
Example #10
Source File: GitLabSCMFileSystem.java From gitlab-branch-source-plugin with MIT License | 6 votes |
protected GitLabSCMFileSystem( GitLabApi gitLabApi, String projectPath, String ref, @CheckForNull SCMRevision rev) throws IOException { super(rev); this.gitLabApi = gitLabApi; this.projectPath = projectPath; if (rev != null) { if (rev.getHead() instanceof MergeRequestSCMHead) { this.ref = ((MergeRequestSCMRevision) rev).getOrigin().getHash(); } else if (rev instanceof BranchSCMRevision) { this.ref = ((BranchSCMRevision) rev).getHash(); } else if (rev instanceof GitTagSCMRevision) { this.ref = ((GitTagSCMRevision) rev).getHash(); } else { this.ref = ref; } } else { this.ref = ref; } }
Example #11
Source File: NoneBranchBuildStrategyImpl.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(strategies.isEmpty()){ return false; } for (BranchBuildStrategy strategy: strategies) { if(strategy.automaticBuild( source, head, currRevision, lastBuiltRevision, lastSeenRevision, taskListener )){ return false; }; } return true; }
Example #12
Source File: GitHubSCMSource.java From github-branch-source-plugin with MIT License | 5 votes |
@Override public SCMRevision getTrustedRevision(SCMRevision revision, final TaskListener listener) throws IOException, InterruptedException { if (revision instanceof PullRequestSCMRevision) { PullRequestSCMHead head = (PullRequestSCMHead) revision.getHead(); try (GitHubSCMSourceRequest request = new GitHubSCMSourceContext(null, SCMHeadObserver.none()) .withTraits(traits) .newRequest(this, listener)) { if (collaboratorNames != null) { request.setCollaboratorNames(collaboratorNames); } else { request.setCollaboratorNames(new DeferredContributorNames(request, listener)); } request.setPermissionsSource(new DeferredPermissionsSource(listener)); if (request.isTrusted(head)) { return revision; } } catch (WrappedException wrapped) { try { wrapped.unwrap(); } catch (HttpException e) { listener.getLogger() .format("It seems %s is unreachable, assuming no trusted collaborators%n", apiUri); collaboratorNames = Collections.singleton(repoOwner); } } PullRequestSCMRevision rev = (PullRequestSCMRevision) revision; listener.getLogger().format("Loading trusted files from base branch %s at %s rather than %s%n", head.getTarget().getName(), rev.getBaseHash(), rev.getPullHash()); return new SCMRevisionImpl(head.getTarget(), rev.getBaseHash()); } return revision; }
Example #13
Source File: SourceActions.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 5 votes |
@Nonnull List<Action> retrieve(@Nonnull SCMRevision revision, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException { if (revision instanceof SCMRevisionImpl) { return retrieve((SCMRevisionImpl) revision, event, listener); } return emptyList(); }
Example #14
Source File: GitHubBuildStatusNotification.java From github-branch-source-plugin with MIT License | 5 votes |
private static String resolveHeadCommit(SCMRevision revision) throws IllegalArgumentException { if (revision instanceof SCMRevisionImpl) { return ((SCMRevisionImpl) revision).getHash(); } else if (revision instanceof PullRequestSCMRevision) { return ((PullRequestSCMRevision) revision).getPullHash(); } else { throw new IllegalArgumentException("did not recognize " + revision); } }
Example #15
Source File: PullRequestSCMHead.java From github-branch-source-plugin with MIT License | 5 votes |
@Override public SCMRevision migrate(@NonNull GitHubSCMSource source, @NonNull PullRequestSCMRevision revision) { PullRequestSCMHead head = migrate(source, (FixMetadata) revision.getHead()); return head != null ? new PullRequestSCMRevision( head, revision.getBaseHash(), revision.getPullHash() ) : null; }
Example #16
Source File: PullRequestSCMHead.java From github-branch-source-plugin with MIT License | 5 votes |
@Override public SCMRevision migrate(@NonNull GitHubSCMSource source, @NonNull PullRequestSCMRevision revision) { PullRequestSCMHead head = migrate(source, (FixOrigin) revision.getHead()); return head != null ? new PullRequestSCMRevision( head, revision.getBaseHash(), revision.getPullHash() ) : null; }
Example #17
Source File: GitHubSCMSource.java From github-branch-source-plugin with MIT License | 5 votes |
@Override public void record(@NonNull SCMHead head, SCMRevision revision, boolean isMatch) { if (isMatch) { listener.getLogger().format(" Met criteria%n"); } else { listener.getLogger().format(" Does not meet criteria%n"); } }
Example #18
Source File: AbstractGiteaSCMHeadEvent.java From gitea-plugin with MIT License | 5 votes |
/** * {@inheritDoc} */ @NonNull @Override public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) { if (source instanceof GiteaSCMSource) { // check the owner, we don't care about the event if the owner isn't a match GiteaSCMSource src = (GiteaSCMSource) source; return StringUtils.equalsIgnoreCase(getPayload().getRepository().getOwner().getUsername(), src.getRepoOwner()) && StringUtils.equalsIgnoreCase(getPayload().getRepository().getName(), src.getRepository()) && GiteaServers.isEventFor(src.getServerUrl(), getPayload().getRepository().getHtmlUrl()) ? headsFor(src) : Collections.<SCMHead, SCMRevision>emptyMap(); } return Collections.emptyMap(); }
Example #19
Source File: GitHubSCMSource.java From github-branch-source-plugin with MIT License | 5 votes |
@NonNull @Override protected SCMProbe createProbe(@NonNull SCMHead head, @CheckForNull final SCMRevision revision) throws IOException { StandardCredentials credentials = Connector.lookupScanCredentials((Item) getOwner(), apiUri, credentialsId); // Github client and validation GitHub github = Connector.connect(apiUri, credentials); try { String fullName = repoOwner + "/" + repository; final GHRepository repo = github.getRepository(fullName); return new GitHubSCMProbe(github, repo, head, revision); } catch (IOException | RuntimeException | Error e) { Connector.release(github); throw e; } }
Example #20
Source File: GitHubStatusNotificationStep.java From pipeline-githubnotify-step-plugin with MIT License | 5 votes |
private String tryToInferSha() { SCMRevisionAction action = run.getAction(SCMRevisionAction.class); if (action != null) { SCMRevision revision = action.getRevision(); if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) { return ((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(); } else if (revision instanceof PullRequestSCMRevision) { return ((PullRequestSCMRevision) revision).getPullHash(); } else { throw new IllegalArgumentException(UNABLE_TO_INFER_COMMIT); } } else { throw new IllegalArgumentException(UNABLE_TO_INFER_COMMIT); } }
Example #21
Source File: ForkPullRequestDiscoveryTrait.java From gitea-plugin with MIT License | 5 votes |
/** * Constructor for stapler. * * @param strategyId the strategy id. * @param trust the authority to use. */ @DataBoundConstructor public ForkPullRequestDiscoveryTrait(int strategyId, @NonNull SCMHeadAuthority<? super GiteaSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> trust) { this.strategyId = strategyId; this.trust = trust; }
Example #22
Source File: GiteaSCMBuilder.java From gitea-plugin with MIT License | 5 votes |
/** * Constructor. * * @param source the {@link GiteaSCMSource}. * @param head the {@link SCMHead} * @param revision the (optional) {@link SCMRevision} */ public GiteaSCMBuilder(@NonNull GiteaSCMSource source, @NonNull SCMHead head, @CheckForNull SCMRevision revision) { super( head, revision, checkoutUriTemplate(null, source.getServerUrl(), null, null) .set("owner", source.getRepoOwner()) .set("repository", source.getRepository()) .expand(), source.getCredentialsId() ); this.context = source.getOwner(); serverUrl = source.getServerUrl(); repoOwner = source.getRepoOwner(); repository = source.getRepository(); sshRemote = source.getSshRemote(); // now configure the ref specs withoutRefSpecs(); String repoUrl; if (head instanceof PullRequestSCMHead) { PullRequestSCMHead h = (PullRequestSCMHead) head; withRefSpec("+refs/pull/" + h.getId() + "/head:refs/remotes/@{remote}/" + head .getName()); repoUrl = repositoryUrl(h.getOriginOwner(), h.getOriginRepository()); } else if (head instanceof TagSCMHead) { withRefSpec("+refs/tags/" + head.getName() + ":refs/tags/@{remote}/" + head.getName()); repoUrl = repositoryUrl(repoOwner, repository); } else { withRefSpec("+refs/heads/" + head.getName() + ":refs/remotes/@{remote}/" + head.getName()); repoUrl = repositoryUrl(repoOwner, repository); } // pre-configure the browser withBrowser(new GiteaBrowser(repoUrl)); }
Example #23
Source File: GiteaCreateSCMEvent.java From gitea-plugin with MIT License | 5 votes |
/** * {@inheritDoc} */ @NonNull @Override public Map<SCMHead, SCMRevision> headsFor(GiteaSCMSource source) { String ref = getPayload().getRef(); ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref; BranchSCMHead h = new BranchSCMHead(ref); return Collections.<SCMHead, SCMRevision>singletonMap(h, new BranchSCMRevision(h, getPayload().getSha())); }
Example #24
Source File: GiteaSCMSource.java From gitea-plugin with MIT License | 5 votes |
@Override public void record(@NonNull SCMHead head, SCMRevision revision, boolean isMatch) { if (isMatch) { listener.getLogger().format(" Met criteria%n"); } else { listener.getLogger().format(" Does not meet criteria%n"); } }
Example #25
Source File: GiteaPushSCMEvent.java From gitea-plugin with MIT License | 5 votes |
/** * {@inheritDoc} */ @NonNull @Override public Map<SCMHead, SCMRevision> headsFor(GiteaSCMSource source) { String ref = getPayload().getRef(); ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref; BranchSCMHead h = new BranchSCMHead(ref); return Collections.<SCMHead, SCMRevision>singletonMap(h, StringUtils.isNotBlank(getPayload().getAfter()) ? new BranchSCMRevision(h, getPayload().getAfter()) : null); }
Example #26
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 #27
Source File: GitHubSCMSource.java From github-integration-plugin with MIT License | 5 votes |
@Nonnull @Override public Set<SCMRevision> parentRevisions(@Nonnull SCMHead head, @Nonnull SCMRevision revision, @CheckForNull TaskListener listener) throws IOException, InterruptedException { return super.parentRevisions(head, revision, listener); }
Example #28
Source File: ChangeRequestBuildStrategyImpl.java From basic-branch-build-strategies-plugin with MIT License | 5 votes |
/** * {@inheritDoc} */ @Restricted(ProtectedExternally.class) @Override public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision, @CheckForNull SCMRevision lastBuiltRevision, @CheckForNull SCMRevision lastSeenRevision, @NonNull TaskListener listener) { if (!(head instanceof ChangeRequestSCMHead)) { return false; } if (ignoreTargetOnlyChanges && currRevision instanceof ChangeRequestSCMRevision && lastBuiltRevision instanceof ChangeRequestSCMRevision) { ChangeRequestSCMRevision<?> curr = (ChangeRequestSCMRevision<?>) currRevision; if (curr.isMerge() && curr.equivalent((ChangeRequestSCMRevision<?>) lastBuiltRevision)) { return false; } } try { if (ignoreUntrustedChanges && !currRevision.equals(source.getTrustedRevision(currRevision, listener))) { return false; } } catch (IOException | InterruptedException e) { LogRecord lr = new LogRecord(Level.WARNING, "Could not determine trust status for revision {0} of {1}, assuming untrusted"); lr.setParameters(new Object[] {currRevision, head}); lr.setThrown(e); Functions.printLogRecord(lr); return false; } return true; }
Example #29
Source File: ChangeRequestBuildStrategyImpl.java From basic-branch-build-strategies-plugin with MIT License | 5 votes |
/** * {@inheritDoc} */ @Restricted(ProtectedExternally.class) @Deprecated @Override public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision, @CheckForNull SCMRevision prevRevision, @NonNull TaskListener taskListener) { return isAutomaticBuild(source,head, currRevision, prevRevision, prevRevision, taskListener); }
Example #30
Source File: BranchBuildStrategyImpl.java From basic-branch-build-strategies-plugin with MIT License | 5 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; } return true; }