scmRevisionHash = ((AbstractGitSCMSource.SCMRevisionImpl) scmRevision).getHash();
@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; }
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); } }
ObjectId fromCommitId; if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) { fromCommitId = ObjectId.fromString(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash()); changelog.excludes(fromCommitId); } else {
@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); }
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; } }
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; }
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()); }
private GitLabSCMMergeRequestHead(int id, String title, GitLabSCMHead source, GitLabSCMBranchHead target, boolean mergeable, boolean merge) { super(source.getProjectId(), title + (merge ? " (merge)" : ""), source.getRevision().getHash(), Messages.GitLabSCMMergeRequest_Pronoun(), MERGE_REQUESTS); this.id = id; this.title = title; this.sourceBranch = source; this.targetBranch = target; this.mergeable = mergeable; this.merge = merge; }
public SpecificRevisionBuildChooser(SCMRevisionImpl revision) { ObjectId sha1 = ObjectId.fromString(revision.getHash()); String name = revision.getHead().getName(); this.revision = new Revision(sha1, Collections.singleton(new Branch(name, sha1))); }
@Override public SCMRevision migrate(@NonNull GitHubSCMSource source, @NonNull AbstractGitSCMSource.SCMRevisionImpl revision) { return new AbstractGitSCMSource.SCMRevisionImpl(migrate(source, revision.getHead()), revision.getHash()); } }