Skip to content

Commit

Permalink
Merge pull request #211 from xjusko/add-additional-logging
Browse files Browse the repository at this point in the history
Add additional logging for debugging purpose of request reviewer intermittent issue
  • Loading branch information
xjusko authored Feb 13, 2025
2 parents 4416520 + 50eba13 commit b585334
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
53 changes: 44 additions & 9 deletions src/main/java/org/wildfly/bot/util/GithubProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ public void processNotifies(GHPullRequest pullRequest, GitHub gitHub, Set<String
.map(GHPerson::getLogin)
.toList();

LOG.infof("Current reviewers already added to the PR: %s", currentReviewers);

reviewers.removeAll(currentReviewers);

LOG.infof("Reviewers to be added to the PR: %s", reviewers);

updateCCMentions(pullRequest, ccMentions);

if (!reviewers.isEmpty()) {
Expand All @@ -118,22 +122,53 @@ public void processNotifies(GHPullRequest pullRequest, GitHub gitHub, Set<String
try {
GHUser ghUser = gitHub.getUser(requestedReviewer);
pullRequest.requestReviewers(List.of(ghUser));
} catch (HttpException | RuntimeException e) {
} catch (HttpException e) {
String responseMessage = e.getResponseMessage() != null ? e.getResponseMessage()
: "No response message available.";
LOG.warnf(
"Failed to add reviewer '%s'. Error: %s, Response: %s",
requestedReviewer, e.getMessage(), responseMessage);
failedReviewers.add(requestedReviewer);
} catch (RuntimeException e) {
LOG.warnf(
"The request of getting GHUser or requesting the user as Pull Request reviewer has failed due to %s",
e.getMessage());
"Unexpected error while adding reviewer '%s'. Error: %s",
requestedReviewer, e.getMessage());
failedReviewers.add(requestedReviewer);
}
}

// TODO Revert after debugging request reviewers bug
if (!failedReviewers.isEmpty()) {
LOG.warnf("Bot can not request PR review from the following people: %s", failedReviewers);
GHRepository repository = pullRequest.getRepository();
sendEmail(
COLLABORATOR_MISSING_SUBJECT.formatted(repository.getFullName()),
COLLABORATOR_MISSING_BODY.formatted(repository.getFullName(), pullRequest.getNumber(),
failedReviewers),
emails);
// Check if actually failedReviewers are not collaborators
for (String failedReviewer : failedReviewers) {
if (repository.isCollaborator(gitHub.getUser(failedReviewer))) {
LOG.warnf("Reviewer '%s' failed to be added, but they are a collaborator in the '%s' repository.",
failedReviewer, repository.getFullName());
}
}
List<String> finalRequestedReviewers = pullRequest.getRequestedReviewers()
.stream()
.map(GHPerson::getLogin)
.toList();

LOG.infof("Final reviewers added to the PR: %s", finalRequestedReviewers);

// Remove successfully added reviewers from the failed list
failedReviewers.removeAll(finalRequestedReviewers);

// Log the actual failed reviewers that were not added
if (!failedReviewers.isEmpty()) {
LOG.warnf("Bot failed to request PR review from the following people: %s", failedReviewers);

sendEmail(
COLLABORATOR_MISSING_SUBJECT.formatted(repository.getFullName()),
COLLABORATOR_MISSING_BODY.formatted(repository.getFullName(), pullRequest.getNumber(),
failedReviewers),
emails);
} else {
LOG.info("All initially failed reviewers were successfully added to the PR after verification.");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testOnlyMissingCollaboratorsNoReviewAssignment() throws Throwable {
.comment(ArgumentMatchers.anyString());
Assertions.assertTrue(inMemoryLogHandler.getRecords().stream().anyMatch(
logRecord -> logRecord.getMessage().contains(
"Bot can not request PR review from the following people: [Butterfly, Tadpole]")));
"Bot failed to request PR review from the following people: [Butterfly, Tadpole]")));

List<Mail> sent = mailbox.getMailsSentTo("foo@bar.baz");
Assertions.assertEquals(sent.size(), 1);
Expand Down Expand Up @@ -143,7 +143,7 @@ public void testCommentAndReviewAssignmentCombination() throws Throwable {
.toList(), Matchers.containsInAnyOrder("Tadpole"));
Assertions.assertTrue(inMemoryLogHandler.getRecords().stream().anyMatch(
logRecord -> logRecord.getMessage().contains(
"Bot can not request PR review from the following people: [Butterfly]")));
"Bot failed to request PR review from the following people: [Butterfly]")));

List<Mail> sent = mailbox.getMailsSentTo("foo@bar.baz");
Assertions.assertEquals(sent.size(), 1);
Expand Down

0 comments on commit b585334

Please sign in to comment.