ticketguy commited on
Commit
b3b7ad8
·
verified ·
1 Parent(s): cff6c87

Upload fetch_repo.py

Browse files
Files changed (1) hide show
  1. fetch_repo.py +23 -0
fetch_repo.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests, json, sys, base64, os
2
+
3
+ def fetch_tree(owner, repo, token=None, branch='main'):
4
+ headers = {'Accept': 'application/vnd.github.v3+json'}
5
+ if token:
6
+ headers['Authorization'] = f'token {token}'
7
+ url = f'https://api.github.com/repos/{owner}/{repo}/git/trees/{branch}?recursive=1'
8
+ r = requests.get(url, headers=headers)
9
+ print('status', r.status_code)
10
+ if r.status_code == 200:
11
+ data = r.json()
12
+ for item in data.get('tree', []):
13
+ print(item['path'])
14
+ else:
15
+ print(r.text[:500])
16
+
17
+ if __name__ == '__main__':
18
+ token = os.environ.get('GITHUB_PAT')
19
+ fetch_tree('ticketguy', 'littlefig', token)
20
+ print('---')
21
+ fetch_tree('ticketguy', 'Lila', token)
22
+ print('---')
23
+ fetch_tree('ticketguy', 'embers-diaries', token)