Skip to content

Instantly share code, notes, and snippets.

@exoego
Last active March 16, 2022 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exoego/1b1380dca387acaf17b26ac166077c9a to your computer and use it in GitHub Desktop.
Save exoego/1b1380dca387acaf17b26ac166077c9a to your computer and use it in GitHub Desktop.
Fetch .ruby-version in company repo
#!/bin/zsh
OWNER=my-company
gh search repos \
--owner=$OWNER \
--language=ruby \
--visibility=private \
--archived=false \
--json="name,defaultBranch" \
--limit=200 \
> repos.json
result="repo, last_updated_at, .ruby_version\n"
for line in `cat repos.json | jq '.[] | .name + "@" + .defaultBranch' --raw-output`; do
parts=(${(@s/@/)line})
repo=$parts[1]
defaultBranch=$parts[2]
lastUpdatedAt=$(gh api repos/$OWNER/$repo/commits/$defaultBranch | jq '.commit.author.date' --raw-output)
ruby_version=$(gh api repos/$OWNER/$repo/contents/.ruby-version --header="Accept: application/vnd.github.VERSION.raw")
if [[ $ruby_version == *"Found"* ]]; then
result+="$repo, $lastUpdatedAt, not found\n"
else
result+="$repo, $lastUpdatedAt, $ruby_version\n"
fi
done
echo $result > result.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment