jenkins.plugins.git.AbstractGitSCMSource Java Examples

The following examples show how to use jenkins.plugins.git.AbstractGitSCMSource. 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: GerritSCMSource.java    From gerrit-code-review-plugin with Apache License 2.0 6 votes vote down vote up
private RefSpecsSCMSourceTrait asRefSpecsSCMSourceTrait(String rawRefSpecs, String remoteName) {
  if (rawRefSpecs != null) {
    Set<String> defaults = new HashSet<>();
    defaults.add("+refs/heads/*:refs/remotes/origin/*");
    if (remoteName != null) {
      defaults.add("+refs/heads/*:refs/remotes/" + remoteName + "/*");
    }
    if (!defaults.contains(rawRefSpecs.trim())) {
      List<String> templates = new ArrayList<>();
      for (String rawRefSpec : rawRefSpecs.split(" ")) {
        if (StringUtils.isBlank(rawRefSpec)) {
          continue;
        }
        if (defaults.contains(rawRefSpec)) {
          templates.add(AbstractGitSCMSource.REF_SPEC_DEFAULT);
        } else {
          templates.add(rawRefSpec);
        }
      }
      if (!templates.isEmpty()) {
        return new RefSpecsSCMSourceTrait(templates.toArray(new String[templates.size()]));
      }
    }
  }
  return null;
}
 
Example #2
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Test
    public void readFileFromDir() throws Exception {
        assumeThat(revision, instanceOf(AbstractGitSCMSource.SCMRevisionImpl.class));
        assumeThat(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(),
                is("c0e024f89969b976da165eecaa71e09dc60c3da1"));
        SCMFileSystem fs = SCMFileSystem.of(source, master, revision);

        String expected = "Some text\n";
        // In previous versions of github-api, GHContent.read() (called by contentAsString())
        // would pull from the "raw" url of the GHContent instance.
        // Thus on windows, if somebody did not configure Git correctly,
        // the checkout may have "fixed" line endings that we needed to handle.
        // The problem with the raw url data is that it can get out of sync when from the actual content.
        // The GitHub API info stays sync'd and correct, so now GHContent.read() pulls from mime encoded data
        // in the GHContent record itself. Keeping this for reference in case it changes again.
//        try (InputStream inputStream = getClass().getResourceAsStream("/raw/__files/body-fu-bar.txt-b4k4I.txt")) {
//            if (inputStream != null) {
//                expected = IOUtils.toString(inputStream, StandardCharsets.US_ASCII);
//            }
//        } catch (IOException e) {
//            // ignore
//        }
        assertThat(fs.getRoot().child("fu/bar.txt").contentAsString(), is(expected));
    }
 
Example #3
Source File: GitHubSCMFileSystem.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param gitHub the {@link GitHub}
 * @param repo the {@link GHRepository}
 * @param refName the ref name, e.g. {@code heads/branchName}, {@code tags/tagName}, {@code pull/N/head} or the SHA.
 * @param rev the optional revision.
 * @throws IOException if I/O errors occur.
 */
protected GitHubSCMFileSystem(GitHub gitHub, GHRepository repo, String refName, @CheckForNull SCMRevision rev) throws IOException {
    super(rev);
    this.gitHub = gitHub;
    this.open = true;
    this.repo = repo;
    if (rev != null) {
        if (rev.getHead() instanceof PullRequestSCMHead) {
            PullRequestSCMRevision prRev = (PullRequestSCMRevision) rev;
            PullRequestSCMHead pr = (PullRequestSCMHead) prRev.getHead();
            if (pr.isMerge()) {
                this.ref = prRev.getMergeHash();
            } else {
                this.ref = prRev.getPullHash();
            }
        } else if (rev instanceof AbstractGitSCMSource.SCMRevisionImpl) {
            this.ref = ((AbstractGitSCMSource.SCMRevisionImpl) rev).getHash();
        } else {
            this.ref = refName;
        }
    } else {
        this.ref = refName;
    }
}
 
Example #4
Source File: GithubNotificationConfig.java    From github-autostatus-plugin with MIT License 6 votes vote down vote up
/**
 * Extracts the branch info from a build.
 *
 * @param build the build
 * @return true if branch info was extracted; false otherwise
 */
private Boolean extractBranchInfo(Run<?, ?> build) {
    SCMRevisionAction scmRevisionAction = build.getAction(SCMRevisionAction.class);
    if (null == scmRevisionAction) {
        return false;
    }
    SCMRevision revision = scmRevisionAction.getRevision();
    if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
        branchName = ((AbstractGitSCMSource.SCMRevisionImpl) revision).getHead().getName();
    } else if (revision instanceof PullRequestSCMRevision) {
        PullRequestSCMHead pullRequestSCMHead = (PullRequestSCMHead) ((PullRequestSCMRevision) revision).getHead();

        branchName = pullRequestSCMHead.getSourceBranch();
    }
    return true;
}
 
Example #5
Source File: GitHubSCMProbe.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@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);
}
 
Example #6
Source File: GitCloneReadSaveRequest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
public GitCloneReadSaveRequest(AbstractGitSCMSource gitSource, String branch, String commitMessage, String sourceBranch, String filePath, byte[] contents) {
    super(gitSource, branch, commitMessage, sourceBranch, filePath, contents);

    GitTool.DescriptorImpl toolDesc = Jenkins.getInstance().getDescriptorByType(GitTool.DescriptorImpl.class);
    @SuppressWarnings("deprecation")
    GitTool foundGitTool = null;
    for (SCMSourceTrait trait : gitSource.getTraits()) {
        if (trait instanceof GitToolSCMSourceTrait) {
            foundGitTool = toolDesc.getInstallation(((GitToolSCMSourceTrait) trait).getGitTool());
        }
    }
    if (foundGitTool == null) {
        foundGitTool = GitTool.getDefaultInstallation();
    }

    this.gitTool = foundGitTool;
    try {
        repositoryPath = Files.createTempDirectory("git").toFile();
    } catch (IOException e) {
        throw new ServiceException.UnexpectedErrorException("Unable to create working directory for repository clone");
    }
}
 
Example #7
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@Test
public void listDir() throws Exception {
    assumeThat(revision, instanceOf(AbstractGitSCMSource.SCMRevisionImpl.class));
    assumeThat(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(),
            is("c0e024f89969b976da165eecaa71e09dc60c3da1"));
    SCMFileSystem fs = SCMFileSystem.of(source, master, revision);
    assertThat(fs.getRoot().child("fu").children(),
            hasItem(Matchers.<SCMFile>hasProperty("name", is("manchu.txt"))));
}
 
Example #8
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@Test
public void resolveDir() throws Exception {
    assumeThat(revision, instanceOf(AbstractGitSCMSource.SCMRevisionImpl.class));
    assumeThat(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(),
            is("c0e024f89969b976da165eecaa71e09dc60c3da1"));
    SCMFileSystem fs = SCMFileSystem.of(source, master, revision);
    assertThat(fs.getRoot().child("fu").getType(), is(SCMFile.Type.DIRECTORY));
}
 
Example #9
Source File: GitHubStatusNotificationStep.java    From pipeline-githubnotify-step-plugin with MIT License 5 votes vote down vote up
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 #10
Source File: GitReadSaveRequest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
GitReadSaveRequest(
        AbstractGitSCMSource gitSource,
        String branch, String commitMessage,
        String sourceBranch, String filePath,
        byte[] contents) {
    this.gitSource = gitSource;
    this.branch = branch;
    this.commitMessage = commitMessage;
    this.sourceBranch = sourceBranch;
    this.filePath = filePath;
    this.contents = contents == null ? null : contents.clone(); // grr findbugs
}
 
Example #11
Source File: GitLabProject.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
private <T extends StandardCredentials> T credentials(AbstractGitSCMSource source, @Nonnull Class<T> type) {
    String credentialsId = source.getCredentialsId();
    if (credentialsId == null) {
        return null;
    }

    return CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(
            type, source.getOwner(), ACL.SYSTEM,
            Collections.<DomainRequirement>emptyList()), CredentialsMatchers.allOf(
            CredentialsMatchers.withId(credentialsId),
            CredentialsMatchers.instanceOf(type)));
}
 
Example #12
Source File: GitLabProject.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
public String getRemote(AbstractGitSCMSource source) {
    if (source.getCredentialsId() != null && credentials(source, StandardCredentials.class) instanceof SSHUserPrivateKey) {
        return getSshUrl();
    } else {
        return getHttpUrl();
    }
}
 
Example #13
Source File: GithubNotificationConfig.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Extracts the SHA for the build.
 *
 * @param build the build
 * @return true if SHA was extracted; false if it could not be extracted
 */
private Boolean extractCommitSha(Run<?, ?> build) {
    SCMRevisionAction scmRevisionAction = build.getAction(SCMRevisionAction.class);
    if (null == scmRevisionAction) {
        log(Level.INFO, "Could not find commit sha - status will not be provided for this build");
        return false;
    }
    SCMRevision revision = scmRevisionAction.getRevision();
    if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
        this.shaString = ((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash();
    } else if (revision instanceof PullRequestSCMRevision) {
        this.shaString = ((PullRequestSCMRevision) revision).getPullHash();
    }
    return true;
}
 
Example #14
Source File: GerritSCMSource.java    From gerrit-code-review-plugin with Apache License 2.0 5 votes vote down vote up
@Restricted(DoNotUse.class)
public String getRawRefSpecs() {
  String remoteName = null;
  RefSpecsSCMSourceTrait refSpecs = null;
  for (SCMSourceTrait trait : traits) {
    if (trait instanceof RemoteNameSCMSourceTrait) {
      remoteName = ((RemoteNameSCMSourceTrait) trait).getRemoteName();
      if (refSpecs != null) break;
    }
    if (trait instanceof RefSpecsSCMSourceTrait) {
      refSpecs = (RefSpecsSCMSourceTrait) trait;
      if (remoteName != null) break;
    }
  }
  if (remoteName == null) {
    remoteName = AbstractGitSCMSource.DEFAULT_REMOTE_NAME;
  }
  if (refSpecs == null) {
    return AbstractGitSCMSource.REF_SPEC_DEFAULT.replaceAll(
        AbstractGitSCMSource.REF_SPEC_REMOTE_NAME_PLACEHOLDER, remoteName);
  }
  StringBuilder result = new StringBuilder();
  boolean first = true;
  Pattern placeholder = Pattern.compile(AbstractGitSCMSource.REF_SPEC_REMOTE_NAME_PLACEHOLDER);
  for (String template : refSpecs.asStrings()) {
    if (first) {
      first = false;
    } else {
      result.append(' ');
    }
    result.append(placeholder.matcher(template).replaceAll(remoteName));
  }
  return result.toString();
}
 
Example #15
Source File: CommitStatusUpdater.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
private static List<GitLabBranchBuild> retrieveGitlabProjectIds(Run<?, ?> build, EnvVars environment) {
    LOGGER.log(Level.INFO, "Retrieving gitlab project ids");
    final List<GitLabBranchBuild> result = new ArrayList<>();

    GitLabWebHookCause gitlabCause = build.getCause(GitLabWebHookCause.class);
    if (gitlabCause != null) {
        return Collections.singletonList(new GitLabBranchBuild(
                gitlabCause.getData().getSourceProjectId().toString(), gitlabCause.getData().getLastCommit()));
    }

    // Check upstream causes for GitLabWebHookCause
    List<GitLabBranchBuild> builds = findBuildsFromUpstreamCauses(build.getCauses());
    if (!builds.isEmpty()) {
        return builds;
    }

    final GitLabClient gitLabClient = getClient(build);
    if (gitLabClient == null) {
        LOGGER.log(Level.WARNING, "No gitlab client found.");
        return result;
    }

    final List<BuildData> buildDatas = build.getActions(BuildData.class);
    if (CollectionUtils.isEmpty(buildDatas)) {
        LOGGER.log(Level.INFO, "Build does not contain build data.");
        return result;
    }

    if (buildDatas.size() == 1) {
        addGitLabBranchBuild(result, getBuildRevision(build), buildDatas.get(0).getRemoteUrls(), environment, gitLabClient);
    } else {
        final SCMRevisionAction scmRevisionAction = build.getAction(SCMRevisionAction.class);

        if (scmRevisionAction == null) {
            LOGGER.log(Level.INFO, "Build does not contain SCM revision action.");
            return result;
        }

        final SCMRevision scmRevision = scmRevisionAction.getRevision();

        String scmRevisionHash = null;
        if (scmRevision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
            if (scmRevision == null) {
                LOGGER.log(Level.INFO, "Build does not contain SCM revision object.");
                return result;
            }
            scmRevisionHash = ((AbstractGitSCMSource.SCMRevisionImpl) scmRevision).getHash();

            for (final BuildData buildData : buildDatas) {
                for (final Entry<String, Build> buildByBranchName : buildData.getBuildsByBranchName().entrySet()) {
                    if (buildByBranchName.getValue().getSHA1().equals(ObjectId.fromString(scmRevisionHash))) {
                        addGitLabBranchBuild(result, scmRevisionHash, buildData.getRemoteUrls(), environment, gitLabClient);
                    }
                }
            }
        }
    }

    return result;
}
 
Example #16
Source File: ChangeSCMRevision.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
ChangeSCMRevision(@Nonnull ChangeSCMHead head, @Nonnull String patchsetHash) {
  super(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(), patchsetHash));
  this.patchsetHash = patchsetHash;
  this.isFilteredByPendingChecks = !head.getPendingCheckerUuids().isEmpty();
}
 
Example #17
Source File: GitLabCommitStatusPublisherTest.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
private AbstractBuild mockBuildWithLibrary(String gitLabConnection, Result result, String... remoteUrls) {
    AbstractBuild build = mock(AbstractBuild.class);
    List<BuildData> buildDatas = new ArrayList<>();
    BuildData buildData = mock(BuildData.class);
    SCMRevisionAction scmRevisionAction = mock(SCMRevisionAction.class);
    AbstractGitSCMSource.SCMRevisionImpl revisionImpl = mock(AbstractGitSCMSource.SCMRevisionImpl.class);
    
    when(build.getAction(SCMRevisionAction.class)).thenReturn(scmRevisionAction);
    when(scmRevisionAction.getRevision()).thenReturn(revisionImpl);
    when(revisionImpl.getHash()).thenReturn(SHA1);
    
    Revision revision = mock(Revision.class);
    when(revision.getSha1String()).thenReturn(SHA1);
    when(buildData.getLastBuiltRevision()).thenReturn(revision);
    when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));

    Build gitBuild = mock(Build.class);

    when(gitBuild.getMarked()).thenReturn(revision);
    when(gitBuild.getSHA1()).thenReturn(ObjectId.fromString(SHA1));
    when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
    Map<String, Build> buildsByBranchName = new HashMap<>();
    buildsByBranchName.put("develop", gitBuild);
    when(buildData.getBuildsByBranchName()).thenReturn(buildsByBranchName);
    buildDatas.add(buildData);
    
    //Second build data (@librabry)
    BuildData buildDataLib = mock(BuildData.class);
    Revision revisionLib = mock(Revision.class);
    when(revisionLib.getSha1String()).thenReturn("SHALIB");
    when(buildDataLib.getLastBuiltRevision()).thenReturn(revisionLib);
    Build gitBuildLib = mock(Build.class);
    when(gitBuildLib.getMarked()).thenReturn(revisionLib);
    when(buildDataLib.getLastBuild(any(ObjectId.class))).thenReturn(gitBuildLib);
    buildDatas.add(buildDataLib);
    
    when(build.getActions(BuildData.class)).thenReturn(buildDatas);
    when(build.getResult()).thenReturn(result);
    when(build.getUrl()).thenReturn(BUILD_URL);

    AbstractProject<?, ?> project = mock(AbstractProject.class);
    when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection));
    when(build.getProject()).thenReturn(project);
    EnvVars environment = mock(EnvVars.class);
    when(environment.expand(anyString())).thenAnswer(new Answer<String>() {
        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    try {
        when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
    return build;
}
 
Example #18
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
public GitHubSCMFileSystemTest(String revision) {
    this.revision = revision == null ? null : new AbstractGitSCMSource.SCMRevisionImpl(master, revision);
}
 
Example #19
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullMerge_rev_userkey__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-key");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-key"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("[email protected]:tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-key"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(MergeWithGitSCMExtension.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example #20
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullMerge_rev_userpass__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-pass"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.test/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("https://github.test/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-pass"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.test/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(MergeWithGitSCMExtension.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example #21
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullMerge_rev_anon__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId(null);
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is(nullValue()));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.test/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("https://github.test/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is(nullValue()));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.test/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(MergeWithGitSCMExtension.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example #22
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullMerge_rev_userkey__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(false, null);
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-key");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-key"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("[email protected]:tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-key"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(MergeWithGitSCMExtension.class)
    ));
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example #23
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullMerge_rev_userpass__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(false, null);
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-pass"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.com/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-pass"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(MergeWithGitSCMExtension.class)
    ));
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example #24
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullMerge_rev_anon__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(false, null);
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId(null);
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is(nullValue()));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.com/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is(nullValue()));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(MergeWithGitSCMExtension.class)
    ));
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example #25
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullHead_rev_userkey__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.HEAD);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-key");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-key"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("[email protected]:tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1"));
    assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-key"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(1));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example #26
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullHead_rev_userpass__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.HEAD);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-pass"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.test/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1"));
    assertThat(config.getUrl(), is("https://github.test/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-pass"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.test/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(1));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example #27
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullHead_rev_anon__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.HEAD);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId(null);
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is(nullValue()));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.test/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1"));
    assertThat(config.getUrl(), is("https://github.test/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is(nullValue()));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.test/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(1));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example #28
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullHead_rev_userkey__when__build__then__scmBuilt() throws Exception {
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.HEAD);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    createGitHubSCMSourceForTest(false,null);
    source.setCredentialsId("user-key");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-key"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("[email protected]:tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1"));
    assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-key"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(1));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example #29
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullHead_rev_userpass__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(false, null);
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.HEAD);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-pass"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.com/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1"));
    assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-pass"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(1));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example #30
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullHead_rev_anon__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(false, null);
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.HEAD);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId(null);
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is(nullValue()));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.com/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1"));
    assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is(nullValue()));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(1));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}