From 9ea6330477e2b0df03bcd8dc846559897e54e8e7 Mon Sep 17 00:00:00 2001 From: Jesper Utoft Date: Thu, 9 Nov 2023 12:06:21 +0100 Subject: [PATCH 1/4] Initial support for blocking comments api. --- .../rest/domain/comment/BlockerComments.java | 81 +++++++++++++++++++ .../pullrequest/BlockerCommentsPage.java | 52 ++++++++++++ .../rest/fallbacks/BitbucketFallbacks.java | 10 +++ .../rest/features/PullRequestApi.java | 22 ++++- 4 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/comment/BlockerComments.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/BlockerCommentsPage.java diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/comment/BlockerComments.java b/src/main/java/com/cdancy/bitbucket/rest/domain/comment/BlockerComments.java new file mode 100644 index 000000000..a438497e4 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/comment/BlockerComments.java @@ -0,0 +1,81 @@ +package com.cdancy.bitbucket.rest.domain.comment; + +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.pullrequest.Author; +import com.google.auto.value.AutoValue; +import com.google.gson.JsonElement; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +import java.util.List; +import java.util.Map; + +@AutoValue +public abstract class BlockerComments implements ErrorsHolder { + public enum BlockingCommentState { + OPEN, + PENDING, + RESOLVED + } + + public abstract Map properties(); + + public abstract int id(); + + public abstract int version(); + + @Nullable + public abstract String text(); + + @Nullable + public abstract Author author(); + + public abstract long createdDate(); + + public abstract long updatedDate(); + public abstract boolean threadResolved(); + public abstract String severity(); + public abstract BlockingCommentState state(); + + @Nullable + public abstract PermittedOperations permittedOperations(); + + @Nullable + public abstract Author resolver(); + + BlockerComments() { + } + + @SerializedNames({ "properties", "id", "version", "text", "author", + "createdDate", "updatedDate", "resolver", "threadResolved", "state", "severity", "permittedOperations", "errors" }) + public static BlockerComments create(final Map properties, + final int id, + final int version, + final String text, + final Author author, + final long createdDate, + final long updatedDate, + final Author resolver, + final Boolean threadResolved, + final BlockingCommentState state, + final String severity, + final PermittedOperations permittedOperations, + final List errors) { + + return new AutoValue_BlockerComments(BitbucketUtils.nullToEmpty(errors), + BitbucketUtils.nullToEmpty(properties), + id, + version, + text, + author, + createdDate, + updatedDate, + threadResolved, + severity, + state, + permittedOperations, + resolver); + } +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/BlockerCommentsPage.java b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/BlockerCommentsPage.java new file mode 100644 index 000000000..b54622f65 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/BlockerCommentsPage.java @@ -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.domain.pullrequest; + +import com.cdancy.bitbucket.rest.BitbucketUtils; +import com.cdancy.bitbucket.rest.domain.comment.BlockerComments; +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 BlockerCommentsPage implements Page, ErrorsHolder { + + @SerializedNames({ "start", "limit", "size", + "nextPageStart", "isLastPage", "values", "errors" }) + public static BlockerCommentsPage create(@Nullable final Integer start, + @Nullable final Integer limit, + @Nullable final Integer size, + @Nullable final Integer nextPageStart, + @Nullable final Boolean isLastPage, + @Nullable final List values, + @Nullable final List errors) { + + return new AutoValue_BlockerCommentsPage(start, + limit, + size, + nextPageStart, + isLastPage, + BitbucketUtils.nullToEmpty(values), + BitbucketUtils.nullToEmpty(errors)); + } +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java b/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java index 2536f3b3a..7b6c8be4b 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java +++ b/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java @@ -453,6 +453,16 @@ public Object createOrPropagate(final Throwable throwable) throws Exception { } } + public static final class BlockerCommentsPageOnError implements Fallback { + @Override + public Object createOrPropagate(final Throwable throwable) throws Exception { + if (checkNotNull(throwable, "throwable") != null) { + return createActivitiesPageFromErrors(getErrors(throwable.getMessage())); + } + throw propagate(throwable); + } + } + public static final class ParticipantsPageOnError implements Fallback { @Override public Object createOrPropagate(final Throwable throwable) throws Exception { diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java index 3e56e0fca..c1d2ab02a 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java @@ -29,13 +29,11 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import com.cdancy.bitbucket.rest.domain.comment.BlockerComments; import com.cdancy.bitbucket.rest.domain.participants.Participants; import com.cdancy.bitbucket.rest.domain.participants.ParticipantsPage; import com.cdancy.bitbucket.rest.domain.activities.ActivitiesPage; -import com.cdancy.bitbucket.rest.domain.pullrequest.ChangePage; -import com.cdancy.bitbucket.rest.domain.pullrequest.MergeStatus; -import com.cdancy.bitbucket.rest.domain.pullrequest.PullRequest; -import com.cdancy.bitbucket.rest.domain.pullrequest.PullRequestPage; +import com.cdancy.bitbucket.rest.domain.pullrequest.*; import com.cdancy.bitbucket.rest.options.CreateParticipants; import com.cdancy.bitbucket.rest.options.EditPullRequest; import org.jclouds.javax.annotation.Nullable; @@ -63,6 +61,8 @@ import com.cdancy.bitbucket.rest.parsers.RequestStatusParser; import org.jclouds.rest.annotations.ResponseParser; +import java.util.List; + @Produces(MediaType.APPLICATION_JSON) @RequestFilters(BitbucketAuthenticationFilter.class) @Path("/rest/api/{jclouds.api-version}/projects") @@ -211,6 +211,20 @@ ActivitiesPage listActivities(@PathParam("project") String project, @Nullable @QueryParam("limit") Integer limit, @Nullable @QueryParam("start") Integer start); + @Named("pull-request:list-blocker-comments") + @Documentation({"https://developer.atlassian.com/server/bitbucket/rest/v815/api-group-pull-requests/#api-api-latest-projects-projectkey-repos-repositoryslug-pull-requests-pullrequestid-blocker-comments-get"}) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/{project}/repos/{repo}/pull-requests/{pullRequestId}/blocker-comments") + @Fallback(BitbucketFallbacks.BlockerCommentsPageOnError.class) + @GET + BlockerCommentsPage listBlockerComments(@PathParam("project") String project, + @PathParam("repo") String repo, + @PathParam("pullRequestId") long pullRequestId, + @Nullable @QueryParam("limit") Integer limit, + @Nullable @QueryParam("start") Integer start, +// @Nullable @QueryParam("count") Boolean count, + @Nullable @QueryParam("state") List states); + @Named("pull-request:list-participants") @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm45627978405632"}) @Consumes(MediaType.APPLICATION_JSON) From de308a33f9217b9421d2eb99b3a37fbb8b71130a Mon Sep 17 00:00:00 2001 From: Jesper Utoft Date: Thu, 9 Nov 2023 16:48:25 +0100 Subject: [PATCH 2/4] Add diff api, blockingComments api. --- .../cdancy/bitbucket/rest/BitbucketApi.java | 4 ++ .../bitbucket/rest/domain/commit/Diff.java | 26 ++++++++++ .../rest/domain/commit/DiffHunk.java | 26 ++++++++++ .../rest/domain/commit/DiffHunkSegment.java | 23 +++++++++ .../domain/commit/DiffHunkSegmentLine.java | 20 ++++++++ .../rest/domain/commit/DiffPage.java | 29 +++++++++++ .../pullrequest/BlockerCommentsPage.java | 10 ++-- .../rest/domain/pullrequest/Change.java | 49 ++++++++++--------- .../rest/domain/pullrequest/Conflict.java | 24 +++++++++ .../domain/pullrequest/ConflictChange.java | 41 ++++++++++++++++ .../rest/fallbacks/BitbucketFallbacks.java | 15 ++++++ .../bitbucket/rest/features/CommitsApi.java | 36 +++++++++++++- .../bitbucket/rest/features/CompareApi.java | 48 ++++++++++++++++++ 13 files changed, 323 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/commit/Diff.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunk.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunkSegment.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunkSegmentLine.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffPage.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/Conflict.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/ConflictChange.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/features/CompareApi.java diff --git a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java index 38e86c4e3..5f4b46358 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java @@ -24,6 +24,7 @@ import com.cdancy.bitbucket.rest.features.BuildStatusApi; import com.cdancy.bitbucket.rest.features.CommentsApi; import com.cdancy.bitbucket.rest.features.CommitsApi; +import com.cdancy.bitbucket.rest.features.CompareApi; import com.cdancy.bitbucket.rest.features.DefaultReviewersApi; import com.cdancy.bitbucket.rest.features.FileApi; import com.cdancy.bitbucket.rest.features.HookApi; @@ -54,6 +55,9 @@ public interface BitbucketApi extends Closeable { @Delegate BuildStatusApi buildStatusApi(); + @Delegate + CompareApi compareApi(); + @Delegate CommentsApi commentsApi(); diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/commit/Diff.java b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/Diff.java new file mode 100644 index 000000000..48873873b --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/Diff.java @@ -0,0 +1,26 @@ +package com.cdancy.bitbucket.rest.domain.commit; + +import com.cdancy.bitbucket.rest.domain.common.Error; +import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder; +import com.cdancy.bitbucket.rest.domain.pullrequest.Path; +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 Diff implements ErrorsHolder { + @SerializedNames({"errors", "source", "destination", "truncated", "hunks"}) + public static Diff create(@Nullable final List errors, final Path source, final Path destination, final boolean truncated, final List hunks) { + return new AutoValue_Diff(errors, source, destination, truncated, hunks); + } + + public abstract Path source(); + + public abstract Path destination(); + + public abstract boolean truncated(); + + public abstract List hunks(); +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunk.java b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunk.java new file mode 100644 index 000000000..7cbc4ab35 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunk.java @@ -0,0 +1,26 @@ +package com.cdancy.bitbucket.rest.domain.commit; + +import com.google.auto.value.AutoValue; +import org.jclouds.json.SerializedNames; + +import java.util.List; + +@AutoValue +public abstract class DiffHunk { + @SerializedNames({"sourceLine", "sourceSpan", "destinationLine", "destinationSpan", "truncated", "segments"}) + public static DiffHunk create(final Integer sourceLine, final Integer sourceSpan, final Integer destinationLine, final Integer destinationSpan, final boolean truncated, final List segments) { + return new AutoValue_DiffHunk(sourceLine, sourceSpan, destinationLine, destinationSpan, truncated, segments); + } + + public abstract Integer sourceLine(); + + public abstract Integer sourceSpan(); + + public abstract Integer destinationLine(); + + public abstract Integer destinationSpan(); + + public abstract boolean truncated(); + + public abstract List segments(); +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunkSegment.java b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunkSegment.java new file mode 100644 index 000000000..e7f5c9dcf --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunkSegment.java @@ -0,0 +1,23 @@ +package com.cdancy.bitbucket.rest.domain.commit; + +import com.google.auto.value.AutoValue; +import org.jclouds.json.SerializedNames; + +import java.util.List; + +@AutoValue +public abstract class DiffHunkSegment { + @SerializedNames({"type", "lines", "truncated"}) + public static DiffHunkSegment create(final String type, final List lines, final boolean truncated) { + return new AutoValue_DiffHunkSegment(type, lines, truncated); + } + + /** + * @return "REMOVED", "ADDED", "CONTEXT", ? + */ + public abstract String type(); + + public abstract List lines(); + + public abstract boolean truncated(); +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunkSegmentLine.java b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunkSegmentLine.java new file mode 100644 index 000000000..bd6c4da43 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffHunkSegmentLine.java @@ -0,0 +1,20 @@ +package com.cdancy.bitbucket.rest.domain.commit; + +import com.google.auto.value.AutoValue; +import org.jclouds.json.SerializedNames; + +@AutoValue +public abstract class DiffHunkSegmentLine { + @SerializedNames({"source", "destination", "line", "truncated"}) + public static DiffHunkSegmentLine create(final Integer source, final Integer destination, final String line, final boolean truncated) { + return new AutoValue_DiffHunkSegmentLine(source, destination, line, truncated); + } + + public abstract Integer source(); + + public abstract Integer destination(); + + public abstract String line(); + + public abstract boolean truncated(); +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffPage.java b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffPage.java new file mode 100644 index 000000000..badbf6634 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/commit/DiffPage.java @@ -0,0 +1,29 @@ +package com.cdancy.bitbucket.rest.domain.commit; + +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.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +import java.util.List; + +@AutoValue +public abstract class DiffPage implements ErrorsHolder { + @SerializedNames({"errors", "fromHash", "toHash", "contextLines", "whitespace", "truncated", "diffs"}) + public static DiffPage create(@Nullable final List errors, final String fromHash, final String toHash, final Integer contextLines, final String whitespace, final boolean truncated, final List diffs) { + return new AutoValue_DiffPage(errors, fromHash, toHash, contextLines, whitespace, truncated, diffs); + } + + public abstract String fromHash(); + + public abstract String toHash(); + + public abstract Integer contextLines(); + + public abstract String whitespace(); + + public abstract boolean truncated(); + + public abstract List diffs(); +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/BlockerCommentsPage.java b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/BlockerCommentsPage.java index b54622f65..2ddb10d18 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/BlockerCommentsPage.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/BlockerCommentsPage.java @@ -33,11 +33,11 @@ public abstract class BlockerCommentsPage implements Page, Erro @SerializedNames({ "start", "limit", "size", "nextPageStart", "isLastPage", "values", "errors" }) - public static BlockerCommentsPage create(@Nullable final Integer start, - @Nullable final Integer limit, - @Nullable final Integer size, - @Nullable final Integer nextPageStart, - @Nullable final Boolean isLastPage, + public static BlockerCommentsPage create(@Nullable final int start, + @Nullable final int limit, + @Nullable final int size, + @Nullable final int nextPageStart, + @Nullable final boolean isLastPage, @Nullable final List values, @Nullable final List errors) { diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/Change.java b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/Change.java index 3c6aeb8e2..cc37162bf 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/Change.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/Change.java @@ -49,33 +49,38 @@ public abstract class Change implements LinksHolder { public abstract boolean srcExecutable(); + @Nullable + public abstract Conflict conflict(); + Change() { } - @SerializedNames({ "contentId", "fromContentId", "path", - "executable", "percentUnchanged", "type", - "nodeType", "srcPath", "srcExecutable", - "links" }) - public static Change create(final String contentId, - final String fromContentId, - final Path path, + @SerializedNames({ "contentId", "fromContentId", "path", + "executable", "percentUnchanged", "type", + "nodeType", "srcPath", "srcExecutable", + "links", "conflict" }) + public static Change create(final String contentId, + final String fromContentId, + final Path path, final boolean executable, - final int percentUnchanged, - final String type, - final String nodeType, + final int percentUnchanged, + final String type, + final String nodeType, final Path srcPath, - final boolean srcExecutable, - final Links links) { - - return new AutoValue_Change(links, - contentId, - fromContentId, - path, + final boolean srcExecutable, + final Links links, + final Conflict conflict) { + + return new AutoValue_Change(links, + contentId, + fromContentId, + path, executable, - percentUnchanged, - type, - nodeType, - srcPath, - srcExecutable); + percentUnchanged, + type, + nodeType, + srcPath, + srcExecutable, + conflict); } } diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/Conflict.java b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/Conflict.java new file mode 100644 index 000000000..41f95f4af --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/Conflict.java @@ -0,0 +1,24 @@ +package com.cdancy.bitbucket.rest.domain.pullrequest; + +import com.google.auto.value.AutoValue; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +@AutoValue +public abstract class Conflict { + @Nullable + public abstract ConflictChange ourChange(); + + @Nullable + public abstract ConflictChange theirChange(); + + Conflict() { + } + + @SerializedNames({ "ourChange", "theirChange" }) + public static Conflict create(final ConflictChange ourChange, + final ConflictChange theirChange) { + + return new AutoValue_Conflict(ourChange, theirChange); + } +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/ConflictChange.java b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/ConflictChange.java new file mode 100644 index 000000000..b1673b772 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/ConflictChange.java @@ -0,0 +1,41 @@ +/* + * 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.pullrequest; + +import com.google.auto.value.AutoValue; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +@AutoValue +public abstract class ConflictChange { + + ConflictChange() { + } + + @SerializedNames({"path", "type"}) + public static ConflictChange create(final Path path, final String type) { + + return new AutoValue_ConflictChange(path, type); + } + + @Nullable + public abstract Path path(); + + @Nullable + public abstract String type(); +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java b/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java index 7b6c8be4b..aafae6d7b 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java +++ b/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java @@ -31,6 +31,7 @@ import com.cdancy.bitbucket.rest.domain.comment.Task; import com.cdancy.bitbucket.rest.domain.commit.Commit; import com.cdancy.bitbucket.rest.domain.commit.CommitPage; +import com.cdancy.bitbucket.rest.domain.commit.DiffPage; import com.cdancy.bitbucket.rest.domain.common.Error; import com.cdancy.bitbucket.rest.domain.common.RequestStatus; import com.cdancy.bitbucket.rest.domain.common.Veto; @@ -248,6 +249,16 @@ public Object createOrPropagate(final Throwable throwable) throws Exception { } } + public static final class DiffPageOnError implements Fallback { + @Override + public Object createOrPropagate(final Throwable throwable) throws Exception { + if (checkNotNull(throwable, "throwable") != null) { + return createDiffPageFromErrors(getErrors(throwable.getMessage())); + } + throw propagate(throwable); + } + } + public static final class TagOnError implements Fallback { @Override public Object createOrPropagate(final Throwable throwable) throws Exception { @@ -731,6 +742,10 @@ public static Commit createCommitFromErrors(final List errors) { return Commit.create("-1", "-1", null, 0, null, 0, null,null, null, errors); } + public static DiffPage createDiffPageFromErrors(final List errors) { + return DiffPage.create(errors, null, null, -1, null, false, null); + } + public static Tag createTagFromErrors(final List errors) { return Tag.create(null, null, null, null, null, null, errors); } diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/CommitsApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/CommitsApi.java index fcf020bea..df446ca2d 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/CommitsApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/CommitsApi.java @@ -20,7 +20,9 @@ import com.cdancy.bitbucket.rest.annotations.Documentation; import com.cdancy.bitbucket.rest.domain.commit.Commit; import com.cdancy.bitbucket.rest.domain.commit.CommitPage; +import com.cdancy.bitbucket.rest.domain.commit.DiffPage; import com.cdancy.bitbucket.rest.domain.pullrequest.ChangePage; +import com.cdancy.bitbucket.rest.domain.pullrequest.PullRequestPage; import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks; import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; import org.jclouds.rest.annotations.Fallback; @@ -65,7 +67,7 @@ ChangePage listChanges(@PathParam("project") String project, @PathParam("commitId") String commitId, @Nullable @QueryParam("limit") Integer limit, @Nullable @QueryParam("start") Integer start); - + @Named("commits:list") @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm140236729804608"}) @Consumes(MediaType.APPLICATION_JSON) @@ -83,4 +85,36 @@ CommitPage list(@PathParam("project") String project, @Nullable @QueryParam("until") String until, @Nullable @QueryParam("limit") Integer limit, @Nullable @QueryParam("start") Integer start); + + @Named("commits:pullrequests") + @Documentation({"https://docs.atlassian.com/bitbucket-server/rest/7.21.0/bitbucket-rest.html#idp251"}) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/{project}/repos/{repo}/commits/{commitId}/pull-requests") + @Fallback(BitbucketFallbacks.PullRequestPageOnError.class) + @GET + PullRequestPage pullRequests(@PathParam("project") String project, + @PathParam("repo") String repo, + @PathParam("commitId") String commitId, + @Nullable @QueryParam("limit") Integer limit, + @Nullable @QueryParam("start") Integer start); + + @Named("commits:diff") + @Documentation({"https://docs.atlassian.com/bitbucket-server/rest/7.21.0/bitbucket-rest.html#idp248"}) + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/{project}/repos/{repo}/commits/{commitId}/diff/{path}") + @Fallback(BitbucketFallbacks.DiffPageOnError.class) + @GET + DiffPage diffCommits(@PathParam("project") String project, + @PathParam("repo") String repo, + @PathParam("commitId") String commitId, + @PathParam("path") String path, + @Nullable @QueryParam("autoSrcPath") Boolean autoSrcPath, + @Nullable @QueryParam("contextLines") Integer contextLines, + @Nullable @QueryParam("since") String since, + @Nullable @QueryParam("srcPath") String srcPath, + @Nullable @QueryParam("whitespace") String whitespace, + @Nullable @QueryParam("withComments") Boolean withComments, + @Nullable @QueryParam("avatarSize") String avatarSize, + @Nullable @QueryParam("avatarScheme") String avatarScheme); } diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/CompareApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/CompareApi.java new file mode 100644 index 000000000..68c621063 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/features/CompareApi.java @@ -0,0 +1,48 @@ +package com.cdancy.bitbucket.rest.features; + +import com.cdancy.bitbucket.rest.annotations.Documentation; +import com.cdancy.bitbucket.rest.domain.commit.CommitPage; +import com.cdancy.bitbucket.rest.domain.pullrequest.ChangePage; +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.*; +import javax.ws.rs.core.MediaType; + +@Produces(MediaType.APPLICATION_JSON) +@RequestFilters(BitbucketAuthenticationFilter.class) +@Path("/rest") +@SuppressWarnings("PMD.AvoidDuplicateLiterals") +public interface CompareApi { + @Named("compare:changes") + @Documentation({"https://docs.atlassian.com/bitbucket-server/rest/7.21.0/bitbucket-rest.html#idp257"}) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/api/{jclouds.api-version}/projects/{project}/repos/{repo}/compare/changes") + @Fallback(BitbucketFallbacks.ChangePageOnError.class) + @GET + ChangePage changes(@PathParam("project") String project, + @PathParam("repo") String repo, + @Nullable @QueryParam("from") String fromRef, + @Nullable @QueryParam("to") String toRef, + @Nullable @QueryParam("fromRepo") String fromRepo, + @Nullable @QueryParam("limit") Integer limit, + @Nullable @QueryParam("start") Integer start); + + @Named("compare:commits") + @Documentation({"https://docs.atlassian.com/bitbucket-server/rest/7.21.0/bitbucket-rest.html#idp259"}) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/api/{jclouds.api-version}/projects/{project}/repos/{repo}/compare/commits") + @Fallback(BitbucketFallbacks.CommitPageOnError.class) + @GET + CommitPage commits(@PathParam("project") String project, + @PathParam("repo") String repo, + @Nullable @QueryParam("from") String fromRef, + @Nullable @QueryParam("to") String toRef, + @Nullable @QueryParam("fromRepo") String fromRepo, + @Nullable @QueryParam("limit") Integer limit, + @Nullable @QueryParam("start") Integer start); +} From c30f2a2dd09f54266a6b360a1c21a1cc8338dd5f Mon Sep 17 00:00:00 2001 From: Jesper Utoft Date: Fri, 10 Nov 2023 09:38:57 +0100 Subject: [PATCH 3/4] add comments update command --- .../cdancy/bitbucket/rest/BitbucketApi.java | 1 + .../rest/domain/comment/BlockerComments.java | 14 +--- .../rest/domain/comment/Comments.java | 63 +++++++++----- .../rest/fallbacks/BitbucketFallbacks.java | 2 +- .../bitbucket/rest/features/CommentsApi.java | 24 ++++-- .../rest/features/PullRequestApi.java | 15 +++- .../bitbucket/rest/features/TasksApi.java | 8 +- .../bitbucket/rest/options/CreateComment.java | 15 +++- .../bitbucket/rest/options/UpdateComment.java | 56 +++++++++++++ .../rest/features/CommentsApiLiveTest.java | 38 ++++----- .../rest/features/CommentsApiMockTest.java | 10 +-- .../rest/features/PullRequestApiMockTest.java | 8 +- .../resources/pull-request-activities.json | 82 +------------------ 13 files changed, 179 insertions(+), 157 deletions(-) create mode 100644 src/main/java/com/cdancy/bitbucket/rest/options/UpdateComment.java diff --git a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java index 5f4b46358..0dfa9c00c 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java @@ -95,6 +95,7 @@ public interface BitbucketApi extends Closeable { TagApi tagApi(); @Delegate + @Deprecated TasksApi tasksApi(); @Delegate diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/comment/BlockerComments.java b/src/main/java/com/cdancy/bitbucket/rest/domain/comment/BlockerComments.java index a438497e4..f604ffb49 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/comment/BlockerComments.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/comment/BlockerComments.java @@ -14,12 +14,6 @@ @AutoValue public abstract class BlockerComments implements ErrorsHolder { - public enum BlockingCommentState { - OPEN, - PENDING, - RESOLVED - } - public abstract Map properties(); public abstract int id(); @@ -36,8 +30,8 @@ public enum BlockingCommentState { public abstract long updatedDate(); public abstract boolean threadResolved(); - public abstract String severity(); - public abstract BlockingCommentState state(); + public abstract Comments.Severity severity(); + public abstract Comments.TaskState state(); @Nullable public abstract PermittedOperations permittedOperations(); @@ -59,8 +53,8 @@ public static BlockerComments create(final Map properties, final long updatedDate, final Author resolver, final Boolean threadResolved, - final BlockingCommentState state, - final String severity, + final Comments.TaskState state, + final Comments.Severity severity, final PermittedOperations permittedOperations, final List errors) { diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/comment/Comments.java b/src/main/java/com/cdancy/bitbucket/rest/domain/comment/Comments.java index 7bbfde284..81f4639ea 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/comment/Comments.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/comment/Comments.java @@ -34,6 +34,16 @@ @AutoValue public abstract class Comments implements ErrorsHolder, LinksHolder { + public enum Severity { + NORMAL, + BLOCKER + } + + public enum TaskState { + OPEN, + PENDING, + RESOLVED + } public abstract Map properties(); @@ -51,24 +61,35 @@ public abstract class Comments implements ErrorsHolder, LinksHolder { public abstract long updatedDate(); + /** + * Not defined for activities + * @return + */ + @Nullable + public abstract Severity severity(); + /** + * Not defined for activities + * @return + */ + @Nullable + public abstract TaskState state(); + public abstract List comments(); - - public abstract List tasks(); - + @Nullable public abstract Anchor anchor(); - + @Nullable public abstract Link link(); @Nullable public abstract PermittedOperations permittedOperations(); - + Comments() { } @SerializedNames({ "properties", "id", "version", "text", "author", - "createdDate", "updatedDate", "comments", "tasks", "anchor", "link", "links", + "createdDate", "updatedDate", "comments", "severity", "state", "anchor", "link", "links", "permittedOperations", "errors" }) public static Comments create(final Map properties, final int id, @@ -78,26 +99,28 @@ public static Comments create(final Map properties, final long createdDate, final long updatedDate, final List comments, - final List tasks, + final Severity severity, + final TaskState state, final Anchor anchor, final Link link, final Links links, final PermittedOperations permittedOperations, final List errors) { - - return new AutoValue_Comments(BitbucketUtils.nullToEmpty(errors), - links, + + return new AutoValue_Comments(BitbucketUtils.nullToEmpty(errors), + links, BitbucketUtils.nullToEmpty(properties), - id, - version, - text, - author, - createdDate, - updatedDate, - BitbucketUtils.nullToEmpty(comments), - BitbucketUtils.nullToEmpty(tasks), - anchor, - link, + id, + version, + text, + author, + createdDate, + updatedDate, + severity, + state, + BitbucketUtils.nullToEmpty(comments), + anchor, + link, permittedOperations); } } diff --git a/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java b/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java index aafae6d7b..f6bb2a8a0 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java +++ b/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java @@ -727,7 +727,7 @@ public static ChangePage createChangePageFromErrors(final List errors) { } public static Comments createCommentsFromErrors(final List errors) { - return Comments.create(null, 0, 0, null, null, 0, 0, null, null, null, null, null, null, errors); + return Comments.create(null, 0, 0, null, null, 0, 0, null, null, null, null, null, null, null, errors); } public static CommentPage createCommentPageFromErrors(final List errors) { diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/CommentsApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/CommentsApi.java index 1f1f59f24..c52cacaf6 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/CommentsApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/CommentsApi.java @@ -18,16 +18,10 @@ package com.cdancy.bitbucket.rest.features; import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -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.*; import javax.ws.rs.core.MediaType; +import com.cdancy.bitbucket.rest.options.UpdateComment; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.Payload; @@ -77,6 +71,18 @@ Comments create(@PathParam("project") String project, @PathParam("pullRequestId") int pullRequestId, @BinderParam(BindToJsonPayload.class) CreateComment createComment); + @Named("comments:create") + @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm45888278076336"}) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/{project}/repos/{repo}/pull-requests/{pullRequestId}/comments/{commentId}") + @Fallback(CommentsOnError.class) + @PUT + Comments update(@PathParam("project") String project, + @PathParam("repo") String repo, + @PathParam("pullRequestId") int pullRequestId, + @PathParam("commentId") int commentId, + @BinderParam(BindToJsonPayload.class) UpdateComment updateComment); + @Named("comments:get") @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm45888278070112"}) @Consumes(MediaType.APPLICATION_JSON) @@ -101,7 +107,7 @@ CommentPage fileComments(@PathParam("project") String project, @QueryParam("path") String pathToFile, @Nullable @QueryParam("start") Integer start, @Nullable @QueryParam("limit") Integer limit); - + @Named("comments:file-comments") @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm45888278617264"}) @Consumes(MediaType.APPLICATION_JSON) diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java index c1d2ab02a..d34620332 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java @@ -30,6 +30,7 @@ import javax.ws.rs.core.MediaType; import com.cdancy.bitbucket.rest.domain.comment.BlockerComments; +import com.cdancy.bitbucket.rest.domain.comment.Comments; import com.cdancy.bitbucket.rest.domain.participants.Participants; import com.cdancy.bitbucket.rest.domain.participants.ParticipantsPage; import com.cdancy.bitbucket.rest.domain.activities.ActivitiesPage; @@ -211,6 +212,18 @@ ActivitiesPage listActivities(@PathParam("project") String project, @Nullable @QueryParam("limit") Integer limit, @Nullable @QueryParam("start") Integer start); + @Named("pull-request:list-comments") + @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm45888278197104"}) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/{project}/repos/{repo}/pull-requests/{pullRequestId}/comments") + @Fallback(BitbucketFallbacks.CommentPageOnError.class) + @GET + CommentPage listComments(@PathParam("project") String project, + @PathParam("repo") String repo, + @PathParam("pullRequestId") long pullRequestId, + @Nullable @QueryParam("limit") Integer limit, + @Nullable @QueryParam("start") Integer start); + @Named("pull-request:list-blocker-comments") @Documentation({"https://developer.atlassian.com/server/bitbucket/rest/v815/api-group-pull-requests/#api-api-latest-projects-projectkey-repos-repositoryslug-pull-requests-pullrequestid-blocker-comments-get"}) @Consumes(MediaType.APPLICATION_JSON) @@ -223,7 +236,7 @@ BlockerCommentsPage listBlockerComments(@PathParam("project") String project, @Nullable @QueryParam("limit") Integer limit, @Nullable @QueryParam("start") Integer start, // @Nullable @QueryParam("count") Boolean count, - @Nullable @QueryParam("state") List states); + @Nullable @QueryParam("state") List states); @Named("pull-request:list-participants") @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm45627978405632"}) diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/TasksApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/TasksApi.java index 93f7c5afa..201c3e318 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/TasksApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/TasksApi.java @@ -53,6 +53,7 @@ public interface TasksApi { @Consumes(MediaType.APPLICATION_JSON) @Fallback(BitbucketFallbacks.TaskOnError.class) @POST + @Deprecated Task create(@BinderParam(BindToJsonPayload.class) CreateTask createTask); @Named("tasks:update") @@ -62,8 +63,9 @@ public interface TasksApi { @Fallback(BitbucketFallbacks.TaskOnError.class) @Payload("%7B \"state\": \"{state}\" %7D") @PUT + @Deprecated Task update(@PathParam("taskId") int taskId, @PayloadParam("state") String state); - + @Named("tasks:get") @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm45701777641664"}) @@ -71,8 +73,9 @@ public interface TasksApi { @Path("/{taskId}") @Fallback(BitbucketFallbacks.TaskOnError.class) @GET + @Deprecated Task get(@PathParam("taskId") int taskId); - + @Named("tasks:delete") @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm45701777664960"}) @Consumes(MediaType.APPLICATION_JSON) @@ -80,5 +83,6 @@ public interface TasksApi { @Fallback(BitbucketFallbacks.RequestStatusOnError.class) @ResponseParser(RequestStatusParser.class) @DELETE + @Deprecated RequestStatus delete(@PathParam("taskId") int taskId); } diff --git a/src/main/java/com/cdancy/bitbucket/rest/options/CreateComment.java b/src/main/java/com/cdancy/bitbucket/rest/options/CreateComment.java index bc2e41a09..e18c571fa 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/options/CreateComment.java +++ b/src/main/java/com/cdancy/bitbucket/rest/options/CreateComment.java @@ -18,6 +18,7 @@ package com.cdancy.bitbucket.rest.options; import com.cdancy.bitbucket.rest.domain.comment.Anchor; +import com.cdancy.bitbucket.rest.domain.comment.Comments; import com.cdancy.bitbucket.rest.domain.comment.Parent; import com.google.auto.value.AutoValue; import org.jclouds.javax.annotation.Nullable; @@ -34,13 +35,21 @@ public abstract class CreateComment { @Nullable public abstract Anchor anchor(); + @Nullable + public abstract Comments.Severity severity(); + + @Nullable + public abstract Comments.TaskState state(); + CreateComment() { } - @SerializedNames({ "text", "parent", "anchor" }) + @SerializedNames({ "text", "parent", "anchor", "severity", "state" }) public static CreateComment create(final String text, final Parent parent, - final Anchor anchor) { - return new AutoValue_CreateComment(text, parent, anchor); + final Anchor anchor, + final Comments.Severity severity, + final Comments.TaskState state) { + return new AutoValue_CreateComment(text, parent, anchor, severity, state); } } diff --git a/src/main/java/com/cdancy/bitbucket/rest/options/UpdateComment.java b/src/main/java/com/cdancy/bitbucket/rest/options/UpdateComment.java new file mode 100644 index 000000000..2af5253c0 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/options/UpdateComment.java @@ -0,0 +1,56 @@ +/* + * 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.cdancy.bitbucket.rest.domain.comment.Anchor; +import com.cdancy.bitbucket.rest.domain.comment.BlockerComments; +import com.cdancy.bitbucket.rest.domain.comment.Comments; +import com.cdancy.bitbucket.rest.domain.comment.Parent; +import com.google.auto.value.AutoValue; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +@AutoValue +public abstract class UpdateComment { + + @Nullable + public abstract String text(); + + @Nullable + public abstract Parent parent(); + + @Nullable + public abstract Anchor anchor(); + + @Nullable + public abstract Comments.Severity severity(); + + @Nullable + public abstract Comments.TaskState state(); + UpdateComment() { + } + + @SerializedNames({ "text", "parent", "anchor", "severity", "state" }) + public static UpdateComment create(final String text, + final Parent parent, + final Anchor anchor, + final Comments.Severity severity, + final Comments.TaskState state) { + return new AutoValue_UpdateComment(text, parent, anchor, severity, state); + } +} diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/CommentsApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/CommentsApiLiveTest.java index 04173f627..b8d424535 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/CommentsApiLiveTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/CommentsApiLiveTest.java @@ -53,7 +53,7 @@ public class CommentsApiLiveTest extends BaseBitbucketApiLiveTest { private String filePath; private final String commentText = TestUtilities.randomString(); private final String commentReplyText = TestUtilities.randomString(); - + private int prId = -1; private int commentId = -1; private int commentReplyId = -1; @@ -64,12 +64,12 @@ public void init() { generatedTestContents = TestUtilities.initGeneratedTestContents(this.endpoint, this.bitbucketAuthentication, this.api); this.project = generatedTestContents.project.key(); this.repo = generatedTestContents.repository.name(); - + final BranchPage branchPage = api.branchApi().list(project, repo, null, null, null, null, null, null); assertThat(branchPage).isNotNull(); assertThat(branchPage.errors().isEmpty()).isTrue(); assertThat(branchPage.values().size()).isEqualTo(2); - + String branchToMerge = null; for (final Branch branch : branchPage.values()) { if (!branch.id().endsWith("master")) { @@ -78,7 +78,7 @@ public void init() { } } assertThat(branchToMerge).isNotNull(); - + final String randomChars = TestUtilities.randomString(); final ProjectKey proj = ProjectKey.create(project); final MinimalRepository repository = MinimalRepository.create(repo, null, proj); @@ -86,13 +86,13 @@ public void init() { final Reference toRef = Reference.create(null, repository); final CreatePullRequest cpr = CreatePullRequest.create(randomChars, "Fix for issue " + randomChars, fromRef, toRef, null, null); final PullRequest pr = api.pullRequestApi().create(project, repo, cpr); - + assertThat(pr).isNotNull(); assertThat(project).isEqualTo(pr.fromRef().repository().project().key()); assertThat(repo).isEqualTo(pr.fromRef().repository().name()); prId = pr.id(); } - + @Test public void testComment() { final Comments comm = api().comment(project, repo, prId, commentText); @@ -105,7 +105,7 @@ public void testComment() { @Test (dependsOnMethods = "testComment") public void testCreateComment() { final Parent parent = Parent.create(commentId); - final CreateComment createComment = CreateComment.create(commentReplyText, parent, null); + final CreateComment createComment = CreateComment.create(commentReplyText, parent, null, null, null); final Comments comm = api().create(project, repo, prId, createComment); assertThat(comm).isNotNull(); @@ -114,7 +114,7 @@ public void testCreateComment() { commentReplyId = comm.id(); commentReplyIdVersion = comm.version(); } - + @Test (dependsOnMethods = "testCreateComment") public void testGetComment() { final Comments comm = api().get(project, repo, prId, commentReplyId); @@ -122,34 +122,34 @@ public void testGetComment() { assertThat(comm.errors().isEmpty()).isTrue(); assertThat(comm.text().equals(commentReplyText)).isTrue(); } - + @Test (dependsOnMethods = "testGetComment") public void testCreateInlineComment() { - + final ChangePage changePage = api.pullRequestApi().changes(project, repo, prId, null, null, null); assertThat(changePage).isNotNull(); assertThat(changePage.errors().isEmpty()).isTrue(); assertThat(changePage.values().size()).isEqualTo(1); final Change change = changePage.values().get(0); this.filePath = change.path()._toString(); - - final Anchor anchor = Anchor.create(1, Anchor.LineType.CONTEXT, - Anchor.FileType.FROM, - this.filePath, + + final Anchor anchor = Anchor.create(1, Anchor.LineType.CONTEXT, + Anchor.FileType.FROM, + this.filePath, this.filePath); - + final String randomText = TestUtilities.randomString(); - final CreateComment createComment = CreateComment.create(randomText, null, anchor); + final CreateComment createComment = CreateComment.create(randomText, null, anchor, null, null); final Comments comm = api().create(project, repo, prId, createComment); assertThat(comm).isNotNull(); assertThat(comm.errors().isEmpty()).isTrue(); assertThat(comm.text()).isEqualTo(randomText); } - + @Test (dependsOnMethods = "testCreateInlineComment") public void testGetFileCommentPage() throws Exception { - + final List allComments = Lists.newArrayList(); Integer start = null; while (true) { @@ -165,7 +165,7 @@ public void testGetFileCommentPage() throws Exception { Thread.sleep(1000); } } - + assertThat(allComments.isEmpty()).isFalse(); boolean foundComment = false; for (final Comments comm : allComments) { diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/CommentsApiMockTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/CommentsApiMockTest.java index ccda1a268..cded03dc9 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/CommentsApiMockTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/CommentsApiMockTest.java @@ -75,7 +75,7 @@ public void testCreateComment() throws Exception { final Parent parent = Parent.create(1); final Anchor anchor = Anchor.create(1, Anchor.LineType.CONTEXT, Anchor.FileType.FROM, "path/to/file", "path/to/file"); - final CreateComment createComment = CreateComment.create(measuredReplyKeyword, parent, anchor); + final CreateComment createComment = CreateComment.create(measuredReplyKeyword, parent, anchor, null, null); final Comments pr = baseApi.commentsApi().create(projectKey, repoKey, 101, createComment); assertThat(pr).isNotNull(); assertThat(pr.errors()).isEmpty(); @@ -93,7 +93,7 @@ public void testGetComment() throws Exception { server.enqueue(new MockResponse().setBody(payloadFromResource("/comments.json")).setResponseCode(200)); try (final BitbucketApi baseApi = api(server.getUrl("/"))) { - + final Comments pr = baseApi.commentsApi().get(projectKey, repoKey, 101, 1); assertThat(pr).isNotNull(); assertThat(pr.errors()).isEmpty(); @@ -111,7 +111,7 @@ public void testGetCommentOnError() throws Exception { server.enqueue(new MockResponse().setBody(payloadFromResource("/commit-error.json")).setResponseCode(404)); try (final BitbucketApi baseApi = api(server.getUrl("/"))) { - + final Comments pr = baseApi.commentsApi().get(projectKey, repoKey, 101, 1); assertThat(pr).isNotNull(); assertThat(pr.errors()).isNotEmpty(); @@ -184,12 +184,12 @@ public void testDeleteComment() throws Exception { server.enqueue(new MockResponse().setResponseCode(204)); try (final BitbucketApi baseApi = api(server.getUrl("/"))) { - + final RequestStatus success = baseApi.commentsApi().delete(projectKey, repoKey, 101, 1, 1); assertThat(success).isNotNull(); assertThat(success.value()).isTrue(); assertThat(success.errors()).isEmpty(); - + final Map queryParams = ImmutableMap.of("version", 1); assertSent(server, "DELETE", restApiPath + BitbucketApiMetadata.API_VERSION + "/projects/PRJ/repos/my-repo/pull-requests/101/comments/1", queryParams); diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java index 08a673659..10c4e2d79 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java @@ -505,12 +505,8 @@ public void testGetPullRequestActivities() throws Exception { assertThat(comments.permittedOperations()).isNotNull(); assertThat(comments.permittedOperations().deletable()).isTrue(); assertThat(comments.permittedOperations().transitionable()).isFalse(); - assertThat(comments.tasks().size()).isEqualTo(1); - final Task task = comments.tasks().get(0); - assertThat(task.anchor().type()).isEqualTo("COMMENT"); - assertThat(task.state()).isEqualTo("OPEN"); - assertThat(task.anchor().properties().keySet().contains("likedBy")); - assertThat(task.anchor().properties().keySet().contains("repositoryId")); + assertThat(comments.severity()).isNotNull(); + assertThat(comments.state()).isNotNull(); final Map queryParams = ImmutableMap.of(startKeyword, "0", limitKeyword, 5); assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION diff --git a/src/test/resources/pull-request-activities.json b/src/test/resources/pull-request-activities.json index ec4b94452..8c2ccbe1d 100644 --- a/src/test/resources/pull-request-activities.json +++ b/src/test/resources/pull-request-activities.json @@ -95,87 +95,7 @@ "comments":[ ], - "tasks":[ - { - "anchor":{ - "properties":{ - "likedBy": { - "total": 1, - "likers": [ - { - "name": "example_user", - "emailAddress": "user@example.com", - "id": 1, - "displayName": "Example User", - "active": true, - "slug": "example_user", - "type": "NORMAL", - "links": { - "self": [ - { - "href": "http://git.public.io/users/example_user" - } - ] - } - } - ] - }, - "repositoryId":59 - }, - "id":1465, - "version":0, - "text":"fdasfdsa", - "author":{ - "name":"bear", - "emailAddress":"Hello.World@hotmail.com", - "id":2826, - "displayName":"Hello, World", - "active":true, - "slug":"bear", - "type":"NORMAL", - "links":{ - "self":[ - { - "href":"https://git.public.io/users/bear" - } - ] - } - }, - "createdDate":1499115191384, - "updatedDate":1499115191384, - "permittedOperations":{ - "editable":true, - "deletable":true - }, - "type":"COMMENT" - }, - "author":{ - "name":"bear", - "emailAddress":"Hello.World@hotmail.com", - "id":2826, - "displayName":"Hello, World", - "active":true, - "slug":"bear", - "type":"NORMAL", - "links":{ - "self":[ - { - "href":"https://git.public.io/users/bear" - } - ] - } - }, - "createdDate":1499115208000, - "id":1, - "text":"fdafda", - "state":"OPEN", - "permittedOperations":{ - "deletable":true, - "editable":true, - "transitionable":true - } - } - ], + "tasks":[], "permittedOperations":{ "editable":true, "deletable":true From 2371bf68c1960117628d0ece75662ad2d42e6fb0 Mon Sep 17 00:00:00 2001 From: Jesper Utoft Date: Tue, 21 Nov 2023 09:55:30 +0100 Subject: [PATCH 4/4] add version to comment update command. --- .../bitbucket/rest/features/PullRequestApi.java | 1 - .../cdancy/bitbucket/rest/options/UpdateComment.java | 11 +++++++---- .../rest/features/PullRequestApiMockTest.java | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java index d34620332..9b5037547 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/PullRequestApi.java @@ -29,7 +29,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import com.cdancy.bitbucket.rest.domain.comment.BlockerComments; import com.cdancy.bitbucket.rest.domain.comment.Comments; import com.cdancy.bitbucket.rest.domain.participants.Participants; import com.cdancy.bitbucket.rest.domain.participants.ParticipantsPage; diff --git a/src/main/java/com/cdancy/bitbucket/rest/options/UpdateComment.java b/src/main/java/com/cdancy/bitbucket/rest/options/UpdateComment.java index 2af5253c0..7805adf9e 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/options/UpdateComment.java +++ b/src/main/java/com/cdancy/bitbucket/rest/options/UpdateComment.java @@ -18,7 +18,6 @@ package com.cdancy.bitbucket.rest.options; import com.cdancy.bitbucket.rest.domain.comment.Anchor; -import com.cdancy.bitbucket.rest.domain.comment.BlockerComments; import com.cdancy.bitbucket.rest.domain.comment.Comments; import com.cdancy.bitbucket.rest.domain.comment.Parent; import com.google.auto.value.AutoValue; @@ -42,15 +41,19 @@ public abstract class UpdateComment { @Nullable public abstract Comments.TaskState state(); + + public abstract int version(); + UpdateComment() { } - @SerializedNames({ "text", "parent", "anchor", "severity", "state" }) + @SerializedNames({ "text", "parent", "anchor", "severity", "state", "version" }) public static UpdateComment create(final String text, final Parent parent, final Anchor anchor, final Comments.Severity severity, - final Comments.TaskState state) { - return new AutoValue_UpdateComment(text, parent, anchor, severity, state); + final Comments.TaskState state, + final int version) { + return new AutoValue_UpdateComment(text, parent, anchor, severity, state, version); } } diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java index 10c4e2d79..d873f90b6 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java @@ -40,7 +40,6 @@ import com.cdancy.bitbucket.rest.BitbucketApiMetadata; import com.cdancy.bitbucket.rest.domain.activities.Activities; import com.cdancy.bitbucket.rest.domain.comment.Comments; -import com.cdancy.bitbucket.rest.domain.comment.Task; import com.cdancy.bitbucket.rest.domain.commit.CommitPage; import com.cdancy.bitbucket.rest.domain.common.RequestStatus; import com.cdancy.bitbucket.rest.BaseBitbucketMockTest;