audit-labs/audit-tools
A collection of scripts, queries, and other goodies you can use in an audit.
clone: git clone https://gitbay.org/audit-labs/audit-tools.git
main: applications/github/collectors/api.py · raw
1"""Shared GitHub API helper."""
2
3import requests
4
5
6def paginate(url, cfg, params=None):
7 """Fetch all pages from a GitHub API endpoint and return combined results."""
8 results = []
9 p = dict(params or {})
10 p["per_page"] = 100
11 page = 1
12
13 while True:
14 p["page"] = page
15 resp = requests.get(
16 url, headers=cfg["headers"], params=p, timeout=cfg["timeout"]
17 )
18 resp.raise_for_status()
19 data = resp.json()
20 if not data:
21 break
22 results.extend(data)
23 if "next" not in resp.links:
24 break
25 page += 1
26
27 return results