302 var id = getMessageId(comment);
303 if (existingIds.containsKey(getStableMessageId(id))) {
304 return;
305 }
306
307 var parent = latestGeneralComment();
308 addReplyCommon(parent, comment.author(), "Re: RFR: " + prInstance.pr().title(), comment.body(), id);
309 }
310
311 private String projectRole(Contributor contributor) {
312 var version = censusInstance.configuration().census().version();
313 if (censusInstance.project().isLead(contributor.username(), version)) {
314 return "Lead";
315 } else if (censusInstance.project().isReviewer(contributor.username(), version)) {
316 return "Reviewer";
317 } else if (censusInstance.project().isCommitter(contributor.username(), version)) {
318 return "Committer";
319 } else if (censusInstance.project().isAuthor(contributor.username(), version)) {
320 return "Author";
321 }
322 return "none";
323 }
324
325 void addReview(Review review) {
326 var id = getMessageId(review);
327 if (existingIds.containsKey(getStableMessageId(id))) {
328 return;
329 }
330
331 // Default parent and subject
332 var parent = topCommentForHash(review.hash());
333 var subject = parent.subject();
334
335 var replyBody = ArchiveMessages.reviewCommentBody(review.body().orElse(""));
336
337 addReplyCommon(parent, review.reviewer(), subject, replyBody, id);
338 }
339
340 void addReviewVerdict(Review review) {
341 var id = getMessageId(review);
342 if (existingIds.containsKey(getStableMessageId(id))) {
343 return;
344 }
345
346 var contributor = censusInstance.namespace().get(review.reviewer().id());
347 var isReviewer = contributor != null && censusInstance.project().isReviewer(contributor.username(), censusInstance.configuration().census().version());
348
349 // Default parent and subject
350 var parent = topCommentForHash(review.hash());
351 var subject = parent.subject();
352
353 // Approvals by Reviewers get special treatment - post these as top-level comments
354 if (review.verdict() == Review.Verdict.APPROVED && isReviewer) {
355 approvalIds.add(id);
356 }
357
358 var userName = contributor != null ? contributor.username() : review.reviewer().userName() + "@" + censusInstance.namespace().name();
359 var userRole = contributor != null ? projectRole(contributor) : "no project role";
360 var replyBody = ArchiveMessages.reviewVerdictBody(review.body().orElse(""), review.verdict(), userName, userRole);
361
362 addReplyCommon(parent, review.reviewer(), subject, replyBody, id);
363 }
364
365 void addReviewComment(ReviewComment reviewComment) {
366 var id = getMessageId(reviewComment);
367 if (existingIds.containsKey(getStableMessageId(id))) {
368 return;
369 }
370
371 var parent = parentForReviewComment(reviewComment);
372 var body = new StringBuilder();
373
374 // Add some context to the first post
375 if (reviewComment.parent().isEmpty()) {
376 var contents = prInstance.pr().repository().fileContents(reviewComment.path(), reviewComment.hash().hex()).lines().collect(Collectors.toList());
377
378 body.append(reviewComment.path()).append(" line ").append(reviewComment.line()).append(":\n\n");
379 for (int i = Math.max(0, reviewComment.line() - 2); i < Math.min(contents.size(), reviewComment.line() + 1); ++i) {
|
302 var id = getMessageId(comment);
303 if (existingIds.containsKey(getStableMessageId(id))) {
304 return;
305 }
306
307 var parent = latestGeneralComment();
308 addReplyCommon(parent, comment.author(), "Re: RFR: " + prInstance.pr().title(), comment.body(), id);
309 }
310
311 private String projectRole(Contributor contributor) {
312 var version = censusInstance.configuration().census().version();
313 if (censusInstance.project().isLead(contributor.username(), version)) {
314 return "Lead";
315 } else if (censusInstance.project().isReviewer(contributor.username(), version)) {
316 return "Reviewer";
317 } else if (censusInstance.project().isCommitter(contributor.username(), version)) {
318 return "Committer";
319 } else if (censusInstance.project().isAuthor(contributor.username(), version)) {
320 return "Author";
321 }
322 return "no project role";
323 }
324
325 void addReview(Review review) {
326 var id = getMessageId(review);
327 if (existingIds.containsKey(getStableMessageId(id))) {
328 return;
329 }
330
331 // Default parent and subject
332 var parent = topCommentForHash(review.hash());
333 var subject = parent.subject();
334
335 var replyBody = ArchiveMessages.reviewCommentBody(review.body().orElse(""));
336
337 addReplyCommon(parent, review.reviewer(), subject, replyBody, id);
338 }
339
340 void addReviewVerdict(Review review) {
341 var id = getMessageId(review);
342 if (existingIds.containsKey(getStableMessageId(id))) {
343 return;
344 }
345
346 var contributor = censusInstance.namespace().get(review.reviewer().id());
347 var isReviewer = contributor != null && censusInstance.project().isReviewer(contributor.username(), censusInstance.configuration().census().version());
348
349 // Default parent and subject
350 var parent = topCommentForHash(review.hash());
351 var subject = parent.subject();
352
353 // Approvals by Reviewers get special treatment - post these as top-level comments
354 if (review.verdict() == Review.Verdict.APPROVED && isReviewer) {
355 approvalIds.add(id);
356 }
357
358 var userName = contributor != null ? contributor.username() : review.reviewer().userName() + "@" + censusInstance.namespace().name();
359 var userRole = contributor != null ? projectRole(contributor) : "no OpenJDK username";
360 var replyBody = ArchiveMessages.reviewVerdictBody(review.body().orElse(""), review.verdict(), userName, userRole);
361
362 addReplyCommon(parent, review.reviewer(), subject, replyBody, id);
363 }
364
365 void addReviewComment(ReviewComment reviewComment) {
366 var id = getMessageId(reviewComment);
367 if (existingIds.containsKey(getStableMessageId(id))) {
368 return;
369 }
370
371 var parent = parentForReviewComment(reviewComment);
372 var body = new StringBuilder();
373
374 // Add some context to the first post
375 if (reviewComment.parent().isEmpty()) {
376 var contents = prInstance.pr().repository().fileContents(reviewComment.path(), reviewComment.hash().hex()).lines().collect(Collectors.toList());
377
378 body.append(reviewComment.path()).append(" line ").append(reviewComment.line()).append(":\n\n");
379 for (int i = Math.max(0, reviewComment.line() - 2); i < Math.min(contents.size(), reviewComment.line() + 1); ++i) {
|