From 0251652bce37847b61baf4aabe1d414ca3771280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Wed, 10 Aug 2022 15:07:40 +0200 Subject: [PATCH] Added support for private GitHub repositories (close #345) --- CB/GitHub.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/CB/GitHub.py b/CB/GitHub.py index 412756a..8745428 100644 --- a/CB/GitHub.py +++ b/CB/GitHub.py @@ -60,7 +60,9 @@ def parse(self): def parse_metadata(self): for release in self.payloads[self.releaseDepth]['assets']: if release['name'] and release['name'] == 'release.json': - self.metadata = requests.get(release['browser_download_url'], headers=HEADERS, timeout=5).json() + self.metadata = requests.get(release['url'], + headers=dict({'Accept': 'application/octet-stream'}, **HEADERS), + auth=APIAuth('token', self.apiKey), timeout=5).json() break else: self.metadata = None @@ -92,7 +94,7 @@ def get_latest_package(self): self.parse() for release in self.payloads[self.releaseDepth]['assets']: if release['name'] and release['name'] == targetfile: - self.downloadUrl = release['browser_download_url'] + self.downloadUrl = release['url'] break if not self.downloadUrl: self.releaseDepth += 1 @@ -108,13 +110,13 @@ def get_latest_package(self): if not latest and not release['name'].endswith('-classic.zip') and \ not release['name'].endswith('-bc.zip') and not release['name'].endswith('-bcc.zip') and \ not release['name'].endswith('-wrath.zip'): - latest = release['browser_download_url'] + latest = release['url'] elif not latestclassic and release['name'].endswith('-classic.zip'): - latestclassic = release['browser_download_url'] + latestclassic = release['url'] elif not latestbc and (release['name'].endswith('-bc.zip') or release['name'].endswith('-bcc.zip')): - latestbc = release['browser_download_url'] + latestbc = release['url'] elif not latestwrath and release['name'].endswith('-wrath.zip'): - latestwrath = release['browser_download_url'] + latestwrath = release['url'] if (self.clientType == 'retail' and latest) \ or (self.clientType == 'classic' and latest and not latestclassic) \ or (self.clientType == 'bc' and latest and not latestbc) \ @@ -132,7 +134,9 @@ def get_latest_package(self): @retry() def get_addon(self): - self.archive = zipfile.ZipFile(io.BytesIO(requests.get(self.downloadUrl, headers=HEADERS, timeout=5).content)) + self.archive = zipfile.ZipFile(io.BytesIO( + requests.get(self.downloadUrl, headers=dict({'Accept': 'application/octet-stream'}, **HEADERS), + auth=APIAuth('token', self.apiKey), timeout=5).content)) for file in self.archive.namelist(): if file.lower().endswith('.toc') and '/' not in file: raise RuntimeError(f'{self.name}.\nProject package is corrupted or incorrectly packaged.')