LoginSignup
7
5

More than 5 years have passed since last update.

Githubのリポジトリのスター数の日ごとの遷移を見る

Last updated at Posted at 2016-12-17

やりたいこと

Github上の任意のPublicリポジトリで時系列でスター数の遷移をだしたい。

やったこと

先に結果(?)です

データ取ってくるスクリプト
get_repo_stars.sh(Gist)

出したグラフ(スター数の遷移)

スクリーンショット 2016-12-18 4.44.25.png

やりかた

GithubのAPIで取ります。今回使うAPIは認証不要の機能です。

つかうAPIはこれです。
List Stargazers

ドキュメントにも書いてありますが、スターがついた日時を出すのは、以下の Accept ヘッダーが必要です。

Accept: application/vnd.github.v3.star+json

たとえば、 simeji/jid の各スターがつけられた日時を取りたいときは以下のようにします。

curl -s "https://api.github.com/repos/simeji/jid/stargazers?page=1&per_page=100" -H "Accept: application/vnd.github.v3.star+json" | jq -r '.[].starred_at'

ただ、このAPIは100件ごとしか取れないので、自動的にやろうと思ったら、

curl -s https://api.github.com/repos/simeji/jid | jq .stargazers_count

で取れた件数からページ数を算出してその分だけループさせます。

で、取れた日時の値を日と時間に分割して完了。
あとはそれを Googleのスプレッドシートやエクセルに貼り付けて、日毎にまとめたりしてグラフ作りたければつくります。

上記をまとめたシェルスクリプトが以下のスクリプト
get_repo_stars.sh(Gist)
です。

さいごに

スター数がどのように遷移してきたかを見てみると少し面白いですね。

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5