Search in sources :

Example 1 with ScmContentProvider

use of io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider in project blueocean-plugin by jenkinsci.

the class GithubEnterpriseScmContentProviderTest method testScmSourceProperties.

private void testScmSourceProperties(String mockedApiUrl) throws Exception {
    String credentialId = createGithubEnterpriseCredential();
    MultiBranchProject mbp = mockMbp(credentialId, user, GithubEnterpriseScm.DOMAIN_NAME);
    // ensure the enterprise provider works with enterprise org folder
    ScmContentProvider provider = new GithubEnterpriseScmContentProvider();
    assertTrue("github enterprise provider should support github enterprise org folder", provider.support(mbp));
    assertEquals(GithubEnterpriseScm.ID, provider.getScmId());
    assertEquals(githubApiUrl, provider.getApiUrl(mbp));
    // ensure the enterprise provider doesn't support cloud org folder
    credentialId = createGithubCredential(user);
    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);
    assertFalse("github enterprise provider should not support github 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 2 with ScmContentProvider

use of io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider 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 3 with ScmContentProvider

use of io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider in project blueocean-plugin by jenkinsci.

the class BitbucketServerScmContentProviderTest method checkScmProperties.

@Test
public void checkScmProperties() throws Exception {
    // ensure server provider works with server multibranch pipeline
    String credentialId = createCredential(BitbucketServerScm.ID, authenticatedUser);
    MultiBranchProject mbp = mockMbp(credentialId);
    ScmContentProvider provider = new BitbucketServerScmContentProvider();
    assertTrue(provider.support(mbp));
    assertEquals(provider.getScmId(), BitbucketServerScm.ID);
    assertEquals(provider.getApiUrl(mbp), apiUrl);
    // ensure cloud provider doesn't work with server multibranch pipeline
    provider = new BitbucketCloudScmContentProvider();
    assertFalse(provider.support(mbp));
}
Also used : BitbucketCloudScmContentProvider(io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.BitbucketCloudScmContentProvider) BitbucketCloudScmContentProvider(io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.BitbucketCloudScmContentProvider) ScmContentProvider(io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider) MultiBranchProject(jenkins.branch.MultiBranchProject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ScmContentProvider

use of io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider in project blueocean-plugin by jenkinsci.

the class BitbucketCloudScmContentProviderTest method checkScmProperties.

@Test
public void checkScmProperties() throws Exception {
    // ensure cloud provider works with cloud multibranch pipeline
    String credentialId = createCredential(BitbucketCloudScm.ID, authenticatedUser);
    MultiBranchProject mbp = mockMbp(credentialId);
    ScmContentProvider provider = new BitbucketCloudScmContentProvider();
    // unfortunately overriding the apiUrl for WireMock returns a "localhost" URL here, so we mock the call
    when(((BitbucketSCMSource) mbp.getSCMSources().get(0)).getServerUrl()).thenReturn(BitbucketCloudScm.API_URL);
    assertTrue(provider.support(mbp));
    assertEquals(provider.getScmId(), BitbucketCloudScm.ID);
    assertEquals(provider.getApiUrl(mbp), BitbucketCloudScm.API_URL);
    // ensure server provider doesn't work with cloud multibranch pipeline
    provider = new BitbucketServerScmContentProvider();
    assertFalse(provider.support(mbp));
}
Also used : BitbucketServerScmContentProvider(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.BitbucketServerScmContentProvider) ScmContentProvider(io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider) MultiBranchProject(jenkins.branch.MultiBranchProject) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) BitbucketServerScmContentProvider(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.BitbucketServerScmContentProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with ScmContentProvider

use of io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider in project blueocean-plugin by jenkinsci.

the class GithubScmContentProvider method saveContent.

@Override
public Object saveContent(@Nonnull StaplerRequest staplerRequest, @Nonnull Item item) {
    JSONObject body;
    try {
        body = JSONObject.fromObject(IOUtils.toString(staplerRequest.getReader()));
    } catch (IOException e) {
        throw new ServiceException.UnexpectedErrorException("Failed to read request body");
    }
    body.put("$class", "io.jenkins.blueocean.blueocean_github_pipeline.GithubScmSaveFileRequest");
    GithubScmSaveFileRequest request = staplerRequest.bindJSON(GithubScmSaveFileRequest.class, body);
    if (request == null) {
        throw new ServiceException.BadRequestException(new ErrorMessage(400, "Failed to bind request"));
    }
    ScmContentProvider scmContentProvider = ScmContentProvider.resolve(item);
    if (scmContentProvider != null) {
        return saveContent(request, item);
    }
    throw new ServiceException.BadRequestException("No save scm content provider found for pipeline: " + item.getFullName());
}
Also used : JSONObject(net.sf.json.JSONObject) ServiceException(io.jenkins.blueocean.commons.ServiceException) AbstractScmContentProvider(io.jenkins.blueocean.rest.impl.pipeline.scm.AbstractScmContentProvider) ScmContentProvider(io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider) IOException(java.io.IOException) ErrorMessage(io.jenkins.blueocean.commons.ErrorMessage)

Aggregations

ScmContentProvider (io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider)5 MultiBranchProject (jenkins.branch.MultiBranchProject)4 GitHubSCMSource (org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 BitbucketSCMSource (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource)1 BitbucketCloudScmContentProvider (io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.BitbucketCloudScmContentProvider)1 BitbucketServerScmContentProvider (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.BitbucketServerScmContentProvider)1 ErrorMessage (io.jenkins.blueocean.commons.ErrorMessage)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 AbstractScmContentProvider (io.jenkins.blueocean.rest.impl.pipeline.scm.AbstractScmContentProvider)1 IOException (java.io.IOException)1 JSONObject (net.sf.json.JSONObject)1