Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuildStatusApi gained endpoint 'add'. #86

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<!-- property name="allowedAbbreviationLength" value="1"/ -->
<property name="allowedAbbreviationLength" value="5"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@
import com.cdancy.bitbucket.rest.domain.build.Summary;
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks;
import com.cdancy.bitbucket.rest.filters.BitbucketAuthentication;
import com.cdancy.bitbucket.rest.options.CreateBuildStatus;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;

import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.binders.BindToJsonPayload;

@Produces(MediaType.APPLICATION_JSON)
@RequestFilters(BitbucketAuthentication.class)
Expand All @@ -49,6 +53,15 @@ public interface BuildStatusApi {
StatusPage status(@PathParam("commitId") String commitId,
@Nullable @QueryParam("start") Integer start,
@Nullable @QueryParam("limit") Integer limit);

@Named("build:add-status")
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/4.14.4/bitbucket-build-rest.html#idm44911111500128"})
@Consumes(MediaType.APPLICATION_JSON)
@Path("/commits/{commitId}")
@Fallback(BitbucketFallbacks.FalseOnError.class)
@POST
boolean add(@PathParam("commitId") String commitId,
@BinderParam(BindToJsonPayload.class) CreateBuildStatus createBuildStatus);

@Named("build:status-summary")
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/4.14.4/bitbucket-build-rest.html#idm44911111484336"})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cdancy.bitbucket.rest.options;

import com.google.auto.value.AutoValue;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

@AutoValue
public abstract class CreateBuildStatus {

public enum STATE {
SUCCESSFUL,
FAILED,
INPROGRESS
}

public abstract String state();

public abstract String key();

@Nullable
public abstract String name();

public abstract String url();

@Nullable
public abstract String description();

CreateBuildStatus() {
}

@SerializedNames({ "state", "key", "name", "url", "description" })
public static CreateBuildStatus create(STATE state, String key, String name, String url, String description) {
return new AutoValue_CreateBuildStatus(state != null ? state.toString() : null, key, name, url, description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.cdancy.bitbucket.rest.domain.build.StatusPage;
import com.cdancy.bitbucket.rest.domain.build.Summary;
import com.cdancy.bitbucket.rest.internal.BaseBitbucketMockTest;
import com.cdancy.bitbucket.rest.options.CreateBuildStatus;
import com.google.common.collect.ImmutableMap;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
Expand Down Expand Up @@ -101,4 +102,50 @@ public void testGetSummary() throws Exception {
server.shutdown();
}
}

public void testAddBuildStatus() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

server.enqueue(new MockResponse().setBody(payloadFromResource("/build-status-post.json")).setResponseCode(204));
BitbucketApi baseApi = api(server.getUrl("/"));
BuildStatusApi api = baseApi.buildStatusApi();
try {
final CreateBuildStatus cbs = CreateBuildStatus.create(CreateBuildStatus.STATE.SUCCESSFUL,
"REPO-MASTER",
"REPO-MASTER-42",
"https://bamboo.example.com/browse/REPO-MASTER-42",
"Changes by John Doe");
final boolean success = api.add("306bcf274566f2e89f75ae6f7faf10beff38382012", cbs);
assertThat(success).isTrue();

assertSent(server, "POST", "/rest/build-status/" + BitbucketApiMetadata.API_VERSION
+ "/commits/306bcf274566f2e89f75ae6f7faf10beff38382012");
} finally {
baseApi.close();
server.shutdown();
}
}

public void testAddBuildStatusOnError() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

server.enqueue(new MockResponse().setBody(payloadFromResource("/build-status-post.json")).setResponseCode(404));
BitbucketApi baseApi = api(server.getUrl("/"));
BuildStatusApi api = baseApi.buildStatusApi();
try {
final CreateBuildStatus cbs = CreateBuildStatus.create(CreateBuildStatus.STATE.SUCCESSFUL,
"REPO-MASTER",
"REPO-MASTER-42",
"https://bamboo.example.com/browse/REPO-MASTER-42",
"Changes by John Doe");
final boolean success = api.add("306bcf274566f2e89f75ae6f7faf10beff38382012", cbs);
assertThat(success).isFalse();

assertSent(server, "POST", "/rest/build-status/" + BitbucketApiMetadata.API_VERSION
+ "/commits/306bcf274566f2e89f75ae6f7faf10beff38382012");
} finally {
baseApi.close();
server.shutdown();
}
}
}
7 changes: 7 additions & 0 deletions src/test/resources/build-status-post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"state": "SUCCESSFUL",
"key": "REPO-MASTER",
"name": "REPO-MASTER-42",
"url": "https://bamboo.example.com/browse/REPO-MASTER-42",
"description": "Changes by John Doe"
}