github-nippou 2.0.0.beta3 → 2.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 395e6dc886fa422488530971c407766a8e9f40a2
4
- data.tar.gz: d28cc82a0bf38888a818a4ad8b98bc42e9d0896a
3
+ metadata.gz: e04ff32f953611852d55ee08062486083beda4c6
4
+ data.tar.gz: 678f97c55b3b566e561c97b903fac0f517edea6e
5
5
  SHA512:
6
- metadata.gz: d37a77092bcb34e48fc2351a4165e2a7adf18e506cd057dd7057faadc98ad97c2dd3c4b27ffe477c4b83662cfcc5cddb40a951c30eee2473fa80c4c670956e97
7
- data.tar.gz: c1a5a7c61ffa5b14a4f93cf148c2adf5997ee4b602db560d83536451b9abf5b049dd28bcd8f1cd67ae4873e94d6103c6bdd779b8722751584897ad917ced8283
6
+ metadata.gz: 73d1e69a9dd7ca65092a4e6b58d8194fcb1057c4b024eb69e3cf459cb1dc3a1fc5620159b6e25ea79368aeed818ccee5eb0343bb7c32870c30a4255da787a6f4
7
+ data.tar.gz: db8c91944b4d351c16c75263e89d66a5c7a92ef17acffd61edc576100cc748d336be022426c738d13011e589e82db5b95829d8bb0964e2af34bb30567ca86183
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github-nippou (2.0.0.beta3)
4
+ github-nippou (2.0.0.beta4)
5
5
  activesupport
6
6
  octokit
7
7
  thor
data/README.md CHANGED
@@ -33,6 +33,7 @@ $ github-nippou help
33
33
  Commands:
34
34
  github-nippou help [COMMAND] # Describe available commands or one specific command
35
35
  github-nippou list # Displays today's GitHub events formatted for Nippou
36
+ github-nippou version # Displays version
36
37
 
37
38
  Options:
38
39
  s, [--since-date=SINCE_DATE] # Retrieves GitHub user_events since the date
data/lib/github/nippou.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'github/nippou/concerns/sawyer_resource_github'
2
+ require 'github/nippou/concerns/string_markdown'
3
+
1
4
  require 'github/nippou/commands'
2
5
  require 'github/nippou/user_events'
3
6
  require 'github/nippou/version'
@@ -1,17 +1,10 @@
1
1
  require 'thor'
2
2
 
3
- module StringExMarkdown
4
- refine String do
5
- def markdown_escape
6
- self.gsub(/([`<>])/, '\\\\\1')
7
- end
8
- end
9
- end
10
-
11
3
  module Github
12
4
  module Nippou
13
5
  class Commands < Thor
14
- using StringExMarkdown
6
+ using SawyerResourceGithub
7
+ using StringMarkdown
15
8
 
16
9
  default_task :list
17
10
  class_option :since_date, type: :string,
@@ -23,11 +16,13 @@ module Github
23
16
 
24
17
  desc 'list', "Displays today's GitHub events formatted for Nippou"
25
18
  def list
26
- nippous.each do |url, detail|
27
- line = "* [#{detail[:title]} - #{detail[:repo_basename]}](#{url}) by #{detail[:username]}"
28
- if detail[:merged]
19
+ user_events.each do |user_event|
20
+ issue = user_event.issue(client)
21
+ line = "* [%s - %s](%s) by %s" %
22
+ [issue.title.markdown_escape, user_event.repo.name, user_event.html_url, issue.user.login]
23
+ if issue.merged
29
24
  line << ' **merged!**'
30
- elsif detail[:state] == 'closed'
25
+ elsif issue.state == 'closed'
31
26
  line << ' **closed!**'
32
27
  end
33
28
  puts line
@@ -41,27 +36,10 @@ module Github
41
36
 
42
37
  private
43
38
 
44
- def nippous
45
- result = {}
46
-
47
- user_events.each do |user_event|
48
- case user_event.type
49
- when 'IssuesEvent', 'IssueCommentEvent'
50
- issue = user_event.payload.issue
51
- result[issue.html_url] ||= hash_for_issue(user_event.repo.name, issue.number)
52
- when 'PullRequestEvent', 'PullRequestReviewCommentEvent'
53
- pr = user_event.payload.pull_request
54
- result[pr.html_url] ||= hash_for_pr(user_event.repo.name, pr.number)
55
- end
56
- end
57
-
58
- result.sort
59
- end
60
-
61
39
  def user_events
62
40
  @user_events ||= UserEvents.new(
63
41
  client, user, options[:since_date], options[:until_date]
64
- ).retrieve
42
+ ).collect
65
43
  end
66
44
 
67
45
  def client
@@ -106,30 +84,6 @@ MESSAGE
106
84
  exit!
107
85
  end
108
86
  end
109
-
110
- def hash_for_issue(repo_name, issue_number)
111
- issue = client.issue(repo_name, issue_number)
112
-
113
- {
114
- title: issue.title.markdown_escape,
115
- repo_basename: repo_name,
116
- username: issue.user.login,
117
- merged: issue.merged,
118
- state: issue.state,
119
- }
120
- end
121
-
122
- def hash_for_pr(repo_name, pr_number)
123
- pr = client.pull_request(repo_name, pr_number)
124
-
125
- {
126
- title: pr.title.markdown_escape,
127
- repo_basename: repo_name,
128
- username: pr.user.login,
129
- merged: pr.merged,
130
- state: pr.state,
131
- }
132
- end
133
87
  end
134
88
  end
135
89
  end
@@ -0,0 +1,33 @@
1
+ require 'octokit'
2
+
3
+ module SawyerResourceGithub
4
+ refine Sawyer::Resource do
5
+ def issue(client)
6
+ case
7
+ when self.issue?
8
+ client.issue(self.repo.name, self.payload.issue.number)
9
+ when self.pull_request?
10
+ client.pull_request(self.repo.name, self.payload.pull_request.number)
11
+ end
12
+ end
13
+
14
+ def html_url
15
+ case
16
+ when self.issue?
17
+ self.payload.issue.html_url
18
+ when self.pull_request?
19
+ self.payload.pull_request.html_url
20
+ end
21
+ end
22
+
23
+ def issue?
24
+ self.type == 'IssuesEvent' ||
25
+ self.type == 'IssueCommentEvent'
26
+ end
27
+
28
+ def pull_request?
29
+ self.type == 'PullRequestEvent' ||
30
+ self.type == 'PullRequestReviewCommentEvent'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ module StringMarkdown
2
+ refine String do
3
+ def markdown_escape
4
+ self.gsub(/([`<>])/, '\\\\\1')
5
+ end
6
+ end
7
+ end
@@ -4,13 +4,22 @@ require 'octokit'
4
4
  module Github
5
5
  module Nippou
6
6
  class UserEvents
7
+ using SawyerResourceGithub
8
+
7
9
  def initialize(client, user, since_date, until_date)
8
10
  @client = client
9
11
  @user = user
10
- @since_date = Time.parse(since_date).beginning_of_day
11
- @until_date = Time.parse(until_date).end_of_day
12
+ @since_time = Time.parse(since_date).beginning_of_day
13
+ until_time = Time.parse(until_date).end_of_day
14
+ @range = @since_time..until_time
15
+ end
16
+
17
+ def collect
18
+ uniq(sort(filter(retrieve)))
12
19
  end
13
20
 
21
+ private
22
+
14
23
  def retrieve
15
24
  user_events = @client.user_events(@user, per_page: 100)
16
25
  last_response = @client.last_response
@@ -23,15 +32,31 @@ module Github
23
32
  user_events.select { |user_event| in_range?(user_event) }
24
33
  end
25
34
 
26
- private
27
-
28
35
  def continue?(last_response, user_events)
29
36
  last_response.rels[:next] &&
30
- user_events.last.created_at.getlocal >= @since_date
37
+ user_events.last.created_at.getlocal >= @since_time
31
38
  end
32
39
 
33
40
  def in_range?(user_event)
34
- (@since_date..@until_date).include?(user_event.created_at.getlocal)
41
+ @range.include?(user_event.created_at.getlocal)
42
+ end
43
+
44
+ def filter(user_events)
45
+ user_events.select do |user_event|
46
+ user_event.issue? || user_event.pull_request?
47
+ end
48
+ end
49
+
50
+ def sort(user_events)
51
+ user_events.sort do |a, b|
52
+ a.html_url <=> b.html_url
53
+ end
54
+ end
55
+
56
+ def uniq(user_events)
57
+ user_events.uniq do |user_event|
58
+ user_event.html_url
59
+ end
35
60
  end
36
61
  end
37
62
  end
@@ -1,5 +1,5 @@
1
1
  module Github
2
2
  module Nippou
3
- VERSION = '2.0.0.beta3'
3
+ VERSION = '2.0.0.beta4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-nippou
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta3
4
+ version: 2.0.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Masuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-26 00:00:00.000000000 Z
11
+ date: 2016-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -100,6 +100,8 @@ files:
100
100
  - github-nippou.gemspec
101
101
  - lib/github/nippou.rb
102
102
  - lib/github/nippou/commands.rb
103
+ - lib/github/nippou/concerns/sawyer_resource_github.rb
104
+ - lib/github/nippou/concerns/string_markdown.rb
103
105
  - lib/github/nippou/user_events.rb
104
106
  - lib/github/nippou/version.rb
105
107
  homepage: https://github.com/masutaka/github-nippou