Githubで今日なにをしたか、調べるスクリプトを書いた

こんにちは。ブログの最終投稿日時が99日前で「意識が低まっているのでは?」と言われちゃったきたけーです。最近、春の陽気につられて意識も高まってきたので、リハビリします。

最近、会社のその日の業務内容の報告にGithub(ペパボではGH:Eもつかっている)のpullreqとかissueのタイトルとURLを貼っつけています。 終業間際にGithubの画面をブラウザで開いて、いちいちリンクとかタイトルをコピーするのが面倒だったので簡単なスクリプトを書きました。

require 'octokit'

client = Octokit::Client.new(login: 'kitak', access_token: 'githubの/settings/applicationsで発行したトークン')
events = client.user_events('kitak')

url_to_detail = {}

events.each do |_|
  break unless _.created_at.getlocal.to_date == Time.now.to_date
  case _.type
  when "IssuesEvent"
    url_to_detail[_.payload.issue.html_url] ||= {title: _.payload.issue.title, comments: []}
  when "IssueCommentEvent"
    url_to_detail[_.payload.issue.html_url] ||= {title: _.payload.issue.title, comments: []}
    url_to_detail[_.payload.issue.html_url][:comments] << _.payload.comment.html_url
  when "PullRequestEvent"
    url_to_detail[_.payload.pull_request.html_url] ||= {title: _.payload.pull_request.title, comments: []}
  end
end

url_to_detail.each do |url, detail|
  puts "- #{detail[:title]} #{url}"
  detail[:comments].reverse.each do |comment|
    puts "  * #{comment}"
  end
end

出力はこんなかんじ。

- パスワードを再設定できるようにする https://github.com/mamebro/mameblo/pull/152
  * https://github.com/mamebro/mameblo/pull/152#issuecomment-40911787
- paperboyなURLをpepaboに変更 https://github.com/kitak/about_p/pull/97
  * https://github.com/kitak/about_p/pull/97#issuecomment-39665740
- 個別の投稿・近況を取得するAPIを作成する https://github.com/mamebro/mameblo/pull/118
  * https://github.com/mamebro/mameblo/pull/118#issuecomment-37750837
  * https://github.com/mamebro/mameblo/pull/118#issuecomment-37751686
  * https://github.com/mamebro/mameblo/pull/118#issuecomment-37755731
  * https://github.com/mamebro/mameblo/pull/118#issuecomment-37758864
  * https://github.com/mamebro/mameblo/pull/118#issuecomment-37776595
  * https://github.com/mamebro/mameblo/pull/118#issuecomment-37804472
- Entry と Bean の関連の定義を修正しました (`has_many beans`) https://github.com/mamebro/mameblo/pull/126

いらなかったらコメントのURLを除いたり、適宜微修正して、日報に貼り付けるだけ。便利。 他にも色々イベントが取れるので( https://developer.github.com/v3/activity/events/types/ )もっとうまくコードを書いたり、出力できるかも。