Skip to content

Instantly share code, notes, and snippets.

@fpinzn
Last active October 8, 2020 04:49
Show Gist options
  • Save fpinzn/a04174e9ad4741edfd1d5ea76bce9474 to your computer and use it in GitHub Desktop.
Save fpinzn/a04174e9ad4741edfd1d5ea76bce9474 to your computer and use it in GitHub Desktop.
## Average life of all PRs in the organization
  1. Auth

Simple auth using a token retrieved from the github ui.

curl -u fpinzn:token https://api.github.com/user

  1. Get all PRs from a repo https://api.github.com/repos/vlipco/waybox-api/pulls

  2. Get all repos from an organization

curl -u fpinzn:token https://api.github.com/orgs/vlipco/repos

  1. List of open PRs title, created_at, and closed_at

... 'https://api.github.com/repos/vlipco/waybox-api/pulls?state=open' | jq '.[] | {title: .title, created_at: .created_at, closed_at: .closed_at}'

  1. List of repo names ordered descendetly from the most recently pushed (max 100 per page)

... 'https://api.github.com/orgs/vlipco/repos?type=all&per_page=100&sort=pushed' | jq '.[] | .name'

  1. List of endpoints to get all open prs of all repos

... 'https://api.github.com/orgs/vlipco/repos?type=all&per_page=100&sort=pushed' | jq '.[] | "https://api.github.com/repos/vlipco/\(.name)/pulls?state=open"'

  1. List of open PRs for all repos including repo, title, author, created_at, body and requested_reviewers
API_TOKEN=token; curl -u fpinzn:$API_TOKEN 'https://api.github.com/orgs/vlipco/repos?type=all&per_page=100&sort=pushed' | jq '.[] | "https://api.github.com/repos/vlipco/\(.name)/pulls?state=open"' | xargs curl -u fpinzn:$API_TOKEN | jq '.[] | {repo: .head.repo.name, title: .title, author: .user.login, created_at: .created_at, requested_reviewers: (.requested_reviewers | .[] | .login), body: .body}'
  1. Date of creation of all PRs
API_TOKEN=token; curl -u fpinzn:$API_TOKEN 'https://api.github.com/orgs/vlipco/repos?type=all&per_page=100&sort=pushed' | jq '.[] | "https://api.github.com/repos/vlipco/\(.name)/pulls?state=open"' | xargs curl -u fpinzn:$API_TOKEN | jq '.[] | .created_at'
  1. Average of days all PRs in the 100 repos with the most recent pushes have been open
API_TOKEN=token; curl -u fpinzn:$API_TOKEN 'https://api.github.com/orgs/vlipco/repos?type=all&per_page=100&sort=pushed' | jq '.[] | "https://api.github.com/repos/vlipco/\(.name)/pulls?state=open"' | xargs curl -u fpinzn:$API_TOKEN | jq '.[] | .created_at' | xargs ruby -e "require 'date'; puts ARGV.reduce(0) {|sum_of_days, date| sum_of_days + (DateTime.now.new_offset - DateTime.parse(date)).to_i }/ ARGV.count"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment