github-nippou 1.2.0 → 2.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2fc65a5d317d5e2fb3eb3981317283b208ce4c3
4
- data.tar.gz: 5dc2731edf57ac227fb2ac9945462c99149d0d36
3
+ metadata.gz: 7f0f13ef8692fd47c64b7406283ad0aa0fc38591
4
+ data.tar.gz: 567ff11a390184d4e85e1c7ca04f02d74d25a7d7
5
5
  SHA512:
6
- metadata.gz: c605539e14192e274703a38b015ec784d13adf475e8809d400d81e605356858f347c9acb1413542d7e7dc0906297aee199fb9ffe48bb7d0523bc5c4c8c1dbb7d
7
- data.tar.gz: 42f9b41d7ca288574f6bf553818fe07b6cf682da28eac025950588f22dce9af0763c83483f0ba230877b2917e8190d60710ca5b2e4310b64057a22b52f8f7319
6
+ metadata.gz: 7173ae0ab09b35cff1bc6529f231fc1d6ddff2605134d591409493fef445d231932ee2b5ceb3b0fd50acbf792e2353040d216860ceac7ae733f2c9fa4816549a
7
+ data.tar.gz: 4e234ec0584549fb6eaa188f73acbf8037db618730d845a66e4cac520c48cf6acad5b98467c9599e0111fa604ed560c49733136ef80c690d63ee732b83b0c056
data/Gemfile.lock CHANGED
@@ -1,16 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github-nippou (1.2.0)
4
+ github-nippou (2.0.0.beta1)
5
+ activesupport
5
6
  octokit
6
7
  thor
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
12
+ activesupport (4.2.6)
13
+ i18n (~> 0.7)
14
+ json (~> 1.7, >= 1.7.7)
15
+ minitest (~> 5.1)
16
+ thread_safe (~> 0.3, >= 0.3.4)
17
+ tzinfo (~> 1.1)
11
18
  addressable (2.4.0)
12
19
  faraday (0.9.2)
13
20
  multipart-post (>= 1.2, < 3)
21
+ i18n (0.7.0)
22
+ json (1.8.3)
23
+ minitest (5.8.4)
14
24
  multipart-post (2.0.0)
15
25
  octokit (4.3.0)
16
26
  sawyer (~> 0.7.0, >= 0.5.3)
@@ -19,6 +29,9 @@ GEM
19
29
  addressable (>= 2.3.5, < 2.5)
20
30
  faraday (~> 0.8, < 0.10)
21
31
  thor (0.19.1)
32
+ thread_safe (0.3.5)
33
+ tzinfo (1.2.2)
34
+ thread_safe (~> 0.1)
22
35
 
23
36
  PLATFORMS
24
37
  ruby
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ['lib']
22
22
 
23
+ spec.add_dependency 'activesupport'
23
24
  spec.add_dependency 'octokit'
24
25
  spec.add_dependency 'thor'
25
26
 
data/lib/github/nippou.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'github/nippou/commands'
2
+ require 'github/nippou/user_events'
2
3
  require 'github/nippou/version'
@@ -1,4 +1,3 @@
1
- require 'octokit'
2
1
  require 'thor'
3
2
 
4
3
  module StringExMarkdown
@@ -15,8 +14,9 @@ module Github
15
14
  using StringExMarkdown
16
15
 
17
16
  default_task :list
18
- class_option :all, type: :boolean, aliases: :a, desc: 'Also displays GitHub events before today'
19
- class_option :num, type: :numeric, default: 50, aliases: :n, desc: 'GitHub event numbers that retrieve from GitHub'
17
+ class_option :since_date, type: :string,
18
+ default: Time.now.strftime('%Y%m%d'),
19
+ aliases: :s, desc: 'Retrieves GitHub user_events since the date'
20
20
 
21
21
  desc 'list', "Displays today's GitHub events formatted for Nippou"
22
22
  def list
@@ -35,30 +35,25 @@ module Github
35
35
 
36
36
  def nippous
37
37
  result = {}
38
- now = Time.now
39
38
 
40
- client.user_events(user, per_page: options[:num]).each do |event|
41
- break if skip?(event, now)
42
-
43
- case event.type
39
+ user_events.each do |user_event|
40
+ case user_event.type
44
41
  when 'IssuesEvent', 'IssueCommentEvent'
45
- issue = event.payload.issue
46
- result[issue.html_url] ||= hash_for_issue(event.repo, issue)
42
+ issue = user_event.payload.issue
43
+ result[issue.html_url] ||= hash_for_issue(user_event.repo.name, issue.number)
47
44
  when 'PullRequestEvent', 'PullRequestReviewCommentEvent'
48
- pr = event.payload.pull_request
49
- result[pr.html_url] ||= hash_for_pr(event.repo, pr)
45
+ pr = user_event.payload.pull_request
46
+ result[pr.html_url] ||= hash_for_pr(user_event.repo.name, pr.number)
50
47
  end
51
48
  end
52
49
 
53
50
  result.sort
54
51
  end
55
52
 
56
- def skip?(event, now)
57
- if options[:all]
58
- false
59
- else
60
- event.created_at.getlocal.to_date != now.to_date
61
- end
53
+ def user_events
54
+ @user_events ||= UserEvents.new(
55
+ client, user, options[:since_date]
56
+ ).retrieve
62
57
  end
63
58
 
64
59
  def client
@@ -104,18 +99,28 @@ MESSAGE
104
99
  end
105
100
  end
106
101
 
107
- def hash_for_issue(repo, issue)
108
- title = issue.title.markdown_escape
109
- merged = client.pull_merged?(repo.name, issue.number)
110
- state = client.issue(repo.name, issue.number).state
111
- {title: title, repo_basename: repo.name, username: issue.user.login, merged: merged, state: state}
102
+ def hash_for_issue(repo_name, issue_number)
103
+ issue = client.issue(repo_name, issue_number)
104
+
105
+ {
106
+ title: issue.title.markdown_escape,
107
+ repo_basename: repo_name,
108
+ username: issue.user.login,
109
+ merged: client.pull_merged?(repo_name, issue.number),
110
+ state: issue.state,
111
+ }
112
112
  end
113
113
 
114
- def hash_for_pr(repo, pr)
115
- title = pr.title.markdown_escape
116
- merged = client.pull_merged?(repo.name, pr.number)
117
- state = client.pull_request(repo.name, pr.number).state
118
- {title: title, repo_basename: repo.name, username: pr.user.login, merged: merged, state: state}
114
+ def hash_for_pr(repo_name, pr_number)
115
+ pr = client.pull_request(repo_name, pr_number)
116
+
117
+ {
118
+ title: pr.title.markdown_escape,
119
+ repo_basename: repo_name,
120
+ username: pr.user.login,
121
+ merged: client.pull_merged?(repo_name, pr.number),
122
+ state: pr.state,
123
+ }
119
124
  end
120
125
  end
121
126
  end
@@ -0,0 +1,32 @@
1
+ require 'active_support/time'
2
+ require 'octokit'
3
+
4
+ module Github
5
+ module Nippou
6
+ class UserEvents
7
+ def initialize(client, user, since_date)
8
+ @client = client
9
+ @user = user
10
+ @range = Time.parse(since_date)..Time.now.end_of_day
11
+ end
12
+
13
+ def retrieve
14
+ user_events = @client.user_events(@user)
15
+ last_response = @client.last_response
16
+
17
+ while last_response.rels[:next] && in_range?(user_events.last)
18
+ last_response = last_response.rels[:next].get
19
+ user_events.concat(last_response.data)
20
+ end
21
+
22
+ user_events.select { |user_event| in_range?(user_event) }
23
+ end
24
+
25
+ private
26
+
27
+ def in_range?(user_event)
28
+ @range.include?(user_event.created_at.getlocal)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  module Github
2
2
  module Nippou
3
- VERSION = '1.2.0'
3
+ VERSION = '2.0.0.beta1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-nippou
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0.beta1
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-23 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: octokit
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +100,7 @@ files:
86
100
  - github-nippou.gemspec
87
101
  - lib/github/nippou.rb
88
102
  - lib/github/nippou/commands.rb
103
+ - lib/github/nippou/user_events.rb
89
104
  - lib/github/nippou/version.rb
90
105
  homepage: https://github.com/masutaka/github-nippou
91
106
  licenses:
@@ -102,12 +117,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
117
  version: '0'
103
118
  required_rubygems_version: !ruby/object:Gem::Requirement
104
119
  requirements:
105
- - - ">="
120
+ - - ">"
106
121
  - !ruby/object:Gem::Version
107
- version: '0'
122
+ version: 1.3.1
108
123
  requirements: []
109
124
  rubyforge_project:
110
- rubygems_version: 2.4.8
125
+ rubygems_version: 2.5.1
111
126
  signing_key:
112
127
  specification_version: 4
113
128
  summary: Print today's your GitHub action.