github-nippou 2.0.0.beta4 → 2.0.0.beta5

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: e04ff32f953611852d55ee08062486083beda4c6
4
- data.tar.gz: 678f97c55b3b566e561c97b903fac0f517edea6e
3
+ metadata.gz: 5c0359c1b0c93e33e07c49a4642968c84af8eb4a
4
+ data.tar.gz: aeee0e7c9a0732b7a237785c83862033e357d003
5
5
  SHA512:
6
- metadata.gz: 73d1e69a9dd7ca65092a4e6b58d8194fcb1057c4b024eb69e3cf459cb1dc3a1fc5620159b6e25ea79368aeed818ccee5eb0343bb7c32870c30a4255da787a6f4
7
- data.tar.gz: db8c91944b4d351c16c75263e89d66a5c7a92ef17acffd61edc576100cc748d336be022426c738d13011e589e82db5b95829d8bb0964e2af34bb30567ca86183
6
+ metadata.gz: da2634a1fb6c171d8f9e6ed5d557458576b44971322d4ebf1c6bf07ba8eb692d35733ab17fd4cb7bff7af49a854bf7e8024f191b1a2946c1e88d5967aedbd189
7
+ data.tar.gz: 0ec755b2b786478253bcca2b613faaf98bb9c43830eb081316ac9ab9059b031f0f5984a314522a3595949507007f8b8961136131796f20ca00f57f480a84ff3e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github-nippou (2.0.0.beta4)
4
+ github-nippou (2.0.0.beta5)
5
5
  activesupport
6
6
  octokit
7
7
  thor
@@ -16,17 +16,22 @@ module Github
16
16
 
17
17
  desc 'list', "Displays today's GitHub events formatted for Nippou"
18
18
  def list
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
24
- line << ' **merged!**'
25
- elsif issue.state == 'closed'
26
- line << ' **closed!**'
19
+ 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
27
30
  end
28
- puts line
29
31
  end
32
+ threads.each(&:join)
33
+
34
+ puts sort(lines)
30
35
  end
31
36
 
32
37
  desc 'version', 'Displays version'
@@ -42,6 +47,35 @@ module Github
42
47
  ).collect
43
48
  end
44
49
 
50
+ def format_line(user_event, i)
51
+ puts "#{i} : #{user_event.html_url}" if ENV['GITHUB_NIPPOU_DEBUG']
52
+ issue = issue(user_event)
53
+ line = "* [%s - %s](%s) by %s" %
54
+ [issue.title.markdown_escape, user_event.repo.name, user_event.html_url, issue.user.login]
55
+
56
+ if issue.merged
57
+ line << ' **merged!**'
58
+ elsif issue.state == 'closed'
59
+ line << ' **closed!**'
60
+ end
61
+
62
+ line
63
+ end
64
+
65
+ def issue(user_event)
66
+ if user_event.issue?
67
+ client.issue(user_event.repo.name, user_event.payload.issue.number)
68
+ else
69
+ client.pull_request(user_event.repo.name, user_event.payload.pull_request.number)
70
+ end
71
+ end
72
+
73
+ def sort(lines)
74
+ lines.sort do |a, b|
75
+ a.html_url_as_nippou <=> b.html_url_as_nippou
76
+ end
77
+ end
78
+
45
79
  def client
46
80
  @client ||= Octokit::Client.new(login: user, access_token: access_token)
47
81
  end
@@ -84,6 +118,18 @@ MESSAGE
84
118
  exit!
85
119
  end
86
120
  end
121
+
122
+ def thread_num
123
+ @thread_num ||=
124
+ case
125
+ when ENV['GITHUB_NIPPOU_THREAD_NUM']
126
+ ENV['GITHUB_NIPPOU_THREAD_NUM']
127
+ when !`git config github-nippou.thread-num`.chomp.empty?
128
+ `git config github-nippou.thread-num`.chomp
129
+ else
130
+ 5
131
+ end.to_i
132
+ end
87
133
  end
88
134
  end
89
135
  end
@@ -2,15 +2,6 @@ require 'octokit'
2
2
 
3
3
  module SawyerResourceGithub
4
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
5
  def html_url
15
6
  case
16
7
  when self.issue?
@@ -3,5 +3,10 @@ module StringMarkdown
3
3
  def markdown_escape
4
4
  self.gsub(/([`<>])/, '\\\\\1')
5
5
  end
6
+
7
+ def html_url_as_nippou
8
+ self =~ /^\* \[.+\]\((.+)\)/
9
+ $1
10
+ end
6
11
  end
7
12
  end
@@ -15,7 +15,7 @@ module Github
15
15
  end
16
16
 
17
17
  def collect
18
- uniq(sort(filter(retrieve)))
18
+ uniq(filter(retrieve))
19
19
  end
20
20
 
21
21
  private
@@ -47,12 +47,6 @@ module Github
47
47
  end
48
48
  end
49
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
50
  def uniq(user_events)
57
51
  user_events.uniq do |user_event|
58
52
  user_event.html_url
@@ -1,5 +1,5 @@
1
1
  module Github
2
2
  module Nippou
3
- VERSION = '2.0.0.beta4'
3
+ VERSION = '2.0.0.beta5'
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.beta4
4
+ version: 2.0.0.beta5
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-27 00:00:00.000000000 Z
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport