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));
}
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));
}
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));
}
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));
}
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());
}
Aggregations