-
Notifications
You must be signed in to change notification settings - Fork 12
Feature: PR link #19
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
Open
ILike2WatchMemes
wants to merge
19
commits into
SkyHanniStudios:master
Choose a base branch
from
ILike2WatchMemes:pr-link
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature: PR link #19
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
00c2db0
Merge branch 'pr-10' into pr-link
ILike2WatchMemes 8ebbec9
Merge branch 'pr-18' into pr-link
ILike2WatchMemes a280741
add link option
ILike2WatchMemes cb846db
fix config link
ILike2WatchMemes afedf40
updates
ILike2WatchMemes 2b56e98
Merge remote-tracking branch 'upstream/master' into pr-link
ILike2WatchMemes a733fef
Update PullRequestCommand.kt
ILike2WatchMemes 2d9bbbe
Merge remote-tracking branch 'upstream/master' into pr-link
ILike2WatchMemes 2fcb6e2
remove * import
ILike2WatchMemes 9e28cf5
Merge branch 'master' into pr-link
ILike2WatchMemes 8f98d57
Merge branch 'refs/heads/master' into fork/ILike2WatchMemes/pr-link
hannibal002 c40eb43
updates
ILike2WatchMemes 44db0e3
added more _
hannibal002 50fa292
merged logic into parseValidPrNumber
hannibal002 222b8e8
made isLinked unnecessary
hannibal002 65b2efa
title format don't replace wrong titles
hannibal002 fe49eb6
actually link config
ILike2WatchMemes dd3d004
merge
ILike2WatchMemes 994f432
Merge branch 'master' into pr-link
ILike2WatchMemes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/at/hannibal2/skyhanni/discord/LinkListener.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package at.hannibal2.skyhanni.discord | ||
|
|
||
| import at.hannibal2.skyhanni.discord.Utils.messageSend | ||
| import net.dv8tion.jda.api.events.message.MessageReceivedEvent | ||
|
|
||
| object LinkListener { | ||
|
|
||
| private const val GITHUB_WEBHOOK_ID = "1347997547368550461" | ||
ILike2WatchMemes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private val githubPattern = | ||
| "\\[ILike2WatchMemes/DiscordBot] (New comment on pull request|Pull request review submitted:) #(?<pr>\\d+):? .+".toPattern() | ||
ILike2WatchMemes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| fun onMessage(bot: DiscordBot, event: MessageReceivedEvent) { | ||
| event.onMessage(bot) | ||
| } | ||
|
|
||
| private fun MessageReceivedEvent.onMessage(bot: DiscordBot) { | ||
| if (this.author.id == GITHUB_WEBHOOK_ID) { | ||
ILike2WatchMemes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val embed = this.message.embeds[0] | ||
|
|
||
| val title = embed.title ?: return | ||
|
|
||
| val prNumber = getPr(title)?.toInt() ?: return | ||
| val link = Database.getLink(prNumber) ?: return | ||
|
|
||
| val guild = bot.jda.getGuildById(BOT.config.allowedServerId) ?: return | ||
| val channel = guild.getThreadChannelById(link.channel) ?: return | ||
|
|
||
|
|
||
| channel.messageSend(this.message.embeds[0]) | ||
| } | ||
| } | ||
|
|
||
| private fun getPr(title: String): String? { | ||
| val matcher = githubPattern.matcher(title) | ||
| if (!matcher.matches()) return null | ||
| return matcher.group("pr") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/main/kotlin/at/hannibal2/skyhanni/discord/command/LinkCommands.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package at.hannibal2.skyhanni.discord.command | ||
|
|
||
| import at.hannibal2.skyhanni.discord.Database | ||
| import at.hannibal2.skyhanni.discord.OPEN_PR_TAG | ||
| import at.hannibal2.skyhanni.discord.Option | ||
| import at.hannibal2.skyhanni.discord.PLEADING_FACE | ||
| import at.hannibal2.skyhanni.discord.Utils.logAction | ||
| import at.hannibal2.skyhanni.discord.Utils.reply | ||
| import at.hannibal2.skyhanni.discord.Utils.userError | ||
| import at.hannibal2.skyhanni.discord.Utils.userSuccess | ||
| import at.hannibal2.skyhanni.discord.command.LinkCommand.setTags | ||
| import at.hannibal2.skyhanni.discord.command.LinkCommand.setTitle | ||
| import net.dv8tion.jda.api.entities.channel.ChannelType | ||
| import net.dv8tion.jda.api.entities.channel.forums.ForumTag | ||
| import net.dv8tion.jda.api.events.message.MessageReceivedEvent | ||
| import net.dv8tion.jda.api.managers.channel.concrete.ThreadChannelManager | ||
|
|
||
| object LinkCommand : BaseCommand() { | ||
| override val name = "link" | ||
|
|
||
| override val description = "Link a forum post to a pull request." | ||
| override val options: List<Option> = listOf( | ||
| Option("number", "Number of the pull request you want the post to be linked to.") | ||
| ) | ||
|
|
||
| override fun MessageReceivedEvent.execute(args: List<String>) { | ||
| if (args.size != 1) return wrongUsage("<number>") | ||
| val first = args.first() | ||
| val prNumber = first.toIntOrNull() ?: run { | ||
| userError("Unknown number $PLEADING_FACE ($first})") | ||
| return | ||
| } | ||
| if (prNumber < 1) { | ||
| userError("PR number needs to be positive $PLEADING_FACE") | ||
| return | ||
| } | ||
|
|
||
| if (!isFromType(ChannelType.GUILD_PUBLIC_THREAD)) { | ||
| userError("Wrong channel $PLEADING_FACE") | ||
| return | ||
| } | ||
|
|
||
| val post = channel.asThreadChannel() | ||
| val manager = post.manager | ||
|
|
||
| if (Database.isLinked(post.id)) { | ||
| reply("Post already linked to ${Database.getPullrequest(channel.id)} $PLEADING_FACE") | ||
| return | ||
| } | ||
|
|
||
| Database.addLink(post.id, prNumber) | ||
| logAction("${author.name} linked pr $prNumber") | ||
|
|
||
| if (!post.name.contains("(PR #")) manager.setTitle("${post.name} (PR #$prNumber)") | ||
|
|
||
| val tags = post.appliedTags | ||
| if (tags.none { it.id == OPEN_PR_TAG }) { | ||
| val tag = post.parentChannel.asForumChannel().getAvailableTagById(OPEN_PR_TAG) ?: return | ||
| manager.setTags(tags + tag) | ||
| } | ||
|
|
||
| userSuccess("Successfully linked PR $prNumber to this post.") | ||
| } | ||
|
|
||
| fun ThreadChannelManager.setTags(tags: List<ForumTag>) { | ||
| setAppliedTags(tags).queue() | ||
| } | ||
|
|
||
| fun ThreadChannelManager.setTitle(name: String) { | ||
| setName(name).queue() | ||
| } | ||
| } | ||
|
|
||
| object UnlinkCommand : BaseCommand() { | ||
| override val name = "unlink" | ||
|
|
||
| override val description = "Unlink a forum post from a pull request." | ||
|
|
||
| override fun MessageReceivedEvent.execute(args: List<String>) { | ||
| if (!isFromType(ChannelType.GUILD_PUBLIC_THREAD)) { | ||
| userError("Wrong channel $PLEADING_FACE") | ||
| return | ||
| } | ||
|
|
||
| if (!Database.isLinked(channel.id)) { | ||
| userError("Post isn't linked to any pull request $PLEADING_FACE") | ||
| return | ||
| } | ||
|
|
||
| val post = channel.asThreadChannel() | ||
| val manager = post.manager | ||
|
|
||
| Database.deleteLink(post.id) | ||
| logAction("${author.name} unlinked the pull request") | ||
|
|
||
| if (post.name.contains("(PR #")) manager.setTitle(post.name.split("(PR #")[0]) | ||
|
|
||
| val tags = post.appliedTags | ||
| if (tags.any { it.id == OPEN_PR_TAG }) { | ||
| val tag = post.parentChannel.asForumChannel().getAvailableTagById(OPEN_PR_TAG) ?: return | ||
| manager.setTags(tags.filter { it != tag }) | ||
| } | ||
|
|
||
| userSuccess("Successfully unlinked this post.") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.