Skip to content

Commit

Permalink
add support for private github repos
Browse files Browse the repository at this point in the history
  • Loading branch information
brentpicasso committed Oct 18, 2024
1 parent 9bfa3eb commit 1068a81
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class Recipe(metaclass=RecipeMeta):
if you want.
'''

_github_access_token = None
'''Used to access a private git repository. Specify the github-supplied
access token in order to download the private repository files.
'''

_version = None
'''A string giving the version of the software the recipe describes,
e.g. ``2.0.3`` or ``master``.'''
Expand Down Expand Up @@ -170,6 +175,11 @@ def versioned_url(self):
return None
return self.url.format(version=self.version)

@property
def github_access_token(self):
key = "GITHUB_ACCESS_TOKEN_" + self.name
return environ.get(key, self._github_access_token)

def download_file(self, url, target, cwd=None):
"""
(internal) Download an ``url`` to a ``target``.
Expand Down Expand Up @@ -205,6 +215,9 @@ def report_hook(index, blksize, size):
# jqueryui.com returns a 403 w/ the default user agent
# Mozilla/5.0 doesnt handle redirection for liblzma
url_opener.addheaders = [('User-agent', 'Wget/1.0')]
if self.github_access_token:
url_opener.addheaders += [('Authorization', f'token {self.github_access_token}'),
('Accept', 'application/vnd.github.v3.raw')]
urlretrieve(url, target, report_hook)
except OSError as e:
attempts += 1
Expand Down

0 comments on commit 1068a81

Please sign in to comment.