diff --git a/Gemfile.lock b/Gemfile.lock index 6420399..bdf63d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -27,4 +27,4 @@ DEPENDENCIES rake (~> 10.0) BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/lib/github/nippou.rb b/lib/github/nippou.rb index a8c0ce9..186cb17 100644 --- a/lib/github/nippou.rb +++ b/lib/github/nippou.rb @@ -1,63 +1,73 @@ require 'github/nippou/version' require 'octokit' +module StringExMarkdown + refine String do + def markdown_escape + self.gsub('`', '\\\`') + end + end +end + module Github module Nippou - def self.list - user = self.user - client = Octokit::Client.new(login: user, access_token: self.access_token) - events = client.user_events(user) + class << self + using StringExMarkdown - url_to_detail = {} + def list + nippous = {} + now = Time.now - events.each do |_| - break unless _.created_at.getlocal.to_date == Time.now.to_date - case _.type - when 'IssuesEvent', 'IssueCommentEvent' - title = _.payload.issue.title.gsub('`', '\\\`') - merged = client.pull_merged?(_.repo.name, _.payload.issue.number) - url_to_detail[_.payload.issue.html_url] ||= {title: title, repo_basename: _.repo.name, username: _.payload.issue.user.login, merged: merged} - when 'PullRequestEvent', 'PullRequestReviewCommentEvent' - title = _.payload.pull_request.title.gsub('`', '\\\`') - merged = client.pull_merged?(_.repo.name, _.payload.pull_request.number) - url_to_detail[_.payload.pull_request.html_url] ||= {title: title, repo_basename: _.repo.name, username: _.payload.pull_request.user.login, merged: merged} + client.user_events(user).each do |event| + break unless event.created_at.getlocal.to_date == now.to_date + case event.type + when 'IssuesEvent', 'IssueCommentEvent' + issue = event.payload.issue + nippous[issue.html_url] ||= hash_for_issue(event.repo, issue) + when 'PullRequestEvent', 'PullRequestReviewCommentEvent' + pr = event.payload.pull_request + nippous[pr.html_url] ||= hash_for_pr(event.repo, pr) + end end - end - url_to_detail.each do |url, detail| - line = "* [#{detail[:title]} - #{detail[:repo_basename]}](#{url}) by #{detail[:username]}" - line << ' **merged!**' if detail[:merged] - puts line + nippous.each do |url, detail| + line = "* [#{detail[:title]} - #{detail[:repo_basename]}](#{url}) by #{detail[:username]}" + line << ' **merged!**' if detail[:merged] + puts line + end end - end - private + private + + def client + @client ||= Octokit::Client.new(login: user, access_token: access_token) + end - def self.user - case - when ENV['GITHUB_NIPPOU_USER'] - ENV['GITHUB_NIPPOU_USER'] - when !`git config github-nippou.user`.chomp.empty? - `git config github-nippou.user`.chomp - else - puts <