From fae731e925ca76b534b10ce0472f014ddf816fde Mon Sep 17 00:00:00 2001 From: Piyush Bhangale Date: Fri, 21 Feb 2020 10:30:33 +0530 Subject: [PATCH 1/4] feat: add github_token in config --- core/config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/config.py b/core/config.py index a0eda4a2dc..f9097e737e 100644 --- a/core/config.py +++ b/core/config.py @@ -110,6 +110,8 @@ class ConfigManager: "owners": None, # bot "token": None, + # github access token for private repositories + "github_token": None # Logging "log_level": "INFO", "enable_plugins": True, From 8b127b5e1fc43ad1a11036ae3ed5710de5fc2d34 Mon Sep 17 00:00:00 2001 From: Piyush Bhangale Date: Fri, 21 Feb 2020 10:36:02 +0530 Subject: [PATCH 2/4] feat: add authorization header if present --- cogs/plugins.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cogs/plugins.py b/cogs/plugins.py index e4543d2f1e..e8b7095c0c 100644 --- a/cogs/plugins.py +++ b/cogs/plugins.py @@ -154,7 +154,10 @@ async def download_plugin(self, plugin, force=False): logger.debug("Loading cached %s.", plugin.cache_path) else: - async with self.bot.session.get(plugin.url) as resp: + headers = {} + if self.bot.config.get("github_token") is not None: + headers["Authorization"] = f"token {self.bot.config.get('github_token')}" + async with self.bot.session.get(plugin.url, headers=headers) as resp: logger.debug("Downloading %s.", plugin.url) raw = await resp.read() plugin_io = io.BytesIO(raw) From 5aa1f007ddbcf7e0cb93fb9a0bc7e351cc903525 Mon Sep 17 00:00:00 2001 From: Piyush Bhangale Date: Fri, 21 Feb 2020 10:38:26 +0530 Subject: [PATCH 3/4] fix: add a missing comma --- core/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/config.py b/core/config.py index f9097e737e..9b2763aa55 100644 --- a/core/config.py +++ b/core/config.py @@ -111,7 +111,7 @@ class ConfigManager: # bot "token": None, # github access token for private repositories - "github_token": None + "github_token": None, # Logging "log_level": "INFO", "enable_plugins": True, From fcacfb6071f3d18c4a1a3265ea42bd48e75ceaa7 Mon Sep 17 00:00:00 2001 From: Taaku18 <45324516+Taaku18@users.noreply.github.com> Date: Tue, 9 Jun 2020 02:40:04 -0700 Subject: [PATCH 4/4] Add to changelog and bump version --- CHANGELOG.md | 3 ++- bot.py | 2 +- cogs/plugins.py | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f82dcdc294..baa39edb39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,14 @@ This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2. however, insignificant breaking changes do not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319). If you're a plugins developer, note the "BREAKING" section. -# v3.5.0dev3 +# v3.5.0dev4 ### Added - A confirmation when you manually delete a thread message embed. - Config var `enable_eval` defaults true, set `enable_eval=no` to disable the eval command. (GH #2803) - Added `?plugins reset` command to completely reset everything related to plugins. This will fix some problems caused by broken plugins in the file system. +- Support private GitHub repos for plugins (thanks to @officialpiyush pr#2767) ### Changed diff --git a/bot.py b/bot.py index 2d0d66f047..28d786b3a9 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,4 @@ -__version__ = "3.5.0-dev3" +__version__ = "3.5.0-dev4" import asyncio diff --git a/cogs/plugins.py b/cogs/plugins.py index 74881f81f8..8ea358bcb3 100644 --- a/cogs/plugins.py +++ b/cogs/plugins.py @@ -157,11 +157,12 @@ async def download_plugin(self, plugin, force=False): if plugin.cache_path.exists() and not force: plugin_io = plugin.cache_path.open("rb") logger.debug("Loading cached %s.", plugin.cache_path) - else: headers = {} - if self.bot.config.get("github_token") is not None: - headers["Authorization"] = f"token {self.bot.config.get('github_token')}" + github_token = self.bot.config.get("github_token") + if github_token is not None: + headers["Authorization"] = f"token {github_token}" + async with self.bot.session.get(plugin.url, headers=headers) as resp: logger.debug("Downloading %s.", plugin.url) raw = await resp.read()