Skip to content

Instantly share code, notes, and snippets.

@v1v
Created March 12, 2024 15:32
Show Gist options
  • Save v1v/187728021437e95ca3e8c8db9fccc479 to your computer and use it in GitHub Desktop.
Save v1v/187728021437e95ca3e8c8db9fccc479 to your computer and use it in GitHub Desktop.
gather the last 7 day workflow runs for the given GitHub org
#!/usr/bin/env python3
import logging
import os
from github import Auth, Github
def cli() -> None:
auth = Auth.Token(os.getenv("GITHUB_API_TOKEN"))
g = Github(auth=auth)
gh_repos = g.get_organization("your-repo").get_repos(sort="full_name", direction="asc")
command = "gh run list --jq ' .[]| select(.createdAt > (now-( 7 * 86400) | strftime(\"%Y-%m-%dT%H-%M-%SZ\") ))' --json conclusion,databaseId,createdAt,name --limit 1000"
for repo in gh_repos:
logging.info("Inspect %s", repo.full_name)
os.system(f"{command} --repo {repo.full_name} > out/{repo.name}.json")
if __name__ == "__main__":
logging.basicConfig(format="[%(levelname)s] %(message)s", level="INFO", stream=sys.stderr)
# pylint: disable=E1120
cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment