Skip to content
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

Continue/feature/reference gh #966

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
490ec6f
Bugfix
Tais993 Sep 30, 2022
aa58c07
Update application/src/main/java/org/togetherjava/tjbot/commands/syst…
Tais993 Oct 1, 2022
5f574d3
fixed debug message
Taz03 Oct 1, 2022
a9fef62
add github referencing + github command
illuminator3 Oct 2, 2022
9de6564
make codeql and sonarcloud happy
illuminator3 Oct 2, 2022
1af1b54
spotless, *sigh*
illuminator3 Oct 2, 2022
4325805
forgot these two
illuminator3 Oct 2, 2022
d45db55
remove mention when reference
illuminator3 Oct 2, 2022
99ce678
aaaaaaaaaa
illuminator3 Oct 2, 2022
cad10d2
Merge branch 'develop' into feature/reference-gh
illuminator3 Oct 4, 2022
a85abc2
fix compilation
illuminator3 Oct 4, 2022
ef9989e
fix compilation x2
illuminator3 Oct 4, 2022
1ba1418
apply spotless
illuminator3 Oct 4, 2022
3db6cfa
fix doc
illuminator3 Oct 4, 2022
62b728d
requested changes
illuminator3 Oct 4, 2022
3d2e48c
requested changes
illuminator3 Oct 4, 2022
4c40202
requested changes
illuminator3 Oct 5, 2022
d98b829
Update application/config.json.template
illuminator3 Oct 6, 2022
099f250
Update application/src/main/java/org/togetherjava/tjbot/commands/gith…
illuminator3 Oct 6, 2022
b93dd7e
Update application/src/main/java/org/togetherjava/tjbot/commands/gith…
illuminator3 Oct 6, 2022
c7a8773
resolve conflicts
ankitsmt211 Nov 24, 2023
d780f41
Merge branch 'develop' into continue/feature/reference-gh
ankitsmt211 Nov 24, 2023
39bc9b2
sonar fix
ankitsmt211 Nov 24, 2023
eb930b8
adding back suspicousKeywords
ankitsmt211 Nov 24, 2023
10414c6
requested changes in old PR
ankitsmt211 Nov 24, 2023
92fdef4
java doc fixes
ankitsmt211 Nov 24, 2023
4fafdb0
avatar of author in embed
ankitsmt211 Nov 24, 2023
c8afcb3
refactor embed reply for clarity, add date of creation
ankitsmt211 Nov 24, 2023
5cbdfc9
sonar fix
ankitsmt211 Nov 24, 2023
2d9b54a
refactor date to a better format
ankitsmt211 Nov 24, 2023
c3102af
upgrade from 1.313->1.315
ankitsmt211 Nov 24, 2023
fbd249d
remove duplicate
ankitsmt211 Nov 24, 2023
d5f3a0c
requested changes
ankitsmt211 Nov 25, 2023
53fc48b
refactor date using calendar api to java time api & remove months array
ankitsmt211 Nov 26, 2023
2dfaa0c
get rid of redundant modifier and an extra line of space
ankitsmt211 Nov 26, 2023
0695af9
making formatter a constant field instead of local var
ankitsmt211 Nov 26, 2023
109abf8
update config template and verify allowed channels
ankitsmt211 Nov 27, 2023
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 @@ -20,14 +20,14 @@
import java.util.stream.Stream;

/**
* Slash command (/github) used to search for an issue in one of the repositories listed in the
* config. It even comes with auto completion!
* Slash command (/github-search) used to search for an issue in one of the repositories listed in
* the config. It also auto suggests issues/PRs on trigger.
*/
public class GitHubCommand extends SlashCommandAdapter {
public final class GitHubCommand extends SlashCommandAdapter {
private static final Duration CACHE_EXPIRES_AFTER = Duration.ofMinutes(1);

/**
* Compares the getUpdatedAt values.
* Compares two GitHub Issues ascending by the time they have been updated at.
*/
private static final Comparator<GHIssue> GITHUB_ISSUE_TIME_COMPARATOR = (i1, i2) -> {
try {
Expand Down Expand Up @@ -70,7 +70,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event) {
return;
}

reference.findIssue(Integer.parseInt(matcher.group(GitHubReference.ID_GROUP)))
int issueId = Integer.parseInt(matcher.group(GitHubReference.ID_GROUP));
reference.findIssue(issueId)
.ifPresentOrElse(issue -> event.replyEmbeds(reference.generateReply(issue)).queue(),
() -> event.reply("Could not find the issue you are looking for.")
.setEphemeral(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
* GitHub Referencing feature. If someone sends #id of an issue (e.g. #207) in specified channel,
* the bot replies with an embed that contains info on the issue/PR.
*/
public class GitHubReference extends MessageReceiverAdapter {
public final class GitHubReference extends MessageReceiverAdapter {
static final String ID_GROUP = "id";

/**
* The pattern used to determine whether a message is referencing an issue.
* The pattern(#123) used to determine whether a message is referencing an issue.
*/
protected static final String ID_GROUP = "id";
protected static final Pattern ISSUE_REFERENCE_PATTERN =
static final Pattern ISSUE_REFERENCE_PATTERN =
Pattern.compile("#(?<%s>\\d+)".formatted(ID_GROUP));
private static final int ISSUE_OPEN = Color.green.getRGB();
private static final int ISSUE_CLOSE = Color.red.getRGB();
private static final List<String> months = List.of("Jan", "Feb", "Mar", "Apr", "May", "Jun",
private static final List<String> MONTHS = List.of("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
private final Config config;

Expand Down Expand Up @@ -135,7 +136,7 @@ protected MessageEmbed generateReply(GHIssue issue) throws UncheckedIOException

// Format: 9 Oct, 2023
String dateOfCreation = "%d %s, %d".formatted(createdAt.get(Calendar.DATE),
months.get(createdAt.get(Calendar.MONTH)), createdAt.get(Calendar.YEAR));
MONTHS.get(createdAt.get(Calendar.MONTH)), createdAt.get(Calendar.YEAR));
Zabuzard marked this conversation as resolved.
Show resolved Hide resolved

String footer = "%s • %s • %s".formatted(labels, assignees, dateOfCreation);

Expand Down Expand Up @@ -166,7 +167,7 @@ private String getUserNameOrThrow(GHUser user) throws UncheckedIOException {
/**
* Looks through all of the given repositories for an issue/pr with the given id.
*/
protected Optional<GHIssue> findIssue(int id) {
Optional<GHIssue> findIssue(int id) {
return repositories.stream().map(repository -> {
try {
return Optional.of(repository.getIssue(id));
Expand All @@ -181,7 +182,7 @@ protected Optional<GHIssue> findIssue(int id) {
/**
* All repositories monitored by this instance.
*/
protected List<GHRepository> getRepositories() {
List<GHRepository> getRepositories() {
return repositories;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ public List<String> getBlacklistedFileExtensions() {
}

/**
* The REGEX pattern used to identify the channels that support GitHub issue referencing
* The REGEX pattern used to identify the channels that support GitHub issue referencing.
*/
public String getGitHubReferencingEnabledChannelPattern() {
return githubReferencingEnabledChannelPattern;
}

/**
* The list of repositories that are searched when referencing a GitHub issue
* The list of repositories that are searched when referencing a GitHub issue.
*/
public List<Long> getGitHubRepositories() {
return githubRepositories;
Expand Down
2 changes: 1 addition & 1 deletion database/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var sqliteVersion = "3.44.0.0"
dependencies {
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation "org.xerial:sqlite-jdbc:${sqliteVersion}"
implementation 'org.flywaydb:flyway-core:10.0.0'
implementation 'org.flywaydb:flyway-core:10.1.0'
implementation "org.jooq:jooq:$jooqVersion"

implementation project(':utils')
Expand Down
Loading