Last active
August 29, 2015 14:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
ruby '2.1.5' | |
gem 'i18n' | |
gem 'activesupport' | |
gem 'octokit' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
account: | |
id: userid | |
access_token: github accesstoken | |
output: | |
date_format: '%Y/%m/%d %a.' | |
name: 名前 |
Gemfile に activesupport が入ってるけど特に使ってない 🙈
前回から日付出力するのに active_support/time
は使ってる。
今回、実行時に日付指定できるようにした。未指定の場合は本日の日報が作られる。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
までやったので一旦上げてみる。