Skip to content

Commit a8bb2fe

Browse files
rewrite github related code (#738)
Rewrite the entirety of GitHub issue/pull handling code. closes GH-571 closes GH-320 closes GH-564 closes GH-564 Key refactors: - use a renderer system for each type of resource having a class based renderer, rather than a whole bunch of Ifs - centralized configuration for all behavioral changes by any configuration or feature set - standardized behavior - removal of the show more/less button, replaced with the show more button which shows a modal rather than more contents - smaller limits on the size of the embed - proper mixing of different types, such as a link and shorthand in the same message - properly follow and display source repository when an issue/discussion has been transferred to a different repository - mirror the emoji colors to the embed colour - when displaying comments, use the same coloured embeds that Discord webhooks use. - provide the correct html_url for mannequin users - provide the correct username/login for mannequin users on comment embeds --------- Signed-off-by: Zenith <me@arielle.codes> Co-authored-by: vi <8530778+shiftinv@users.noreply.github.com>
1 parent 814c830 commit a8bb2fe

14 files changed

Lines changed: 1915 additions & 1356 deletions

docs/commands/app-commands.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,16 @@ bots.
246246

247247
Fetches info from GitHub.
248248

249-
### `github`
249+
### `github info`
250250

251-
- `arg` (`string`) (required) Can be a org/repo#number, a link to an issue or
252-
issue comment, and more.
251+
- `arg` (`string`) (required) The GitHub resource to view . Can be a URL or
252+
shorthand like owner/repo#issue_number.
253253

254-
View information about an issue, pull, discussion, or comment on GitHub.
254+
Fetch GitHub information.
255255

256256
**Usable in:** `Guilds`, `Bot DMs`, `Private Channels`
257257

258-
**Installable as:** `Guild`
258+
**Installable as:** `Guild`, `User`
259259

260260
## Guild Config
261261

docs/commands/prefix-commands.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,29 +141,21 @@ Management commands for bot features.
141141

142142
Fetches info from GitHub.
143143

144-
### `github [user_or_repo=]`
144+
### `github [args...]`
145145

146-
*Commands for finding information related to GitHub.*
146+
*Group for GitHub related commands.*
147147

148-
**Can also use:** `gh`, `git`
148+
**Can also use:** `gh`
149149

150-
### `github issue <numbers> <repo> [user=None]`
150+
### `github repo <user_and_repo> [repo=]`
151151

152-
*Command to retrieve issue(s) from a GitHub repository.*
152+
*Fetch GitHub repository information.*
153153

154-
**Can also use:** `github pr`, `github pull`
154+
**Can also use:** `github repo_info`, `github repository`
155155

156-
### `github repository [repository...]`
156+
### `github user <user>`
157157

158-
*Fetches a repositories' GitHub information.*
159-
160-
**Can also use:** `github repo`, `repo`
161-
162-
### `github user <username>`
163-
164-
*Fetches a user's GitHub information.*
165-
166-
**Can also use:** `github userinfo`
158+
*Fetch GitHub user information.*
167159

168160
## Help
169161

monty/constants.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ class GHColour(int, enum.Enum):
240240
attention = 0x9A6700
241241
default = 0x1F2328
242242

243+
# These are used by Discord
244+
issue_comment = 0xE68D60
245+
pull_comment = 0xBFE5BF
246+
243247

244248
## DEPRECATED
245249
# TODO: Will be replaced in favour of application emojis
@@ -329,6 +333,11 @@ class AppEmojisCls(BaseModel, arbitrary_types_allowed=True):
329333
file_name="discussion-closed",
330334
color=GHColour.done,
331335
)
336+
discussion_closed_unresolved: AppEmojiAnn = Octicon(
337+
name="gh-discussion-closed-unresolved",
338+
file_name="comment-discussion",
339+
color=GHColour.muted,
340+
)
332341
discussion_outdated: AppEmojiAnn = Octicon(
333342
name="gh-discussion-outdated",
334343
file_name="discussion-outdated",
@@ -349,8 +358,18 @@ class AppEmojisCls(BaseModel, arbitrary_types_allowed=True):
349358
file_name="issue-closed",
350359
color=GHColour.done,
351360
)
361+
issue_closed_generic: AppEmojiAnn = Octicon(
362+
name="gh-skip",
363+
file_name="skip",
364+
color=GHColour.muted,
365+
)
352366
issue_closed_unplanned: AppEmojiAnn = Octicon(
353-
name="gh-issue-closed-unplanned",
367+
name="gh-skip",
368+
file_name="skip",
369+
color=GHColour.muted,
370+
)
371+
issue_closed_duplicate: AppEmojiAnn = Octicon(
372+
name="gh-skip",
354373
file_name="skip",
355374
color=GHColour.muted,
356375
)
@@ -395,9 +414,14 @@ class Feature(enum.Enum):
395414
DISCORD_TOKEN_REMOVER = "DISCORD_BOT_TOKEN_FILTER" # noqa: S105
396415
DISCORD_WEBHOOK_REMOVER = "DISCORD_WEBHOOK_FILTER"
397416
GITHUB_COMMENT_LINKS = "GITHUB_EXPAND_COMMENT_LINKS"
417+
"Controls whether or not GitHub comment links are expanded into embeds. Requires GITHUB_ISSUE_LINKS to be enabled."
398418
GITHUB_DISCUSSIONS = "GITHUB_AUTOLINK_DISCUSSIONS"
399-
GITHUB_ISSUE_EXPAND = "GITHUB_AUTOLINK_ISSUE_SHOW_DESCRIPTION"
419+
"Controls whether or not GitHub Discussions are automatically linked. Requires GITHUB_ISSUE_LINKS to be enabled."
400420
GITHUB_ISSUE_LINKS = "GITHUB_EXPAND_ISSUE_LINKS"
421+
"Controls whether or not GitHub embeds are replaced with Monty's Embeds."
422+
# Deprecated, NO-OP
423+
GITHUB_ISSUE_EXPAND = "GITHUB_AUTOLINK_ISSUE_SHOW_DESCRIPTION"
424+
"Controls whether or not GitHub Embeds are expanded to show more information. Requires GITHUB_ISSUE_LINKS."
401425
GLOBAL_SOURCE = "GLOBAL_SOURCE_COMMAND"
402426
INLINE_DOCS = "INLINE_DOCUMENTATION"
403427
INLINE_EVALULATION = "INLINE_EVALULATION"

monty/exts/info/github/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from .cog import GithubInfo
2+
3+
4+
TYPE_CHECKING = 0
5+
6+
if TYPE_CHECKING:
7+
from monty.bot import Monty
8+
9+
10+
def setup(bot: "Monty") -> None:
11+
"""Setup the Github Info cog."""
12+
bot.add_cog(GithubInfo(bot))

0 commit comments

Comments
 (0)