Search in sources :

Example 6 with GitHubSCMSource

use of org.jenkinsci.plugins.github_branch_source.GitHubSCMSource in project blueocean-plugin by jenkinsci.

the class GithubScmContentProviderTest method testScmSourceProperties.

private void testScmSourceProperties(String mockedApiUrl) throws Exception {
    // ensure the cloud provider works with cloud org folder
    String credentialId = createGithubCredential(user);
    MultiBranchProject mbp = mockMbp(credentialId, user, GithubScm.DOMAIN_NAME);
    // unfortunately overriding the GitHub apiUrl for WireMock returns a "localhost" URL here, so we mock the call
    when(((GitHubSCMSource) mbp.getSCMSources().get(0)).getApiUri()).thenReturn(mockedApiUrl);
    ScmContentProvider provider = new GithubScmContentProvider();
    assertTrue("github provider should support github multi-branch folder", provider.support(mbp));
    assertEquals(GithubScm.ID, provider.getScmId());
    assertEquals(mockedApiUrl, provider.getApiUrl(mbp));
    // ensure the cloud provider doesn't support enterprise org folder
    mbp = mockMbp(createGithubEnterpriseCredential(), user, GithubEnterpriseScm.DOMAIN_NAME);
    assertFalse("github provider should not support github enterprise org folder", provider.support(mbp));
}
Also used : ScmContentProvider(io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider) MultiBranchProject(jenkins.branch.MultiBranchProject) GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)

Example 7 with GitHubSCMSource

use of org.jenkinsci.plugins.github_branch_source.GitHubSCMSource in project configuration-as-code-plugin by jenkinsci.

the class GlobalLibrariesTest method configure_global_library_using_github.

@Issue("JENKINS-57557")
@Test
@ConfiguredWithCode("GlobalLibrariesGitHubTest.yml")
public void configure_global_library_using_github() {
    assertEquals(1, GlobalLibraries.get().getLibraries().size());
    final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
    assertEquals("jenkins-pipeline-lib", library.getName());
    final SCMSourceRetriever retriever = (SCMSourceRetriever) library.getRetriever();
    final GitHubSCMSource scm = (GitHubSCMSource) retriever.getScm();
    assertEquals("e43d6600-ba0e-46c5-8eae-3989bf654055", scm.getId());
    assertEquals("jenkins-infra", scm.getRepoOwner());
    assertEquals("pipeline-library", scm.getRepository());
    assertEquals(3, scm.getTraits().size());
    final BranchDiscoveryTrait branchDiscovery = (BranchDiscoveryTrait) scm.getTraits().get(0);
    assertEquals(1, branchDiscovery.getStrategyId());
    final OriginPullRequestDiscoveryTrait prDiscovery = (OriginPullRequestDiscoveryTrait) scm.getTraits().get(1);
    assertEquals(2, prDiscovery.getStrategyId());
    final ForkPullRequestDiscoveryTrait forkDiscovery = (ForkPullRequestDiscoveryTrait) scm.getTraits().get(2);
    assertEquals(3, forkDiscovery.getStrategyId());
    assertThat(forkDiscovery.getTrust(), instanceOf(TrustPermission.class));
}
Also used : ForkPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait) SCMSourceRetriever(org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever) OriginPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait) LibraryConfiguration(org.jenkinsci.plugins.workflow.libs.LibraryConfiguration) GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) TrustPermission(org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait.TrustPermission) BranchDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 8 with GitHubSCMSource

use of org.jenkinsci.plugins.github_branch_source.GitHubSCMSource in project blueocean-plugin by jenkinsci.

the class GithubIssueTest method changeSetEntry.

@Test
public void changeSetEntry() throws Exception {
    MultiBranchProject project = mock(MultiBranchProject.class);
    Job job = mock(MockJob.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
    when(project.getProperties()).thenReturn(new DescribableList(project));
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(job.getParent()).thenReturn(project);
    GitHubSCMSource source = new GitHubSCMSource("foo", null, null, null, "example", "repo");
    when(project.getSCMSources()).thenReturn(Collections.singletonList(source));
    when(entry.getMsg()).thenReturn("Closed #123 #124");
    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(2, resolved.size());
    Map<String, BlueIssue> issueMap = resolved.stream().collect(Collectors.toMap(BlueIssue::getId, blueIssue -> blueIssue));
    BlueIssue issue123 = issueMap.get("#123");
    Assert.assertEquals("https://github.com/example/repo/issues/123", issue123.getURL());
    BlueIssue issue124 = issueMap.get("#124");
    Assert.assertEquals("https://github.com/example/repo/issues/124", issue124.getURL());
}
Also used : GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) Arrays(java.util.Arrays) MultiBranchProject(jenkins.branch.MultiBranchProject) ChangeLogSet(hudson.scm.ChangeLogSet) BlueIssueFactory(io.jenkins.blueocean.rest.factory.BlueIssueFactory) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) Map(java.util.Map) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Nonnull(javax.annotation.Nonnull) DescribableList(hudson.util.DescribableList) Collection(java.util.Collection) AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) ItemGroup(hudson.model.ItemGroup) Run(hudson.model.Run) Rule(org.junit.Rule) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Job(hudson.model.Job) Assert(org.junit.Assert) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Collections(java.util.Collections) GitSCMSource(jenkins.plugins.git.GitSCMSource) Mockito.mock(org.mockito.Mockito.mock) ChangeLogSet(hudson.scm.ChangeLogSet) DescribableList(hudson.util.DescribableList) MultiBranchProject(jenkins.branch.MultiBranchProject) Run(hudson.model.Run) GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) Job(hudson.model.Job) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Test(org.junit.Test)

Aggregations

GitHubSCMSource (org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)8 MultiBranchProject (jenkins.branch.MultiBranchProject)6 Test (org.junit.Test)3 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)2 DescribableList (hudson.util.DescribableList)2 ScmContentProvider (io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 BranchDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait)2 ForkPullRequestDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait)2 OriginPullRequestDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait)2 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)2 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)1 AbstractFolderProperty (com.cloudbees.hudson.plugins.folder.AbstractFolderProperty)1 AbstractFolderPropertyDescriptor (com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor)1 GitHubWebHook (com.cloudbees.jenkins.GitHubWebHook)1 StandardCredentials (com.cloudbees.plugins.credentials.common.StandardCredentials)1 Domain (com.cloudbees.plugins.credentials.domains.Domain)1 Item (hudson.model.Item)1 ItemGroup (hudson.model.ItemGroup)1