Skip to content

Bugfix/GitHub reference #1061

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

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Changes from all commits
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 @@ -42,7 +42,7 @@ public final class GitHubReference extends MessageReceiverAdapter {
* The pattern(#123) used to determine whether a message is referencing an issue.
*/
static final Pattern ISSUE_REFERENCE_PATTERN =
Pattern.compile("#(?<%s>\\d+)".formatted(ID_GROUP));
Pattern.compile("#(?<%s>\\d{1,5})".formatted(ID_GROUP));
private static final int ISSUE_OPEN = Color.green.getRGB();
private static final int ISSUE_CLOSE = Color.red.getRGB();

Expand Down Expand Up @@ -108,8 +108,9 @@ public void onMessageReceived(MessageReceivedEvent event) {

while (matcher.find()) {
long defaultRepoId = config.getGitHubRepositories().get(0);
findIssue(Integer.parseInt(matcher.group(ID_GROUP)), defaultRepoId)
.ifPresent(issue -> embeds.add(generateReply(issue)));

int issueId = Integer.parseInt(matcher.group(ID_GROUP));
findIssue(issueId, defaultRepoId).ifPresent(issue -> embeds.add(generateReply(issue)));
}

replyBatchEmbeds(embeds, message, false);
Expand Down Expand Up @@ -148,6 +149,10 @@ MessageEmbed generateReply(GHIssue issue) throws UncheckedIOException {
String titleUrl = issue.getHtmlUrl().toString();
String description = issue.getBody();

if (description != null && description.length() > MessageEmbed.DESCRIPTION_MAX_LENGTH) {
description = "too long for preview, visit Github";
}

String labels = issue.getLabels()
.stream()
.map(GHLabel::getName)
Expand Down Expand Up @@ -231,6 +236,10 @@ List<GHRepository> getRepositories() {
}

private boolean isAllowedChannelOrChildThread(MessageReceivedEvent event) {
if (event.getChannelType() != ChannelType.TEXT) {
return false;
}

if (event.getChannelType().isThread()) {
ThreadChannel threadChannel = event.getChannel().asThreadChannel();
String rootChannel = threadChannel.getParentChannel().getName();
Expand Down