Skip to content

Instantly share code, notes, and snippets.

@tmd45
Last active August 29, 2015 14:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tmd45/fb7ed75c74172ef27916 to your computer and use it in GitHub Desktop.
Save tmd45/fb7ed75c74172ef27916 to your computer and use it in GitHub Desktop.
nippo.rb; refs. Githubで今日なにをしたか、調べるスクリプトを書いた - きたけーTechブログ http://kitak.hatenablog.jp/entry/2014/04/22/013849
source 'https://rubygems.org'
ruby '2.1.5'
gem 'i18n'
gem 'activesupport'
gem 'octokit'
##
# Qiita:Team に日報投稿するための下書きを出力する
#
# ### 実行方法
#
# $ bundle exec ruby nippo.rb
#
# 日付指定したい場合
#
# $ bundle exec ruby nippo.rb '20150701'
#
require 'yaml'
require 'rubygems'
require 'active_support'
require 'active_support/time'
require 'octokit'
date = ARGV[0].blank? ? Time.now : Time.parse(ARGV[0].to_s)
config = YAML.load_file('nippo.yml')
@github = []
account = config['account']
client = Octokit::Client.new(login: account['id'], access_token: account['access_token'])
events = client.user_events(account['id'])
output = config['output']
url_to_detail = {}
events.each do |_|
break unless _.created_at.getlocal.to_date == date.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.body.split.join(' ')
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
url_to_detail.each do |url, detail|
@github << "- [#{detail[:title]}](#{url})"
end
puts(<<EOL)
# #{date.strftime(output['date_format'])} #{output['name']}
## 本日の目標と実績
#{@github.join("\n")}
## 発生した問題
## 明日の目標
## 所感
EOL
account:
id: userid
access_token: github accesstoken
output:
date_format: '%Y/%m/%d %a.'
name: 名前
@tmd45
Copy link
Author

tmd45 commented Jun 17, 2014

  • コメントの URL じゃなくてコメントそのものを出力
  • リストのインデントを TAB に変更
  • アカウント情報の外出し

までやったので一旦上げてみる。

@tmd45
Copy link
Author

tmd45 commented Jun 17, 2014

Gemfile に activesupport が入ってるけど特に使ってない 🙈

@tmd45
Copy link
Author

tmd45 commented Aug 20, 2014

前回から日付出力するのに active_support/time は使ってる。
今回、実行時に日付指定できるようにした。未指定の場合は本日の日報が作られる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment