Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ public enum GitHubReviewNotificationType {

DM,
SERVER,
NONE,
BOTH;

public boolean isDmNotify() {
return switch (this) {
case DM, BOTH -> true;
case SERVER -> false;
case SERVER, NONE -> false;
};
}

public boolean isServerNotify() {
return switch (this) {
case SERVER, BOTH -> true;
case DM -> false;
case DM, NONE -> false;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,6 @@ private void handlePRStatusCheck(
return;
}

this.jda.retrieveUserById(reminder.userId()).queue(
user -> this.handleUserRetrieved(
user,
reminder.threadId(),
reminder.pullRequestUrl(),
pullRequest),
throwable -> {
Sentry.captureException(throwable);
LOGGER.log(Level.SEVERE, "Error retrieving user: " + reminder.userId(), throwable);
}
);
}
catch (Exception exception) {
Sentry.captureException(exception);
Expand Down Expand Up @@ -241,42 +230,4 @@ private String findGithubUsernameByDiscordId(long userId) {
.orElse(null);
}

private void handleUserRetrieved(User user, long threadId, String pullRequestUrl, GitHubPullRequest pullRequest) {
if (user == null) {
LOGGER.warning("User is null for thread: " + threadId);
return;
}

ThreadChannel thread = this.jda.getThreadChannelById(threadId);
if (thread == null) {
LOGGER.warning("Could not find thread with ID " + threadId);
return;
}

this.sendReminderMessage(user, thread, pullRequestUrl, pullRequest);
}

private void sendReminderMessage(
User user,
ThreadChannel thread,
String pullRequestUrl,
GitHubPullRequest pullRequest) {
String message = String.format(
"Hey %s! you have been assigned as a reviewer for this pull request: <%s>.",
user.getAsMention(),
pullRequestUrl
);

thread.sendMessage(message).queue(
success -> {
LOGGER.info("Reminder sent to " + user.getName() + " for PR: " + pullRequestUrl);
this.mentionRepository.recordReminderSent(pullRequest, user.getIdLong())
.exceptionally(FutureHandler::handleException);
},
throwable -> {
Sentry.captureException(throwable);
LOGGER.log(Level.SEVERE, "Error sending reminder message to " + user.getName(), throwable);
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public NotificationChild(GitHubReviewService gitHubReviewService) {
.addChoice("DM", GitHubReviewNotificationType.DM.toString())
.addChoice("SERVER", GitHubReviewNotificationType.SERVER.toString())
.addChoice("BOTH", GitHubReviewNotificationType.BOTH.toString())
.addChoice("NONE", GitHubReviewNotificationType.NONE.toString())
.setRequired(true)
);

Expand Down
Loading