-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add new endpoint build api #59
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7dc3474
Add new api call for get information from bamboo
j0nathan33 6c07463
Fix test and Add new LiveTest
j0nathan33 6c22c2a
Add missing latestCommit in object Reference
j0nathan33 fc6ca6a
Fix build
j0nathan33 ffcc11a
Fix missing file
j0nathan33 8e21459
Edit test after codeReview
j0nathan33 299c487
Rename BuildApi to BuildStatusApi after codeReview
j0nathan33 7aeffab
Fix typo
j0nathan33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/cdancy/bitbucket/rest/domain/build/Status.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.domain.build; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import org.jclouds.json.SerializedNames; | ||
|
||
@AutoValue | ||
public abstract class Status { | ||
|
||
public enum StatusState { | ||
SUCCESSFUL, | ||
FAILED | ||
} | ||
|
||
public abstract long dateAdded(); | ||
|
||
public abstract String description(); | ||
|
||
public abstract String key(); | ||
|
||
public abstract String name(); | ||
|
||
public abstract StatusState state(); | ||
|
||
public abstract String url(); | ||
|
||
@SerializedNames({"dateAdded", "description", "key", "name", "state", "url"}) | ||
public static Status create(long dateAdded, String description, String key, String name, StatusState state, | ||
String url) { | ||
return new AutoValue_Status(dateAdded, description, key, name, state, url); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/cdancy/bitbucket/rest/domain/build/StatusPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.domain.build; | ||
|
||
import com.cdancy.bitbucket.rest.domain.common.Error; | ||
import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder; | ||
import com.cdancy.bitbucket.rest.domain.common.Page; | ||
import com.cdancy.bitbucket.rest.utils.Utils; | ||
import com.google.auto.value.AutoValue; | ||
import org.jclouds.javax.annotation.Nullable; | ||
import org.jclouds.json.SerializedNames; | ||
|
||
import java.util.List; | ||
|
||
@AutoValue | ||
public abstract class StatusPage implements Page<Status>, ErrorsHolder { | ||
|
||
@SerializedNames({"start", "limit", "size", "nextPageStart", "isLastPage", "values", "errors"}) | ||
public static StatusPage create(int start, int limit, int size, int nextPageStart, boolean isLastPage, | ||
@Nullable List<Status> values, @Nullable List<Error> errors) { | ||
return new AutoValue_StatusPage(start, limit, size, nextPageStart, isLastPage, | ||
Utils.nullToEmpty(values), Utils.nullToEmpty(errors)); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/cdancy/bitbucket/rest/domain/build/Summary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.domain.build; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import org.jclouds.json.SerializedNames; | ||
|
||
@AutoValue | ||
public abstract class Summary { | ||
|
||
public abstract long failed(); | ||
|
||
public abstract long inProgress(); | ||
|
||
public abstract long successful(); | ||
|
||
@SerializedNames({"failed", "inProgress", "successful"}) | ||
public static Summary create(long failed, long inProgress, long successful) { | ||
return new AutoValue_Summary(failed, inProgress, successful); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/com/cdancy/bitbucket/rest/features/BuildApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.features; | ||
|
||
import com.cdancy.bitbucket.rest.annotations.Documentation; | ||
import com.cdancy.bitbucket.rest.domain.build.StatusPage; | ||
import com.cdancy.bitbucket.rest.domain.build.Summary; | ||
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks; | ||
import com.cdancy.bitbucket.rest.filters.BitbucketAuthentication; | ||
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.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Produces(MediaType.APPLICATION_JSON) | ||
@RequestFilters(BitbucketAuthentication.class) | ||
@Path("/rest/build-status/{jclouds.api-version}") | ||
public interface BuildApi { | ||
|
||
@Named("build:status") | ||
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/4.14.4/bitbucket-build-rest.html#idm44911111531152"}) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Path("/commits/{commitId}") | ||
@Fallback(BitbucketFallbacks.StatusPageOnError.class) | ||
@GET | ||
StatusPage status(@PathParam("commitId") String commitId, | ||
@Nullable @QueryParam("start") Integer start, | ||
@Nullable @QueryParam("limit") Integer limit); | ||
|
||
@Named("build:status-summary") | ||
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/4.14.4/bitbucket-build-rest.html#idm44911111484336"}) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Path("/commits/stats/{commitId}") | ||
@GET | ||
Summary summary(@PathParam("commitId") String commitId); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/com/cdancy/bitbucket/rest/features/BuildApiLiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.features; | ||
|
||
import com.cdancy.bitbucket.rest.BaseBitbucketApiLiveTest; | ||
import com.cdancy.bitbucket.rest.domain.build.StatusPage; | ||
import com.cdancy.bitbucket.rest.domain.build.Summary; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Test(groups = "live", testName = "BuildApiLiveTest") | ||
public class BuildApiLiveTest extends BaseBitbucketApiLiveTest { | ||
|
||
@Test | ||
public void testGetStatusByNonExistentCommit() { | ||
StatusPage statusPage = api().status(randomString(),0,100); | ||
assertThat(statusPage).isNotNull(); | ||
assertThat(statusPage.size() == 0).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testGetSummaryByNonExistentCommit() { | ||
Summary statusPage = api().summary(randomString()); | ||
assertThat(statusPage).isNotNull(); | ||
assertThat(statusPage.successful() == 0).isTrue(); | ||
assertThat(statusPage.inProgress() == 0).isTrue(); | ||
assertThat(statusPage.failed() == 0).isTrue(); | ||
} | ||
|
||
private BuildApi api() { | ||
return api.buildApi(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets rename to
BuildStatusApi
to better align with this http path.