-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_github_workflows.py
More file actions
28 lines (24 loc) · 961 Bytes
/
print_github_workflows.py
File metadata and controls
28 lines (24 loc) · 961 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
import pprint
import requests
"""
Find all the repos in a given org and print out their workflow names and badge url
example workflow: https://github.com/actions/starter-workflows/actions/workflows/auto_assign.yml
output structure: { "repo_name_1": [ {"workflow_name_1": "workflow_badge_1"} ] }
"""
# TODO: Add try/catch around http requests and possibly cache request result
base_url = "https://api.github.com"
org = "actions"
# Choose page 2/2 to conserve api calls & prevent throttling
response1 = requests.get(f"{base_url}/orgs/{org}/repos?page=2")
repos = response1.json()
result = {}
for repo in repos:
name = repo['name']
result[name] = []
response2 = requests.get(f"{base_url}/{org}/{name}/actions/workflows")
workflows = response2.json()['workflows']
for workflow in workflows:
wf_dict = {workflow['name']: workflow['badge_url']}
result[name].append(wf_dict)
pp = pprint.PrettyPrinter(depth=4)
pp.pprint(result)