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 = "refs/pull/" + pr.getNumber() + (pr.isMerge() ? "/merge" : "/head"); } else { this.ref = "refs/heads/" + head.getName(); } }
@Override public String toString() { return getHead().getName() + ":" + hash; } public @Nonnull String getHash() {
@Override protected @Nonnull List<Action> retrieveActions(@NonNull SCMHead head, @edu.umd.cs.findbugs.annotations.CheckForNull SCMHeadEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException { // TODO for Mercurial 2.4+ check for the bookmark called @ and resolve that to determine the primary if ("default".equals(head.getName())) { return Collections.<Action>singletonList(new PrimaryInstanceMetadataAction()); } return Collections.emptyList(); }
private String retrieveRevision(SCMHead head) throws GitLabAPIException { if (head instanceof GitLabSCMMergeRequestHead) { return retrieveMergeRequestRevision(((GitLabSCMMergeRequestHead) head).getId()); } else if (head instanceof GitLabSCMTagHead) { return retrieveTagRevision(head.getName()); } return retrieveBranchRevision(head.getName()); }
@NonNull @Override protected Set<String> retrieveRevisions(@NonNull TaskListener listener) throws IOException, InterruptedException { // don't pass through to git, instead use the super.super behaviour Set<String> revisions = new HashSet<String>(); for (SCMHead head : retrieve(listener)) { revisions.add(head.getName()); } return revisions; }
@CheckForNull SCMRevision retrieve(@Nonnull SCMHead head, @Nonnull TaskListener listener) throws IOException, InterruptedException { log(listener, Messages.GitLabSCMSource_retrievingRevision(head.getName())); try { return new SCMRevisionImpl(head, retrieveRevision(head)); } catch (NoSuchElementException e) { return null; } }
@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 SCMHead migrate(@NonNull GitHubSCMSource source, @NonNull SCMHead head) { return new BranchSCMHead(head.getName()); }
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))); }
/** * {@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); }
@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() {
/** * {@inheritDoc} */ @NonNull @Override protected List<Action> retrieveActions(@NonNull SCMHead head, @CheckForNull SCMHeadEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException { SCMSourceOwner owner = getOwner(); if (owner instanceof Actionable) { for (GitRemoteHeadRefAction a: ((Actionable) owner).getActions(GitRemoteHeadRefAction.class)) { if (getRemote().equals(a.getRemote())) { if (head.getName().equals(a.getName())) { return Collections.<Action>singletonList(new PrimaryInstanceMetadataAction()); } } } } return Collections.emptyList(); }
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()); }
/** * {@inheritDoc} */ @Override public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead head) { if (head instanceof BranchSCMHead && request instanceof GitHubSCMSourceRequest) { for (GHPullRequest p : ((GitHubSCMSourceRequest) request).getPullRequests()) { GHRepository headRepo = p.getHead().getRepository(); if (headRepo != null // head repo can be null if the PR is from a repo that has been deleted && p.getBase().getRepository().getFullName().equalsIgnoreCase(headRepo.getFullName()) && p.getHead().getRef().equals(head.getName())) { return false; } } return true; } return false; } }
/** * {@inheritDoc} */ @Override public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead head) { if (head instanceof BranchSCMHead && request instanceof GitHubSCMSourceRequest) { for (GHPullRequest p : ((GitHubSCMSourceRequest) request).getPullRequests()) { GHRepository headRepo = p.getHead().getRepository(); if (headRepo != null // head repo can be null if the PR is from a repo that has been deleted && p.getBase().getRepository().getFullName().equalsIgnoreCase(headRepo.getFullName()) && p.getHead().getRef().equals(head.getName())) { return true; } } } return false; } }
@SuppressWarnings({"rawtypes", "unchecked"}) private void forceScheduling(GitHubSCMRevision scmRevision) throws IOException { SCMSourceOwner owner = source.getOwner(); if (owner instanceof MultiBranchProject) { MultiBranchProject mb = (MultiBranchProject) owner; BranchProjectFactory pf = mb.getProjectFactory(); SCMHead scmHead = scmRevision.getHead(); Job j = mb.getItemByBranchName(scmHead.getName()); if (j != null) { SCMRevision rev = pf.getRevision(j); // set current rev to dummy to force scheduling if (rev != null && rev.equals(scmRevision)) { pf.setRevisionHash(j, new DummyRevision(scmHead)); } } } }
/** * {@inheritDoc} */ @Override public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead head) { if (head instanceof BranchSCMHead && request instanceof GiteaSCMSourceRequest) { for (GiteaPullRequest p : ((GiteaSCMSourceRequest) request).getPullRequests()) { if (StringUtils.equalsIgnoreCase( p.getBase().getRepo().getOwner().getUsername(), p.getHead().getRepo().getOwner().getUsername()) && StringUtils.equalsIgnoreCase( p.getBase().getRepo().getName(), p.getHead().getRepo().getName()) && StringUtils.equals(p.getHead().getRef(), head.getName())) { return false; } } return true; } return false; } }
@Override public @Nonnull MercurialSCM build() { SCMRevision revision = revision(); MercurialSCM result = new MercurialSCM(source()); if (revision instanceof MercurialSCMSource.MercurialRevision) { result.setRevisionType(MercurialSCM.RevisionType.CHANGESET); result.setRevision(((MercurialSCMSource.MercurialRevision) revision).getHash()); } else { result.setRevisionType(MercurialSCM.RevisionType.BRANCH); result.setRevision(head().getName()); } result.setBrowser(browser()); result.setClean(clean()); result.setCredentialsId(credentialsId()); result.setInstallation(installation()); result.setDisableChangeLog(false); return result; } }