Skip to content

Commit 0e84b3f

Browse files
authored
Merge branch 'master' into fix/fix-breaking-change
2 parents 1520387 + ae3cb19 commit 0e84b3f

File tree

11 files changed

+365
-43
lines changed

11 files changed

+365
-43
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44

55
<artifactId>github-client</artifactId>
6-
<version>0.4.5-SNAPSHOT</version>
6+
<version>0.4.8-SNAPSHOT</version>
77

88
<parent>
99
<groupId>com.spotify</groupId>
@@ -67,7 +67,7 @@
6767
<properties>
6868
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6969
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
70-
<project.build.outputTimestamp>1745843688</project.build.outputTimestamp>
70+
<project.build.outputTimestamp>1749016319</project.build.outputTimestamp>
7171
<spotbugs.excludeFilterFile>spotbugsexclude.xml</spotbugs.excludeFilterFile>
7272
<checkstyle.violationSeverity>error</checkstyle.violationSeverity>
7373
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>

src/main/java/com/spotify/github/v3/clients/PullRequestClient.java

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,41 @@
2020

2121
package com.spotify.github.v3.clients;
2222

23-
import static com.spotify.github.v3.clients.GitHubClient.IGNORE_RESPONSE_CONSUMER;
24-
import static com.spotify.github.v3.clients.GitHubClient.LIST_COMMIT_TYPE_REFERENCE;
25-
import static com.spotify.github.v3.clients.GitHubClient.LIST_PR_TYPE_REFERENCE;
26-
import static com.spotify.github.v3.clients.GitHubClient.LIST_REVIEW_REQUEST_TYPE_REFERENCE;
27-
import static com.spotify.github.v3.clients.GitHubClient.LIST_REVIEW_TYPE_REFERENCE;
28-
import static java.util.Objects.isNull;
29-
30-
import com.google.common.base.Strings;
31-
import com.google.common.collect.ImmutableMap;
32-
import com.spotify.github.async.AsyncPage;
33-
import com.spotify.github.v3.prs.*;
34-
import com.spotify.github.v3.prs.requests.PullRequestCreate;
35-
import com.spotify.github.v3.prs.requests.PullRequestParameters;
36-
import com.spotify.github.v3.prs.requests.PullRequestUpdate;
37-
import com.spotify.github.v3.repos.CommitItem;
38-
3923
import java.io.InputStreamReader;
4024
import java.io.Reader;
4125
import java.lang.invoke.MethodHandles;
4226
import java.util.Iterator;
4327
import java.util.List;
4428
import java.util.Map;
29+
import static java.util.Objects.isNull;
4530
import java.util.concurrent.CompletableFuture;
31+
4632
import javax.ws.rs.core.HttpHeaders;
33+
4734
import org.slf4j.Logger;
4835
import org.slf4j.LoggerFactory;
4936

37+
import com.google.common.base.Strings;
38+
import com.google.common.collect.ImmutableMap;
39+
import com.spotify.github.async.AsyncPage;
40+
import static com.spotify.github.v3.clients.GitHubClient.IGNORE_RESPONSE_CONSUMER;
41+
import static com.spotify.github.v3.clients.GitHubClient.LIST_COMMIT_TYPE_REFERENCE;
42+
import static com.spotify.github.v3.clients.GitHubClient.LIST_PR_TYPE_REFERENCE;
43+
import static com.spotify.github.v3.clients.GitHubClient.LIST_REVIEW_REQUEST_TYPE_REFERENCE;
44+
import static com.spotify.github.v3.clients.GitHubClient.LIST_REVIEW_TYPE_REFERENCE;
45+
import com.spotify.github.v3.prs.Comment;
46+
import com.spotify.github.v3.prs.MergeParameters;
47+
import com.spotify.github.v3.prs.PullRequest;
48+
import com.spotify.github.v3.prs.PullRequestItem;
49+
import com.spotify.github.v3.prs.RequestReviewParameters;
50+
import com.spotify.github.v3.prs.Review;
51+
import com.spotify.github.v3.prs.ReviewParameters;
52+
import com.spotify.github.v3.prs.ReviewRequests;
53+
import com.spotify.github.v3.prs.requests.PullRequestCreate;
54+
import com.spotify.github.v3.prs.requests.PullRequestParameters;
55+
import com.spotify.github.v3.prs.requests.PullRequestUpdate;
56+
import com.spotify.github.v3.repos.CommitItem;
57+
5058
/** Pull call API client */
5159
public class PullRequestClient {
5260

@@ -57,6 +65,8 @@ public class PullRequestClient {
5765
private static final String PR_REVIEWS_TEMPLATE = "/repos/%s/%s/pulls/%s/reviews";
5866
private static final String PR_REVIEW_REQUESTS_TEMPLATE =
5967
"/repos/%s/%s/pulls/%s/requested_reviewers";
68+
private static final String PR_COMMENT_REPLIES_TEMPLATE =
69+
"/repos/%s/%s/pulls/%s/comments/%s/replies";
6070

6171
private final GitHubClient github;
6272
private final String owner;
@@ -450,4 +460,23 @@ private CompletableFuture<List<PullRequestItem>> list(final String parameterPath
450460
log.debug("Fetching pull requests from " + path);
451461
return github.request(path, LIST_PR_TYPE_REFERENCE);
452462
}
463+
464+
/**
465+
* Creates a reply to a pull request review comment.
466+
*
467+
* @param prNumber pull request number
468+
* @param commentId the ID of the comment to reply to
469+
* @param body the reply message
470+
* @return the created comment
471+
* @see "https://docs.github.com/en/rest/pulls/comments#create-a-reply-for-a-review-comment"
472+
*/
473+
public CompletableFuture<Comment> createCommentReply(
474+
final long prNumber, final long commentId, final String body) {
475+
final String path =
476+
String.format(PR_COMMENT_REPLIES_TEMPLATE, owner, repo, prNumber, commentId);
477+
final Map<String, String> payload = ImmutableMap.of("body", body);
478+
final String jsonPayload = github.json().toJsonUnchecked(payload);
479+
log.debug("Creating reply to PR comment: " + path);
480+
return github.post(path, jsonPayload, Comment.class);
481+
}
453482
}

src/main/java/com/spotify/github/v3/comment/Comment.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -75,4 +75,8 @@ public interface Comment extends UpdateTracking {
7575

7676
/** The issueURL which the comment belongs to. */
7777
Optional<URI> issueUrl();
78+
79+
/** Node ID */
80+
@Nullable
81+
String nodeId();
7882
}

src/main/java/com/spotify/github/v3/prs/Comment.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -73,7 +73,6 @@ public interface Comment extends UpdateTracking {
7373
/** Base commit sha. */
7474
@Nullable
7575
String originalCommitId();
76-
7776
/** Comment author. */
7877
@Nullable
7978
User user();
@@ -82,6 +81,38 @@ public interface Comment extends UpdateTracking {
8281
@Nullable
8382
String body();
8483

84+
/** The ID of the comment to reply to. */
85+
@Nullable
86+
Long inReplyToId();
87+
88+
/** The author association of the comment. */
89+
@Nullable
90+
String authorAssociation();
91+
92+
/** The starting line number in the diff. */
93+
@Nullable
94+
Integer startLine();
95+
96+
/** The starting line number in the original file. */
97+
@Nullable
98+
Integer originalStartLine();
99+
100+
/** The side of the diff where the starting line is from. */
101+
@Nullable
102+
String startSide();
103+
104+
/** The line number in the diff. */
105+
@Nullable
106+
Integer line();
107+
108+
/** The line number in the original file. */
109+
@Nullable
110+
Integer originalLine();
111+
112+
/** The side of the diff where the line is from. */
113+
@Nullable
114+
String side();
115+
85116
/** Comment URL. */
86117
@Nullable
87118
URI htmlUrl();
@@ -94,4 +125,12 @@ public interface Comment extends UpdateTracking {
94125
@Nullable
95126
@JsonProperty("_links")
96127
CommentLinks links();
128+
129+
/** Node ID */
130+
@Nullable
131+
String nodeId();
132+
133+
/** Pull request review ID. */
134+
@Nullable
135+
Long pullRequestReviewId();
97136
}

src/main/java/com/spotify/github/v3/prs/PullRequestItem.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -122,6 +122,12 @@ public interface PullRequestItem extends PartialPullRequestItem {
122122
@JsonProperty("requested_teams")
123123
List<User> requestedTeams();
124124

125-
/** @Deprecated the merge commit sha. */
125+
/**
126+
* @Deprecated the merge commit sha.
127+
*/
126128
Optional<String> mergeCommitSha();
129+
130+
/** Node ID. */
131+
@Nullable
132+
String nodeId();
127133
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*-
2+
* -\-\-
3+
* github-api
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
21+
package com.spotify.github.v3.activity.events;
22+
23+
import java.io.IOException;
24+
import static java.nio.charset.Charset.defaultCharset;
25+
26+
import static org.hamcrest.MatcherAssert.assertThat;
27+
import static org.hamcrest.core.Is.is;
28+
import org.junit.jupiter.api.Test;
29+
30+
import com.google.common.io.Resources;
31+
import static com.google.common.io.Resources.getResource;
32+
import com.spotify.github.jackson.Json;
33+
34+
public class IssueCommentEventTest {
35+
36+
@Test
37+
public void testDeserialization() throws IOException {
38+
String fixture =
39+
Resources.toString(
40+
getResource(this.getClass(), "fixtures/issue_comment_event.json"), defaultCharset());
41+
final IssueCommentEvent event = Json.create().fromJson(fixture, IssueCommentEvent.class);
42+
assertThat(event.action(), is("created"));
43+
assertThat(event.issue().number(), is(2L));
44+
assertThat(event.comment().id(), is(99262140L));
45+
assertThat(event.comment().nodeId(), is("asd123"));
46+
assertThat(
47+
event.comment().body(), is("You are totally right! I'll get this fixed right away."));
48+
}
49+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*-
2+
* -\-\-
3+
* github-client
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
21+
package com.spotify.github.v3.activity.events;
22+
23+
import java.io.IOException;
24+
import static java.nio.charset.Charset.defaultCharset;
25+
26+
import static org.hamcrest.MatcherAssert.assertThat;
27+
import static org.hamcrest.core.Is.is;
28+
import org.junit.jupiter.api.Test;
29+
30+
import com.google.common.io.Resources;
31+
import static com.google.common.io.Resources.getResource;
32+
import com.spotify.github.jackson.Json;
33+
34+
public class PullRequestReviewCommentEventTest {
35+
@Test
36+
public void testDeserialization() throws IOException {
37+
String fixture =
38+
Resources.toString(
39+
getResource(this.getClass(), "fixtures/pull_request_review_comment_event.json"),
40+
defaultCharset());
41+
final PullRequestReviewCommentEvent event =
42+
Json.create().fromJson(fixture, PullRequestReviewCommentEvent.class);
43+
assertThat(event.action(), is("created"));
44+
assertThat(event.comment().id(), is(29724692L));
45+
assertThat(event.comment().nodeId(), is("abc234"));
46+
assertThat(event.pullRequest().nodeId(), is("abc123"));
47+
assertThat(event.comment().body(), is("Maybe you should use more emojji on this line."));
48+
assertThat(event.comment().originalCommitId(), is("0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c"));
49+
assertThat(event.comment().originalLine(), is(1));
50+
assertThat(event.comment().originalPosition(), is(1));
51+
assertThat(event.comment().originalStartLine(), is(1));
52+
assertThat(event.comment().line(), is(1));
53+
assertThat(event.comment().side(), is("RIGHT"));
54+
assertThat(event.comment().startLine(), is(1));
55+
assertThat(event.comment().startSide(), is("RIGHT"));
56+
assertThat(event.comment().authorAssociation(), is("NONE"));
57+
assertThat(event.comment().pullRequestReviewId(), is(42L));
58+
assertThat(event.comment().inReplyToId(), is(426899381L));
59+
}
60+
}

0 commit comments

Comments
 (0)