-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathget_contents.py
More file actions
29 lines (22 loc) · 892 Bytes
/
get_contents.py
File metadata and controls
29 lines (22 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from lib.base import BaseGithubAction
from lib.formatters import contents_to_dict
__all__ = [
'GetContentsAction'
]
class GetContentsAction(BaseGithubAction):
def run(self, user, repo, ref, path, decode=False):
user = self._client.get_user(user)
repo = user.get_repo(repo)
contents = repo.get_contents(path, ref=ref)
result = contents_to_dict(contents=contents, decode=decode)
return result
if __name__ == '__main__':
import os
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN')
GITHUB_ORG = os.environ.get('GITHUB_ORG')
GITHUB_REPO = os.environ.get('GITHUB_REPO')
act = GetContentsAction(config={'token': GITHUB_TOKEN, 'github_type': 'online'})
res = act.run(user=GITHUB_ORG, repo=GITHUB_REPO, ref='branch1', path='README.md', decode=True)
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(res)