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

Feature/blocker comments #403

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add diff api, blockingComments api.
Jesper Utoft committed Nov 9, 2023
commit de308a33f9217b9421d2eb99b3a37fbb8b71130a
4 changes: 4 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java
Original file line number Diff line number Diff line change
@@ -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();

26 changes: 26 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/domain/commit/Diff.java
Original file line number Diff line number Diff line change
@@ -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<Error> errors, final Path source, final Path destination, final boolean truncated, final List<DiffHunk> 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<DiffHunk> hunks();
}
Original file line number Diff line number Diff line change
@@ -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<DiffHunkSegment> 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<DiffHunkSegment> segments();
}
Original file line number Diff line number Diff line change
@@ -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<DiffHunkSegmentLine> lines, final boolean truncated) {
return new AutoValue_DiffHunkSegment(type, lines, truncated);
}

/**
* @return "REMOVED", "ADDED", "CONTEXT", ?
*/
public abstract String type();

public abstract List<DiffHunkSegmentLine> lines();

public abstract boolean truncated();
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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<Error> errors, final String fromHash, final String toHash, final Integer contextLines, final String whitespace, final boolean truncated, final List<Diff> 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<Diff> diffs();
}
Original file line number Diff line number Diff line change
@@ -33,11 +33,11 @@ public abstract class BlockerCommentsPage implements Page<BlockerComments>, 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<BlockerComments> values,
@Nullable final List<Error> errors) {

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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<Object> {
@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<Object> {
@Override
public Object createOrPropagate(final Throwable throwable) throws Exception {
@@ -731,6 +742,10 @@ public static Commit createCommitFromErrors(final List<Error> errors) {
return Commit.create("-1", "-1", null, 0, null, 0, null,null, null, errors);
}

public static DiffPage createDiffPageFromErrors(final List<Error> errors) {
return DiffPage.create(errors, null, null, -1, null, false, null);
}

public static Tag createTagFromErrors(final List<Error> errors) {
return Tag.create(null, null, null, null, null, null, errors);
}
36 changes: 35 additions & 1 deletion src/main/java/com/cdancy/bitbucket/rest/features/CommitsApi.java
Original file line number Diff line number Diff line change
@@ -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);
}
Loading