Skip to content

Commit

Permalink
Merge branch 'master' into upgrade-to-gradle-6.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cdancy authored Mar 23, 2021
2 parents ef856f0 + 84ded8a commit 42ea26f
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 46 deletions.
6 changes: 5 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
### Version 2.7.2 (TBA)
### Version 2.7.3 (TBA)

### Version 2.7.2 (02/08/2021)
* ADDED: `Commit` object gained properties `committer` and `committerTimestamp` . - [PR 261](https://github.com/cdancy/bitbucket-rest/pull/261)
* ADDED: `PullRequestSettings` object gained property `unapproveOnUpdate` . - [PR 263](https://github.com/cdancy/bitbucket-rest/pull/263)

### Version 2.7.1 (10/30/2020)
* ADDED: `SearchApi` with endpoints `search` . - [PR 242](https://github.com/cdancy/bitbucket-rest/pull/242)
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ repositories {
}

dependencies {
ext.jcloudsVersion = '2.2.1'
ext.autoValueVersion = '1.7.4'
ext.jcloudsVersion = '2.3.0'
ext.autoValueVersion = '1.7.5'
ext.autoServiceVersion = '1.0-rc7'
ext.guiceVersion = '4.2.3'

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = com.cdancy
version = 2.7.2-SNAPSHOT
version = 2.7.3-SNAPSHOT

artifactoryURL = http://127.0.0.1:8080/artifactory
artifactoryUser = admin
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.cdancy.bitbucket.rest.features.FileApi;
import com.cdancy.bitbucket.rest.features.HookApi;
import com.cdancy.bitbucket.rest.features.InsightsApi;
import com.cdancy.bitbucket.rest.features.LabelsApi;
import com.cdancy.bitbucket.rest.features.ProjectApi;
import com.cdancy.bitbucket.rest.features.PullRequestApi;
import com.cdancy.bitbucket.rest.features.RepositoryApi;
Expand Down Expand Up @@ -95,8 +96,10 @@ public interface BitbucketApi extends Closeable {

@Delegate
KeysApi keysApi();

@Delegate
SearchApi searchApi();

@Delegate
LabelsApi labelsApi();
}
37 changes: 23 additions & 14 deletions src/main/java/com/cdancy/bitbucket/rest/domain/commit/Commit.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public abstract class Commit implements ErrorsHolder {

public abstract long authorTimestamp();

@Nullable
public abstract Author committer();

public abstract long committerTimestamp();

@Nullable
public abstract String message();

Expand All @@ -49,22 +54,26 @@ public abstract class Commit implements ErrorsHolder {
Commit() {
}

@SerializedNames({ "id", "displayId", "author",
"authorTimestamp", "message", "parents", "errors" })
public static Commit create(final String id,
final String displayId,
@SerializedNames({ "id", "displayId", "author",
"authorTimestamp", "committer", "committerTimestamp", "message", "parents", "errors" })
public static Commit create(final String id,
final String displayId,
final Author author,
final long authorTimestamp,
final String message,
final List<Parents> parents,
final long authorTimestamp,
final Author committer,
final long committerTimestamp,
final String message,
final List<Parents> parents,
final List<Error> errors) {

return new AutoValue_Commit(BitbucketUtils.nullToEmpty(errors),
id,
displayId,
author,
authorTimestamp,
message,

return new AutoValue_Commit(BitbucketUtils.nullToEmpty(errors),
id,
displayId,
author,
authorTimestamp,
committer,
committerTimestamp,
message,
BitbucketUtils.nullToEmpty(parents));
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/domain/labels/Label.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.labels;

import com.cdancy.bitbucket.rest.BitbucketUtils;
import com.cdancy.bitbucket.rest.domain.common.Error;
import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
import com.google.auto.value.AutoValue;
import org.jclouds.json.SerializedNames;

import java.util.List;

@AutoValue
public abstract class Label implements ErrorsHolder {

public abstract String name();

Label() {
}

@SerializedNames({"name", "errors"})
public static Label create(final String name, final List<Error> errors) {
return new AutoValue_Label(BitbucketUtils.nullToEmpty(errors), name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.labels;

import com.cdancy.bitbucket.rest.BitbucketUtils;
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.google.auto.value.AutoValue;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import java.util.List;

@AutoValue
public abstract class LabelsPage implements Page<Label>, ErrorsHolder {

@SerializedNames({"start", "limit", "size", "nextPageStart", "isLastPage", "values", "errors"})
public static LabelsPage create(final int start,
final int limit,
final int size,
final int nextPageStart,
final boolean isLastPage,
final List<Label> values,
@Nullable final List<Error> errors) {

return new AutoValue_LabelsPage(start,
limit,
size,
nextPageStart,
isLastPage,
BitbucketUtils.nullToEmpty(values),
BitbucketUtils.nullToEmpty(errors));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,26 @@ public abstract class PullRequestSettings implements ErrorsHolder {
@Nullable
public abstract Long requiredSuccessfulBuilds();

@SerializedNames({ "mergeConfig", "requiredAllApprovers",
@Nullable
public abstract Boolean unapproveOnUpdate();

@SerializedNames({ "mergeConfig", "requiredAllApprovers",
"requiredAllTasksComplete", "requiredApprovers",
"requiredSuccessfulBuilds", "errors" })
public static PullRequestSettings create(final MergeConfig mergeConfig,
"requiredSuccessfulBuilds", "unapproveOnUpdate", "errors" })
public static PullRequestSettings create(final MergeConfig mergeConfig,
final Boolean requiredAllApprovers,
final Boolean requiredAllTasksComplete,
final Boolean requiredAllTasksComplete,
final Long requiredApprovers,
final Long requiredSuccessfulBuilds,
final Long requiredSuccessfulBuilds,
final Boolean unapproveOnUpdate,
@Nullable final List<Error> errors) {
return new AutoValue_PullRequestSettings(BitbucketUtils.nullToEmpty(errors),
mergeConfig,

return new AutoValue_PullRequestSettings(BitbucketUtils.nullToEmpty(errors),
mergeConfig,
requiredAllApprovers,
requiredAllTasksComplete,
requiredApprovers,
requiredSuccessfulBuilds);
requiredAllTasksComplete,
requiredApprovers,
requiredSuccessfulBuilds,
unapproveOnUpdate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import com.cdancy.bitbucket.rest.domain.insights.AnnotationsResponse;
import com.cdancy.bitbucket.rest.domain.insights.InsightReport;
import com.cdancy.bitbucket.rest.domain.insights.InsightReportPage;
import com.cdancy.bitbucket.rest.domain.labels.Label;
import com.cdancy.bitbucket.rest.domain.labels.LabelsPage;
import com.cdancy.bitbucket.rest.domain.participants.Participants;
import com.cdancy.bitbucket.rest.domain.participants.Participants.Role;
import com.cdancy.bitbucket.rest.domain.participants.Participants.Status;
Expand Down Expand Up @@ -587,6 +589,26 @@ public Object createOrPropagate(final Throwable throwable) throws Exception {
}
}

public static final class LabelsOnError implements Fallback<Object> {
@Override
public Object createOrPropagate(final Throwable throwable) throws Exception {
if (checkNotNull(throwable, "throwable") != null) {
return createLabelsPageFromErrors(getErrors(throwable.getMessage()));
}
throw propagate(throwable);
}
}

public static final class LabelByNameOnError implements Fallback<Object> {
@Override
public Object createOrPropagate(final Throwable throwable) throws Exception {
if (checkNotNull(throwable, "throwable") != null) {
return createLabelByNameFromErrors(getErrors(throwable.getMessage()));
}
throw propagate(throwable);
}
}

public static RequestStatus createRequestStatusFromErrors(final List<Error> errors) {
return RequestStatus.create(false, errors);
}
Expand Down Expand Up @@ -660,7 +682,7 @@ public static CommitPage createCommitPageFromErrors(final List<Error> errors) {
}

public static Commit createCommitFromErrors(final List<Error> errors) {
return Commit.create("-1", "-1", null, 0, null, null, errors);
return Commit.create("-1", "-1", null, 0, null, 0, null, null, errors);
}

public static Tag createTagFromErrors(final List<Error> errors) {
Expand Down Expand Up @@ -716,7 +738,7 @@ public static ProjectPermissionsPage createProjectPermissionsPageFromErrors(fina
}

public static PullRequestSettings createPullRequestSettingsFromErrors(final List<Error> errors) {
return PullRequestSettings.create(null, null, null, null, null, errors);
return PullRequestSettings.create(null, null, null, null, null, null, errors);
}

public static ProjectPage createProjectPageFromErrors(final List<Error> errors) {
Expand Down Expand Up @@ -778,6 +800,14 @@ public static AccessKeyPage createAccessKeyPageFromErrors(final List<Error> erro
return AccessKeyPage.create(0, 0, 0, 0, false, null, errors);
}

public static LabelsPage createLabelsPageFromErrors(final List<Error> errors) {
return LabelsPage.create(0, 0, 0, 0, false, null, errors);
}

public static Label createLabelByNameFromErrors(final List<Error> errors) {
return Label.create("", errors);
}

/**
* Parse list of Error's from output.
*
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/features/LabelsApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.labels.Label;
import com.cdancy.bitbucket.rest.domain.labels.LabelsPage;
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks;
import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter;
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(BitbucketAuthenticationFilter.class)
@Path("/rest")
public interface LabelsApi {

@Named("labels:list")
@Documentation({"https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html#idp86"})
@Consumes(MediaType.APPLICATION_JSON)
@Path("/api/{jclouds.api-version}/labels")
@Fallback(BitbucketFallbacks.LabelsOnError.class)
@GET
LabelsPage list(@Nullable @QueryParam("prefix") String prefix);

@Named("labels:get-by-name")
@Documentation({"https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html#idp88"})
@Consumes(MediaType.APPLICATION_JSON)
@Path("/api/{jclouds.api-version}/labels/{labelName}")
@Fallback(BitbucketFallbacks.LabelByNameOnError.class)
@GET
Label getLabelByName(@PathParam("labelName") String labelName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,24 @@ public abstract class CreatePullRequestSettings {

public abstract long requiredSuccessfulBuilds();

public abstract boolean unapproveOnUpdate();

public static CreatePullRequestSettings create(final PullRequestSettings pullRequestSettings) {
return new AutoValue_CreatePullRequestSettings(pullRequestSettings.mergeConfig(),
pullRequestSettings.requiredAllApprovers(), pullRequestSettings.requiredAllTasksComplete(),
pullRequestSettings.requiredApprovers(), pullRequestSettings.requiredSuccessfulBuilds());
pullRequestSettings.requiredApprovers(), pullRequestSettings.requiredSuccessfulBuilds(),
pullRequestSettings.unapproveOnUpdate());
}

@SerializedNames({ "mergeConfig", "requiredAllApprovers", "requiredAllTasksComplete",
"requiredApprovers", "requiredSuccessfulBuilds" })
public static CreatePullRequestSettings create(final MergeConfig mergeConfig,
"requiredApprovers", "requiredSuccessfulBuilds", "unapproveOnUpdate" })
public static CreatePullRequestSettings create(final MergeConfig mergeConfig,
final boolean requiredAllApprovers,
final boolean requiredAllTasksComplete,
final boolean requiredAllTasksComplete,
final long requiredApprovers,
final long requiredSuccessfulBuilds) {
final long requiredSuccessfulBuilds,
final boolean unapproveOnUpdate) {
return new AutoValue_CreatePullRequestSettings(mergeConfig, requiredAllApprovers, requiredAllTasksComplete,
requiredApprovers, requiredSuccessfulBuilds);
requiredApprovers, requiredSuccessfulBuilds, unapproveOnUpdate);
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/cdancy/bitbucket/rest/TestUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static synchronized User getDefaultUser(final BitbucketAuthentication aut
assertThat(userPage).isNotNull();
assertThat(userPage.size() > 0).isTrue();
for (final User user : userPage.values()) {
if (username.equals(user.slug())) {
if (username.equals(user.name())) {
defaultUser = user;
break;
}
Expand Down
Loading

0 comments on commit 42ea26f

Please sign in to comment.