scmRevisionHash = ((AbstractGitSCMSource.SCMRevisionImpl) scmRevision).getHash();
.encodeTo(repositoryUrl + "/tree/" + branchName, branchName)); BranchSCMHead head = new BranchSCMHead(branchName); if (request.process(head, new SCMRevisionImpl(head, branch.getSHA1()), new SCMSourceRequest.ProbeLambda<BranchSCMHead, SCMRevisionImpl>() { @NonNull
new AbstractGitSCMSource.SCMRevisionImpl(head, ghPullRequest.getHead().getSha()); result.put(head, hash);
withRevision(new AbstractGitSCMSource.SCMRevisionImpl(head, rev.getPullHash()));
new AbstractGitSCMSource.SCMRevisionImpl(head, push.getHead()));
rev = new AbstractGitSCMSource.SCMRevisionImpl((BranchSCMHead) head, repo.getBranch(ref).getSHA1());
return new SCMRevisionImpl(head, ghRepository.getRef("heads/" + head.getName()).getObject().getSha());
throws UnsupportedOperationException, IOException, InterruptedException { AbstractGitSCMSource.SCMRevisionImpl rev = getRevision(); if (rev == null ? revision == null : rev.equals(revision)) { ObjectId fromCommitId; if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) { fromCommitId = ObjectId.fromString(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash()); changelog.excludes(fromCommitId); } else {
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());
sha1 != null ? new SCMRevisionImpl(head, sha1) : null);
@Override public long lastModified() { if (repo == null) { return 0L; } synchronized (this) { if (!open) { return 0L; } } if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) { try { GHCommit commit = repo.getCommit(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash()); return commit.getCommitDate().getTime(); } catch (IOException e) { // ignore } } else if (revision == null) { try { GHRef ref = repo.getRef(this.ref); GHCommit commit = repo.getCommit(ref.getObject().getSha()); return commit.getCommitDate().getTime(); } catch (IOException e) { // ignore } } return 0; }
/** * Constructor. * * @param client the client * @param remote the remote GIT URL * @param head identifier for the head commit to be referenced * @param rev the revision. * @throws IOException on I/O error * @throws InterruptedException on thread interruption */ protected GitSCMFileSystem(GitClient client, String remote, final String head, @CheckForNull AbstractGitSCMSource.SCMRevisionImpl rev) throws IOException, InterruptedException { super(rev); this.remote = remote; this.head = head; cacheEntry = AbstractGitSCMSource.getCacheEntry(remote); listener = new LogTaskListener(LOGGER, Level.FINER); this.client = client; commitId = rev == null ? invoke(new FSFunction<ObjectId>() { @Override public ObjectId invoke(Repository repository) throws IOException, InterruptedException { return repository.getRef(head).getObjectId(); } }) : ObjectId.fromString(rev.getHash()); }
@Override public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev) throws IOException, InterruptedException, GitException { listener.getLogger().println("Merging " + targetBranch.getName() + " commit " + targetBranch.getRevision().getHash() + " into merge-request head commit " + rev.getSha1String()); checkout(scm, build, git, listener, rev); try { git.setAuthor("Jenkins", /* could parse out of JenkinsLocationConfiguration.get().getAdminAddress() but seems overkill */"nobody@nowhere"); git.setCommitter("Jenkins", "nobody@nowhere"); MergeCommand cmd = git.merge().setRevisionToMerge(ObjectId.fromString(targetBranch.getRevision().getHash())); for (GitSCMExtension ext : scm.getExtensions()) { // By default we do a regular merge, allowing it to fast-forward. ext.decorateMergeCommand(scm, build, git, listener, cmd); } cmd.execute(); } catch (GitException e) { // Try to revert merge conflict markers. checkout(scm, build, git, listener, rev); throw e; } build.addAction(new MergeRecord(targetBranch.getRefSpec().destinationRef(targetBranch.getName()), targetBranch.getRevision().getHash())); // does not seem to be used, but just in case ObjectId mergeRev = git.revParse(Constants.HEAD); listener.getLogger().println("Merge succeeded, producing " + mergeRev.name()); return new Revision(mergeRev, rev.getBranches()); // note that this ensures Build.revision != Build.marked }
@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); }
@Override public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException { if (head instanceof GitTagSCMHead) { try { ObjectId objectId = client.revParse(Constants.R_TAGS + head.getName()); return new GitTagSCMRevision((GitTagSCMHead) head, objectId.name()); } catch (GitException e) { // tag does not exist return null; } } else { for (Branch b : client.getRemoteBranches()) { String branchName = StringUtils.removeStart(b.getName(), remoteName + "/"); if (branchName.equals(head.getName())) { return new SCMRevisionImpl(head, b.getSHA1String()); } } } return null; } },
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; } }
@Nonnull private List<Action> retrieve(@Nonnull SCMRevisionImpl revision, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException { List<Action> actions = new ArrayList<>(); String hash = revision.getHash(); Action linkAction = GitLabLinkAction.toCommit(source.getProject(), hash); actions.add(linkAction); SCMHead head = revision.getHead(); if (head instanceof GitLabSCMMergeRequestHead) { actions.add(createHeadMetadataAction(head.getName(), ((GitLabSCMMergeRequestHead) head).getSource(), hash, linkAction.getUrlName())); } else if (head instanceof GitLabSCMHead) { actions.add(createHeadMetadataAction(head.getName(), (GitLabSCMHead) head, hash, linkAction.getUrlName())); } if (event instanceof GitLabSCMEvent) { actions.add(new GitLabSCMCauseAction(((GitLabSCMEvent) event).getCause())); } return actions; }
@Override public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException { String hash; try { hash = client.revParse(revision).name(); } catch (GitException x) { // Try prepending remote name in case it was a branch. try { hash = client.revParse(context.remoteName() + "/" + revision).name(); } catch (GitException x2) { listener.getLogger().println(x.getMessage()); listener.getLogger().println(x2.getMessage()); return null; } } return new SCMRevisionImpl(new SCMHead(revision), hash); } },
private boolean matches(SCMSourceCriteria criteria, GitLabSCMHead head, TaskListener listener) { SCMSourceCriteria.Probe probe = source.createProbe(head, head.getRevision()); try { if (criteria.isHead(probe, listener)) { log(listener, head.getName() + " (" + head.getRevision().getHash() + ") meets criteria"); return true; } else { log(listener, head.getName() + " (" + head.getRevision().getHash() + ") does not meet criteria"); } } catch (IOException e) { log(listener, "error checking criteria: " + e.getMessage()); } return false; }