Skip to content
Permalink
Browse files
forge: return commit comment from addCommitComment
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Nov 9, 2020
1 parent 9a725bb commit dd7933bbc278a8ad058d57552677ac32a6ab8bd0
Showing 5 changed files with 21 additions and 14 deletions.
@@ -157,7 +157,8 @@ public List<CommitComment> commitComments(Hash commit) {
}

@Override
public void addCommitComment(Hash commit, String body) {
public CommitComment addCommitComment(Hash commit, String body) {
return null;
}

@Override
@@ -69,7 +69,7 @@ PullRequest createPullRequest(HostedRepository target,
List<HostedBranch> branches();
List<CommitComment> commitComments(Hash hash);
List<CommitComment> recentCommitComments();
void addCommitComment(Hash hash, String body);
CommitComment addCommitComment(Hash hash, String body);
void updateCommitComment(String id, String body);
Optional<HostedCommit> commit(Hash hash);
List<Check> allChecks(Hash hash);
@@ -360,11 +360,12 @@ public List<CommitComment> recentCommitComments() {
}

@Override
public void addCommitComment(Hash hash, String body) {
public CommitComment addCommitComment(Hash hash, String body) {
var query = JSON.object().put("body", body);
request.post("commits/" + hash.hex() + "/comments")
.body(query)
.execute();
var result = request.post("commits/" + hash.hex() + "/comments")
.body(query)
.execute();
return toCommitComment(result);
}

@Override
@@ -298,12 +298,14 @@ private CommitComment toCommitComment(Hash hash, JSONValue o) {
// GitLab does not offer updated_at for commit comments
var createdAt = ZonedDateTime.parse(o.get("created_at").asString());
// GitLab does not offer an id for commit comments
var id = "";
var body = o.get("note").asString();
var user = gitLabHost.parseAuthorField(o);
var id = Integer.toString((hash.hex() + createdAt.toString() + user.id()).hashCode());
return new CommitComment(hash,
path,
line,
id,
o.get("note").asString(),
body,
gitLabHost.parseAuthorField(o),
createdAt,
createdAt);
@@ -381,11 +383,12 @@ public List<CommitComment> recentCommitComments() {
}

@Override
public void addCommitComment(Hash hash, String body) {
public CommitComment addCommitComment(Hash hash, String body) {
var query = JSON.object().put("note", body);
request.post("repository/commits/" + hash.hex() + "/comments")
.body(query)
.execute();
var result = request.post("repository/commits/" + hash.hex() + "/comments")
.body(query)
.execute();
return toCommitComment(hash, result);
}

@Override
@@ -221,7 +221,7 @@ public List<CommitComment> recentCommitComments() {
}

@Override
public void addCommitComment(Hash hash, String body) {
public CommitComment addCommitComment(Hash hash, String body) {
var id = nextCommitCommentId;
nextCommitCommentId += 1;
var createdAt = ZonedDateTime.now();
@@ -230,7 +230,9 @@ public void addCommitComment(Hash hash, String body) {
commitComments.put(hash, new ArrayList<>());
}
var comments = commitComments.get(hash);
comments.add(new CommitComment(hash, null, -1, Integer.toString(id), body, host.currentUser(), createdAt, createdAt));
var comment = new CommitComment(hash, null, -1, Integer.toString(id), body, host.currentUser(), createdAt, createdAt);
comments.add(comment);
return comment;
}

@Override

1 comment on commit dd7933b

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on dd7933b Nov 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.