github-nippou 2.0.0.beta5 → 2.0.0.beta6

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: 5c0359c1b0c93e33e07c49a4642968c84af8eb4a
4
- data.tar.gz: aeee0e7c9a0732b7a237785c83862033e357d003
3
+ metadata.gz: 79390fbd81c7c4d4b3d1fe9443f882ab52f8d894
4
+ data.tar.gz: 10a6ee01658bf337a39f8599e018536e8c0593a9
5
5
  SHA512:
6
- metadata.gz: da2634a1fb6c171d8f9e6ed5d557458576b44971322d4ebf1c6bf07ba8eb692d35733ab17fd4cb7bff7af49a854bf7e8024f191b1a2946c1e88d5967aedbd189
7
- data.tar.gz: 0ec755b2b786478253bcca2b613faaf98bb9c43830eb081316ac9ab9059b031f0f5984a314522a3595949507007f8b8961136131796f20ca00f57f480a84ff3e
6
+ metadata.gz: 63d33966ebd8cd63886832a68f0c490845cb1e896942c807fe2ef5a1c196684385bbdc4786d188608ccb1df87f9f27dbbc3262d0c21a253a4e50a26751edb0e4
7
+ data.tar.gz: eb3430e7111a0750764415f258196e8331b7f7ee5699e08f23d06f0f09ce4f122fdc5167cc104a09ebca9a40d0936a0d0462f4c0be71039a5a3a2e34e75d72bd
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github-nippou (2.0.0.beta5)
4
+ github-nippou (2.0.0.beta6)
5
5
  activesupport
6
6
  octokit
7
+ parallel
7
8
  thor
8
9
 
9
10
  GEM
@@ -24,6 +25,7 @@ GEM
24
25
  multipart-post (2.0.0)
25
26
  octokit (4.3.0)
26
27
  sawyer (~> 0.7.0, >= 0.5.3)
28
+ parallel (1.8.0)
27
29
  rake (11.1.1)
28
30
  sawyer (0.7.0)
29
31
  addressable (>= 2.3.5, < 2.5)
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency 'activesupport'
24
24
  spec.add_dependency 'octokit'
25
+ spec.add_dependency 'parallel'
25
26
  spec.add_dependency 'thor'
26
27
 
27
28
  spec.add_development_dependency 'bundler'
@@ -1,3 +1,4 @@
1
+ require 'parallel'
1
2
  require 'thor'
2
3
 
3
4
  module Github
@@ -17,19 +18,12 @@ module Github
17
18
  desc 'list', "Displays today's GitHub events formatted for Nippou"
18
19
  def list
19
20
  lines = []
20
- threads = []
21
- mutex1 = Mutex::new
22
- mutex2 = Mutex::new
23
-
24
- thread_num.times do |i|
25
- threads << Thread.start do
26
- while user_event = mutex1.synchronize { user_events.pop } do
27
- line = format_line(user_event, i)
28
- mutex2.synchronize { lines << line }
29
- end
30
- end
21
+ mutex = Mutex::new
22
+
23
+ Parallel.each_with_index(user_events, in_threads: thread_num) do |user_event, i|
24
+ line = format_line(user_event, i)
25
+ mutex.synchronize { lines << line }
31
26
  end
32
- threads.each(&:join)
33
27
 
34
28
  puts sort(lines)
35
29
  end
@@ -48,7 +42,7 @@ module Github
48
42
  end
49
43
 
50
44
  def format_line(user_event, i)
51
- puts "#{i} : #{user_event.html_url}" if ENV['GITHUB_NIPPOU_DEBUG']
45
+ puts "#{i % thread_num} : #{user_event.html_url}" if ENV['GITHUB_NIPPOU_DEBUG']
52
46
  issue = issue(user_event)
53
47
  line = "* [%s - %s](%s) by %s" %
54
48
  [issue.title.markdown_escape, user_event.repo.name, user_event.html_url, issue.user.login]
@@ -63,16 +57,20 @@ module Github
63
57
  end
64
58
 
65
59
  def issue(user_event)
66
- if user_event.issue?
67
- client.issue(user_event.repo.name, user_event.payload.issue.number)
68
- else
60
+ case
61
+ when user_event.payload.pull_request
69
62
  client.pull_request(user_event.repo.name, user_event.payload.pull_request.number)
63
+ when user_event.payload.issue.pull_request
64
+ # a pull_request like an issue
65
+ client.pull_request(user_event.repo.name, user_event.payload.issue.number)
66
+ else
67
+ client.issue(user_event.repo.name, user_event.payload.issue.number)
70
68
  end
71
69
  end
72
70
 
73
71
  def sort(lines)
74
72
  lines.sort do |a, b|
75
- a.html_url_as_nippou <=> b.html_url_as_nippou
73
+ a.markdown_html_url <=> b.markdown_html_url
76
74
  end
77
75
  end
78
76
 
@@ -3,22 +3,11 @@ require 'octokit'
3
3
  module SawyerResourceGithub
4
4
  refine Sawyer::Resource do
5
5
  def html_url
6
- case
7
- when self.issue?
8
- self.payload.issue.html_url
9
- when self.pull_request?
6
+ if self.payload.pull_request
10
7
  self.payload.pull_request.html_url
8
+ else
9
+ self.payload.issue.html_url
11
10
  end
12
11
  end
13
-
14
- def issue?
15
- self.type == 'IssuesEvent' ||
16
- self.type == 'IssueCommentEvent'
17
- end
18
-
19
- def pull_request?
20
- self.type == 'PullRequestEvent' ||
21
- self.type == 'PullRequestReviewCommentEvent'
22
- end
23
12
  end
24
13
  end
@@ -4,7 +4,7 @@ module StringMarkdown
4
4
  self.gsub(/([`<>])/, '\\\\\1')
5
5
  end
6
6
 
7
- def html_url_as_nippou
7
+ def markdown_html_url
8
8
  self =~ /^\* \[.+\]\((.+)\)/
9
9
  $1
10
10
  end
@@ -42,8 +42,11 @@ module Github
42
42
  end
43
43
 
44
44
  def filter(user_events)
45
+ elements = %w(IssuesEvent IssueCommentEvent
46
+ PullRequestEvent PullRequestReviewCommentEvent)
47
+
45
48
  user_events.select do |user_event|
46
- user_event.issue? || user_event.pull_request?
49
+ elements.include?(user_event.type)
47
50
  end
48
51
  end
49
52
 
@@ -1,5 +1,5 @@
1
1
  module Github
2
2
  module Nippou
3
- VERSION = '2.0.0.beta5'
3
+ VERSION = '2.0.0.beta6'
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.beta5
4
+ version: 2.0.0.beta6
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-29 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parallel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: thor
43
57
  requirement: !ruby/object:Gem::Requirement