Skip to content
Open
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions sanicbot/extensions/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from discord.ext import commands
from discord.ext.commands import Context

from sanicbot.core.config import config
from sanicbot.core.utils import failure_message, success_message


Expand Down Expand Up @@ -44,6 +45,26 @@ async def retrieve_github_issue(
repo = f"sanic-{repo}"
await self.lookup(ctx, number, repo)

@commands.command()
async def issue(self, ctx: Context, repo: str, title: str, *, content: str) -> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a worthwhile command, however it would be better implemented using slash sub-commands. Considering what @ahopkins mentioned about a GH client, sub-commands would make things easier.

repo = repo if not repo.startswith("sanic") else "sanic-" + repo
url = f"https://api.github.com/repos/sanic-org/{repo}/issues"
body = f"Forwarded from discord (Author: {ctx.author}, ID: {ctx.author.id})\n" + content
data = {
"title": title,
"body": body,
}
headers = {
"Accept": "application/vnd.github.v3+json",
"Authorization": "token " + config["SANIC"]["git_token"]
}
async with httpx.AsyncClient() as client:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by extending the commands.Bot class (see PR #8 for implementation) we can attach a bot-level httpclient so we're not creating a new client each time a command is called.

response = await client.post(url, data=data, headers=headers)
if response.status_code == 200:
await success_message(ctx, "Issue created\n" + response.json()["url"])
else:
await failure_message(ctx, "An error occured: `" + response.json()["message"] + "`")
Comment on lines +61 to +66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be premature for now, but it would be nice to abstract some of this into a GH client.

Copy link

@airsho airsho Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be set up like so: /gh create issue whereas issue lookup could be set up like: /gh issue 2559 and PRs /gh pr 352, could display lists of issues/PRs with pagination: /gh issues 1 and /gh prs 1


@commands.Cog.listener('on_message')
async def github_issue_message_listener(self, message: Message):
if not message.author.bot:
Expand Down