protected GitHubSCMFileSystem(GitHub gitHub, GHRepository repo, String ref, @CheckForNull SCMRevision rev) throws IOException { super(rev); this.gitHub = gitHub; this.open = true; this.repo = repo; if (rev != null) { if (rev.getHead() instanceof PullRequestSCMHead) { PullRequestSCMHead pr = (PullRequestSCMHead) rev.getHead(); assert !pr.isMerge(); // TODO see below this.ref = ((PullRequestSCMRevision) rev).getPullHash(); } else if (rev instanceof AbstractGitSCMSource.SCMRevisionImpl) { this.ref = ((AbstractGitSCMSource.SCMRevisionImpl) rev).getHash(); } else { this.ref = ref; } } else { this.ref = ref; } }
@Override public SCMFile getRoot() { if (repo == null) { return null; } synchronized (this) { if (!open) { return null; } } String ref; if (revision != null) { if (revision.getHead() instanceof PullRequestSCMHead) { ref = this.ref; } else if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl){ ref = ((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(); } else { ref = this.ref; } } else { ref = this.ref; } return new GitHubSCMFile(this, repo, ref); }
/** * {@inheritDoc} */ @NonNull @Override public SubversionSCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) { if (revision != null && !head.equals(revision.getHead())) { revision = null; } if (revision != null && !(revision instanceof SCMRevisionImpl)) { revision = null; } StringBuilder remote = new StringBuilder(remoteBase); if (!remoteBase.endsWith("/")) { remote.append('/'); } remote.append(head.getName()); if (revision != null) { remote.append('@').append(((SCMRevisionImpl) revision).getRevision()); } else if (remote.indexOf("@") != -1) { // name contains an @ so need to ensure there is an @ at the end of the name remote.append('@'); } return new SubversionSCM(remote.toString(), credentialsId, "."); }
/** * {@inheritDoc} */ protected SCM run() throws Exception { StepContext context = getContext(); TaskListener listener = context.get(TaskListener.class); assert listener != null; PrintStream out = listener.getLogger(); out.printf("Checking for first existing branch from %s...%n", targets); SCMRevision fetch = source.fetch(new ObserverImpl(targets), listener).result(); if (fetch == null) { out.println("Could not find any matching branch%n"); if (ignoreErrors) { return null; } throw new AbortException("Could not find any matching branch"); } out.printf("Found %s at revision %s%n", fetch.getHead().getName(), fetch); return source.build(fetch.getHead(), fetch); }
/** * {@inheritDoc} */ protected SCM run() throws Exception { StepContext context = getContext(); TaskListener listener = context.get(TaskListener.class); assert listener != null; PrintStream out = listener.getLogger(); out.printf("Checking for first existing branch from %s...%n", targets); SCMRevision fetch = source.fetch(new ObserverImpl(targets), listener).result(); if (fetch == null) { if (ignoreErrors) { out.println("Could not find any matching branch"); return null; } throw new AbortException("Could not find any matching branch"); } out.printf("Found %s at revision %s%n", fetch.getHead().getName(), fetch); return source.build(fetch.getHead(), fetch); }
@Override public void retrieve(String name, String version, boolean changelog, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception { SCMRevision revision = scm.fetch(version, listener); if (revision == null) { throw new AbortException("No version " + version + " found for library " + name); } doRetrieve(name, changelog, scm.build(revision.getHead(), revision), target, run, listener); }
@Override public SCMRevision getTrustedRevision(SCMRevision revision, TaskListener listener) throws IOException, InterruptedException { String branch = revision.getHead().getName(); if (branch.equals("master")) { return revision; } else { listener.getLogger().println("not trusting " + branch); return fetch(new SCMHead("master"), listener); } } @Override public SCMSourceDescriptor getDescriptor() {
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 { this.ref = ref; } } else { this.ref = ref; } }
Result result = build.getResult(); String revisionToNotify = resolveHeadCommit(revision); SCMHead head = revision.getHead(); if (Result.SUCCESS.equals(result)) { createCommitStatus(repo, revisionToNotify, GHCommitState.SUCCESS, url, Messages.GitHubBuildStatusNotification_CommitStatus_Good(), head);
throws IOException, InterruptedException { if (revision instanceof PullRequestSCMRevision) { PullRequestSCMHead head = (PullRequestSCMHead) revision.getHead();
headName = rev.getHead().getName(); } else { if (branchSpec.getName().startsWith(Constants.R_HEADS)) {
private void assertRevision(@CheckForNull SCMRevision rev, @CheckForNull String expectedFile, @NonNull SCMSource source, @NonNull Run<?,?> run, @NonNull TaskListener listener) throws Exception { if (rev == null) { assertNull(expectedFile); return; } FilePath ws = new FilePath(run.getRootDir()).child("tmp"); try { source.build(rev.getHead(), rev).checkout(run, new Launcher.LocalLauncher(listener), ws, listener, null, SCMRevisionState.NONE); } catch (Exception x) { x.printStackTrace(listener.error("could not check out")); assertNull(expectedFile); return; } FilePath file = ws.child("file"); assertEquals(expectedFile, file.exists() ? file.readToString() : null); }