Skip to content

Commit

Permalink
Allow specifying already existing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Jun 12, 2022
1 parent 52438a3 commit f68a56b
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.apache.commons.io.IOUtils;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHOrganization;

import java.io.IOException;
Expand Down Expand Up @@ -59,7 +60,8 @@ public Link() {
janitorOnly = true;
options = List.of(
new OptionData(OptionType.STRING, "repo", "The name of the fork to link. E.g: Vampirism", true),
new OptionData(OptionType.STRING, "mod", "The CurseForge slug of the mod to link the fork to.", true)
new OptionData(OptionType.STRING, "mod", "The CurseForge slug of the mod to link the fork to", true),
new OptionData(OptionType.INTEGER, "issue", "The number of an already existing issue on the archives repo")
);
}

Expand All @@ -78,11 +80,16 @@ protected void exec(SlashCommandEvent event) throws Throwable {
}
final var mod = modsResponse.get().get(0);
final var archivesRepo = getArchivesRepo();
final var issue = archivesRepo.createIssue(mod.name())
.assignee(getLinkedAccount(event.getUser().getIdLong()))
.label("in-progress")
.body(getIssueBody(parent.getHtmlUrl().toString(), mod.links().websiteUrl()))
.create();
final GHIssue issue;
if (event.hasOption("issue")) {
issue = archivesRepo.getIssue(event.getOption("issue", 0, OptionMapping::getAsInt));
} else {
issue = archivesRepo.createIssue(mod.name())
.assignee(getLinkedAccount(event.getUser().getIdLong()))
.label("in-progress")
.body(getIssueBody(parent.getHtmlUrl().toString(), mod.links().websiteUrl()))
.create();
}
TheInquisitor.getInstance().jdbi().useExtension(ModsDAO.class, db -> db.insert(repo, mod.id(), issue.getNumber()));
event.getHook()
.sendMessage("Linked [%s](%s) to issue %s.".formatted(mod.name(), mod.links().websiteUrl(), issue.getHtmlUrl()))
Expand Down

0 comments on commit f68a56b

Please sign in to comment.