diff options
| author | 2020-09-19 20:38:30 -0400 | |
|---|---|---|
| committer | 2020-09-19 20:38:57 -0400 | |
| commit | 157cc184c075287eb24a765b15430f2530d44bae (patch) | |
| tree | 11df8c1cd96f7a3fb4c9b05cc3aec7cddb74c628 /bot/exts/evergreen | |
| parent | Invoke help command when no PRs/issues are given (diff) | |
Authenticate with the GitHub API to allow for more requests
Diffstat (limited to 'bot/exts/evergreen')
| -rw-r--r-- | bot/exts/evergreen/issues.py | 10 | 
1 files changed, 7 insertions, 3 deletions
| diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index e128ae50..15c97473 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -4,7 +4,7 @@ import random  import discord  from discord.ext import commands -from bot.constants import Channels, Colours, Emojis, ERROR_REPLIES, WHITELISTED_CHANNELS +from bot.constants import Channels, Colours, Emojis, ERROR_REPLIES, Tokens, WHITELISTED_CHANNELS  from bot.utils.decorators import override_in_channel  log = logging.getLogger(__name__) @@ -16,6 +16,10 @@ BAD_RESPONSE = {  MAX_REQUESTS = 10 +REQUEST_HEADERS = dict() +if GITHUB_TOKEN := Tokens.github: +    REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}" +  class Issues(commands.Cog):      """Cog that allows users to retrieve issues from GitHub.""" @@ -30,7 +34,7 @@ class Issues(commands.Cog):          ctx: commands.Context,          numbers: commands.Greedy[int],          repository: str = "seasonalbot", -            user: str = "python-discord" +        user: str = "python-discord"      ) -> None:          """Command to retrieve issue(s) from a GitHub repository."""          links = [] @@ -55,7 +59,7 @@ class Issues(commands.Cog):              merge_url = f"https://api.github.com/repos/{user}/{repository}/pulls/{number}/merge"              log.trace(f"Querying GH issues API: {url}") -            async with self.bot.http_session.get(url) as r: +            async with self.bot.http_session.get(url, headers=REQUEST_HEADERS) as r:                  json_data = await r.json()              if r.status in BAD_RESPONSE: | 
