| import requests, json, sys, base64, os | |
| def fetch_tree(owner, repo, token=None, branch='main'): | |
| headers = {'Accept': 'application/vnd.github.v3+json'} | |
| if token: | |
| headers['Authorization'] = f'token {token}' | |
| url = f'https://api.github.com/repos/{owner}/{repo}/git/trees/{branch}?recursive=1' | |
| r = requests.get(url, headers=headers) | |
| print('status', r.status_code) | |
| if r.status_code == 200: | |
| data = r.json() | |
| for item in data.get('tree', []): | |
| print(item['path']) | |
| else: | |
| print(r.text[:500]) | |
| if __name__ == '__main__': | |
| token = os.environ.get('GITHUB_PAT') | |
| fetch_tree('ticketguy', 'littlefig', token) | |
| print('---') | |
| fetch_tree('ticketguy', 'Lila', token) | |
| print('---') | |
| fetch_tree('ticketguy', 'embers-diaries', token) | |