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

997: Email notifications are not sent to alias if binary change is commented in Gitlab #1190

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -369,15 +369,21 @@ static String composeReviewComment(PullRequest pr, ReviewComment reviewComment)

// Add some context to the first post
if (reviewComment.parent().isEmpty()) {
body.append(reviewComment.path()).append(" line ").append(reviewComment.line()).append(":\n\n");
try {
var contents = pr.repository().fileContents(reviewComment.path(), reviewComment.hash().hex()).lines().collect(Collectors.toList());
for (int i = Math.max(0, reviewComment.line() - 3); i < Math.min(contents.size(), reviewComment.line()); ++i) {
body.append("> ").append(i + 1).append(": ").append(contents.get(i)).append("\n");
body.append(reviewComment.path());
if (reviewComment.line() > 0) {
body.append(" line ").append(reviewComment.line());
}
body.append(":\n\n");
if (reviewComment.line() > 0) {
try {
var contents = pr.repository().fileContents(reviewComment.path(), reviewComment.hash().hex()).lines().collect(Collectors.toList());
for (int i = Math.max(0, reviewComment.line() - 3); i < Math.min(contents.size(), reviewComment.line()); ++i) {
body.append("> ").append(i + 1).append(": ").append(contents.get(i)).append("\n");
}
body.append("\n");
} catch (RuntimeException e) {
body.append("> (failed to retrieve contents of file, check the PR for context)\n");
}
body.append("\n");
} catch (RuntimeException e) {
body.append("> (failed to retrieve contents of file, check the PR for context)\n");
}
}
body.append(filterCommentsAndCommands(reviewComment.body()));
@@ -791,7 +791,7 @@ void reviewComment(TestInfo testInfo) throws IOException {
assertTrue(archiveContains(archiveFolder.path(), "This is now ready"));
assertTrue(archiveContains(archiveFolder.path(), "Review comment"));
assertTrue(archiveContains(archiveFolder.path(), "> This is now ready"));
assertTrue(archiveContains(archiveFolder.path(), reviewFile.toString()));
assertTrue(archiveContains(archiveFolder.path(), reviewFile + " line 2:"));
assertFalse(archiveContains(archiveFolder.path(), "Don't mind me"));

// The mailing list as well
@@ -821,6 +821,16 @@ void reviewComment(TestInfo testInfo) throws IOException {
assertEquals(noreplyAddress(archive), newMail.author().address());
assertEquals(listAddress, newMail.sender());
}

// Add a file comment (on line 0)
var fileComment = pr.addReviewComment(masterHash, editHash, reviewFile.toString(), 0, "File review comment");
TestBotRunner.runPeriodicItems(mlBot);
listServer.processIncoming();

// The archive should contain the additional comment
Repository.materialize(archiveFolder.path(), archive.url(), "master");
assertTrue(archiveContains(archiveFolder.path(), "File review comment"));
assertTrue(archiveContains(archiveFolder.path(), reviewFile + ":"));
}
}

@@ -210,15 +210,27 @@ private ReviewComment parseReviewComment(String discussionId, ReviewComment pare
String path;
Hash hash;

// Is the comment on the old or the new version of the file?
if (note.get("position").get("new_line").isNull()) {
line = note.get("position").get("old_line").asInt();
path = note.get("position").get("old_path").asString();
hash = new Hash(note.get("position").get("start_sha").asString());
var position = note.get("position");
// Is this a line comment?
// For line comments, this field is always set, either to a value or null, but
// for file comments there is no new_line field at all.
if (position.get("new_line") != null) {
// Is the comment on the old or the new version of the file?
if (position.get("new_line").isNull()) {
line = position.get("old_line").asInt();
path = position.get("old_path").asString();
hash = new Hash(position.get("start_sha").asString());
} else {
line = position.get("new_line").asInt();
path = position.get("new_path").asString();
hash = new Hash(position.get("head_sha").asString());
}
} else {
line = note.get("position").get("new_line").asInt();
path = note.get("position").get("new_path").asString();
hash = new Hash(note.get("position").get("head_sha").asString());
// This comment does not have a line. Gitlab seems to only allow file comments
// on the new file
line = 0;
path = position.get("new_path").asString();
hash = new Hash(position.get("head_sha").asString());
}

var comment = new ReviewComment(parent,