Conversation
|
| try { | ||
| github = new GitHubBuilder().withOAuthToken(githubApiKey).build(); | ||
| } catch (IOException e) { | ||
| logger.error("Failed to initialize GitHub API wrapper.", e); |
There was a problem hiding this comment.
The error message, since duplicate should be stored in a String
| github = new GitHubBuilder().withOAuthToken(githubApiKey).build(); | ||
| } catch (IOException e) { | ||
| logger.error("Failed to initialize GitHub API wrapper.", e); | ||
| event.reply("Failed to initialize GitHub API wrapper.").setEphemeral(true).queue(); |
There was a problem hiding this comment.
Actually, this isn't a meaningful error message to the user. Instead opt for something user friendly e.g. "An internal error occurred while linking your repository, please try again later"
|
|
||
| try { | ||
| if (!isRepositoryAccessible(github, repositoryOwner, repositoryName)) { | ||
| event.reply("Repository is not publicly available.").setEphemeral(true).queue(); |
There was a problem hiding this comment.
Opt to provide the owner and name in this error message. It could have been they made a typo. Maybe include a link to the docs on how they can set the visibility too.
| } | ||
| } catch (IOException e) { | ||
| logger.error("Failed to check if GitHub repository is available.", e); | ||
| event.reply("Failed to link repository.").setEphemeral(true).queue(); |
There was a problem hiding this comment.
Same here, opt for the user friendly message. Make it a constant above since it can be reused.
|
|
||
| try { | ||
| saveNotificationToDatabase(channelId, repositoryOwner, repositoryName); | ||
| event.reply("Successfully linked repository.").setEphemeral(true).queue(); |
There was a problem hiding this comment.
Let's make this response a pretty embed for everyone in the project thread to see.
| } | ||
| } | ||
|
|
||
| lastExecution = new Date(); |
There was a problem hiding this comment.
System.currentTimeMillis() please to avoid creating a new Date object each time
|
|
||
| List<GHPullRequest> pullRequests = repository.getPullRequests(GHIssueState.OPEN); | ||
| for (GHPullRequest pr : pullRequests) { | ||
| if (pr.getCreatedAt().after(lastExecution)) { |
There was a problem hiding this comment.
pr.getCreatedAt() > lastExecution
| logger.info("Failed to find channel {} to send pull request notification.", channelId); | ||
| return; | ||
| } | ||
| channel.sendMessage("New pull request from " + pr.getUser().getLogin() + ".").queue(); |
There was a problem hiding this comment.
Let's make this a pretty embed. We're missing key details here such as the PR name, description, number, creation date and URL.
|
|
||
| GitHub github; | ||
| try { | ||
| github = new GitHubBuilder().withOAuthToken(githubApiKey).build(); |
There was a problem hiding this comment.
Let's move this into the constructor and log. So we can fail fast. Or even better, do the init inside Features.java and only then bind the routine/commands if we can successfully create a GitHub object.
| event.reply("Successfully linked repository.").setEphemeral(true).queue(); | ||
| } catch (DatabaseException e) { | ||
| logger.error("Failed to save pull request notification to database.", e); | ||
| event.reply("Failed to link repository.").setEphemeral(true).queue(); |
There was a problem hiding this comment.
Better error message please
20b0898 to
1e1717b
Compare
|
|
Closing this PR. The webhook alternative approach involves sharing the sensitive webhook link with a third party. My suggestion would be sharing them with very active #projects posts and trusted users if needed. If anything goes wrong, we can just disable the webhook. Quick note: |


About
closes #1142
Implements the functionality for PR notifications
link-gh-project: links a channel to GitHub repositories to announce new pull requestunlink-gh-project: unlinks a previous pull request notification configurationThe
PullRequestNotificationRoutinehandles pulling the new updates from repositories and sending a notification.Database
This PR creates a new database table to store the notification configuration: