Search in sources :

Example 6 with HttpResponse

use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.HttpResponse in project blueocean-plugin by jenkinsci.

the class BitbucketServerApi method getDefaultBranch.

@Override
@CheckForNull
public BbBranch getDefaultBranch(@Nonnull String orgId, @Nonnull String repoSlug) {
    try {
        HttpResponse response = request.get(String.format("%s/%s/repos/%s/branches/default", baseUrl + "projects", orgId, repoSlug));
        int status = response.getStatus();
        // With 5.6.0 its 204, before that it was 404
        if (status == 404 || status == 204) {
            // empty repo gives 404, we ignore these
            return null;
        }
        InputStream inputStream = response.getContent();
        return om.readValue(inputStream, new TypeReference<BbServerBranch>() {
        });
    } catch (IOException e) {
        throw new ServiceException.UnexpectedErrorException(e.getMessage(), e);
    }
}
Also used : ServiceException(io.jenkins.blueocean.commons.ServiceException) InputStream(java.io.InputStream) HttpResponse(io.jenkins.blueocean.blueocean_bitbucket_pipeline.HttpResponse) IOException(java.io.IOException) BbServerBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch) CheckForNull(javax.annotation.CheckForNull)

Example 7 with HttpResponse

use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.HttpResponse in project blueocean-plugin by jenkinsci.

the class BitbucketApiTest method testAutoRedirectDisabled.

@Test
public void testAutoRedirectDisabled() {
    HttpResponse response = new HttpRequest.HttpRequestBuilder(apiUrl).build().get(apiUrl + "/rest/api/1.0/test-redirect");
    assertEquals(302, response.getStatus());
    assertEquals("http://localhost:7990/bitbucket/rest/api/1.0/redirect-test-success", response.getHeader("Location"));
}
Also used : HttpResponse(io.jenkins.blueocean.blueocean_bitbucket_pipeline.HttpResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HttpResponse (io.jenkins.blueocean.blueocean_bitbucket_pipeline.HttpResponse)7 ServiceException (io.jenkins.blueocean.commons.ServiceException)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Nonnull (javax.annotation.Nonnull)3 URISyntaxException (java.net.URISyntaxException)2 HttpEntity (org.apache.http.HttpEntity)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 MultipartEntityBuilder (org.apache.http.entity.mime.MultipartEntityBuilder)2 HttpRequest (io.jenkins.blueocean.blueocean_bitbucket_pipeline.HttpRequest)1 BbCloudSaveContentResponse (io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudSaveContentResponse)1 BbServerBranch (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch)1 BbServerSaveContentResponse (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerSaveContentResponse)1 URL (java.net.URL)1 Map (java.util.Map)1 CheckForNull (javax.annotation.CheckForNull)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1