github-nippou 2.0.1 → 2.1.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: cb50931c5196a3030d97920f992dbd0af7212a57
4
- data.tar.gz: c1c8fd70dde75fdf2e022397ef9fecf1df6d84d5
3
+ metadata.gz: 0ef358687064ffbca6c80ab96136c0a81c36e154
4
+ data.tar.gz: adddcb9ff77d0afddfa4da8c177d10e0f8cb7bab
5
5
  SHA512:
6
- metadata.gz: 0c19ba1b9b71c6de198b437d89aa34e9c16e45b2aee201b690c9df559bf22912bc4e6d6baf0538eed9f348dce2a0da2163bc402ee7f99c4103143f8da22cc7d3
7
- data.tar.gz: 6d10d77b9724a27964da34d757347694fa98d0d1581aa4633747cb1e077e3f5e0879eec5733e1277701d21391469f196493fd4b5e0b0d2a820e26c290cfe5d9a
6
+ metadata.gz: 1ff50591fd5d01d3c6ca25fcc5818e6ece3576f907ab92e671f8a96294840cfa1bab5f9ed6a562532ee6c803dec0c2af1134710febc1514aa4e68aa2950a73ed
7
+ data.tar.gz: b5461b0c1b574930aa9b3add56abd818292a38f55a7def443c96fe8483f47db9595bfc0fd04a20191bc15a05f49a083e8de6ceb7bc1c25d497767042f78d3c53
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github-nippou (2.0.1)
4
+ github-nippou (2.1.0.beta1)
5
5
  activesupport
6
6
  octokit
7
7
  parallel
@@ -10,23 +10,22 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (4.2.6)
13
+ activesupport (5.0.0)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
15
  i18n (~> 0.7)
15
- json (~> 1.7, >= 1.7.7)
16
16
  minitest (~> 5.1)
17
- thread_safe (~> 0.3, >= 0.3.4)
18
17
  tzinfo (~> 1.1)
19
18
  addressable (2.4.0)
19
+ concurrent-ruby (1.0.2)
20
20
  faraday (0.9.2)
21
21
  multipart-post (>= 1.2, < 3)
22
22
  i18n (0.7.0)
23
- json (1.8.3)
24
- minitest (5.8.4)
23
+ minitest (5.9.0)
25
24
  multipart-post (2.0.0)
26
25
  octokit (4.3.0)
27
26
  sawyer (~> 0.7.0, >= 0.5.3)
28
- parallel (1.8.0)
29
- rake (11.1.1)
27
+ parallel (1.9.0)
28
+ rake (11.2.2)
30
29
  sawyer (0.7.0)
31
30
  addressable (>= 2.3.5, < 2.5)
32
31
  faraday (~> 0.8, < 0.10)
@@ -44,4 +43,4 @@ DEPENDENCIES
44
43
  rake
45
44
 
46
45
  BUNDLED WITH
47
- 1.11.2
46
+ 1.12.5
data/lib/github/nippou.rb CHANGED
@@ -2,5 +2,6 @@ require 'github/nippou/concerns/sawyer_resource_github'
2
2
  require 'github/nippou/concerns/string_markdown'
3
3
 
4
4
  require 'github/nippou/commands'
5
+ require 'github/nippou/format'
5
6
  require 'github/nippou/user_events'
6
7
  require 'github/nippou/version'
@@ -4,9 +4,6 @@ require 'thor'
4
4
  module Github
5
5
  module Nippou
6
6
  class Commands < Thor
7
- using SawyerResourceGithub
8
- using StringMarkdown
9
-
10
7
  default_task :list
11
8
  class_option :since_date, type: :string,
12
9
  default: Time.now.strftime('%Y%m%d'),
@@ -20,13 +17,16 @@ module Github
20
17
  def list
21
18
  lines = []
22
19
  mutex = Mutex::new
20
+ format = Format.new(client, thread_num, debug)
23
21
 
24
22
  Parallel.each_with_index(user_events, in_threads: thread_num) do |user_event, i|
25
- line = format_line(user_event, i)
23
+ # Contain GitHub access.
24
+ # So should not put into the mutex block.
25
+ line = format.line(user_event, i)
26
26
  mutex.synchronize { lines << line }
27
27
  end
28
28
 
29
- puts sort(lines)
29
+ puts format.all(lines)
30
30
  end
31
31
 
32
32
  desc 'version', 'Displays version'
@@ -42,39 +42,6 @@ module Github
42
42
  ).collect
43
43
  end
44
44
 
45
- def format_line(user_event, i)
46
- STDERR.puts "#{i % thread_num} : #{user_event.html_url}\n" if debug
47
- issue = issue(user_event)
48
- line = "* [%s - %s](%s) by %s" %
49
- [issue.title.markdown_escape, user_event.repo.name, user_event.html_url, issue.user.login]
50
-
51
- if issue.merged
52
- line << ' **merged!**'
53
- elsif issue.state == 'closed'
54
- line << ' **closed!**'
55
- end
56
-
57
- line
58
- end
59
-
60
- def issue(user_event)
61
- case
62
- when user_event.payload.pull_request
63
- client.pull_request(user_event.repo.name, user_event.payload.pull_request.number)
64
- when user_event.payload.issue.pull_request
65
- # a pull_request like an issue
66
- client.pull_request(user_event.repo.name, user_event.payload.issue.number)
67
- else
68
- client.issue(user_event.repo.name, user_event.payload.issue.number)
69
- end
70
- end
71
-
72
- def sort(lines)
73
- lines.sort do |a, b|
74
- a.markdown_html_url <=> b.markdown_html_url
75
- end
76
- end
77
-
78
45
  def client
79
46
  @client ||= Octokit::Client.new(login: user, access_token: access_token)
80
47
  end
@@ -3,10 +3,5 @@ module StringMarkdown
3
3
  def markdown_escape
4
4
  self.gsub(/([`<>])/, '\\\\\1')
5
5
  end
6
-
7
- def markdown_html_url
8
- self =~ /^\* \[.+\]\((.+)\)/
9
- $1
10
- end
11
6
  end
12
7
  end
@@ -0,0 +1,84 @@
1
+ module Github
2
+ module Nippou
3
+ class Format
4
+ using SawyerResourceGithub
5
+ using StringMarkdown
6
+
7
+ def initialize(client, thread_num, debug)
8
+ @client = client
9
+ @thread_num = thread_num
10
+ @debug = debug
11
+ end
12
+
13
+ def line(user_event, i)
14
+ STDERR.puts "#{i % @thread_num} : #{user_event.html_url}\n" if @debug
15
+ issue = issue(user_event)
16
+
17
+ line = {
18
+ title: issue.title,
19
+ repo_name: user_event.repo.name,
20
+ url: user_event.html_url,
21
+ user: issue.user.login,
22
+ }
23
+
24
+ line[:status] =
25
+ if issue.merged
26
+ :merged
27
+ elsif issue.state == 'closed'
28
+ :closed
29
+ end
30
+
31
+ line
32
+ end
33
+
34
+ def all(lines)
35
+ result = ""
36
+ prev_repo_name = nil
37
+ curr_repo_name = nil
38
+
39
+ sort(lines).each do |line|
40
+ current_repo_name = line[:repo_name]
41
+
42
+ unless current_repo_name == prev_repo_name
43
+ prev_repo_name = current_repo_name
44
+ result << "\n### #{current_repo_name}\n\n"
45
+ end
46
+
47
+ result << "* [%s](%s) by %s%s\n" %
48
+ [line[:title].markdown_escape, line[:url], line[:user], format_status(line[:status])]
49
+ end
50
+
51
+ result
52
+ end
53
+
54
+ private
55
+
56
+ def issue(user_event)
57
+ case
58
+ when user_event.payload.pull_request
59
+ @client.pull_request(user_event.repo.name, user_event.payload.pull_request.number)
60
+ when user_event.payload.issue.pull_request
61
+ # a pull_request like an issue
62
+ @client.pull_request(user_event.repo.name, user_event.payload.issue.number)
63
+ else
64
+ @client.issue(user_event.repo.name, user_event.payload.issue.number)
65
+ end
66
+ end
67
+
68
+ def sort(lines)
69
+ lines.sort { |a, b| a[:url] <=> b[:url] }
70
+ end
71
+
72
+ def format_status(status)
73
+ case status
74
+ when :merged
75
+ ' **merged!**'
76
+ when :closed
77
+ ' **closed!**'
78
+ else
79
+ ''
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,5 +1,5 @@
1
1
  module Github
2
2
  module Nippou
3
- VERSION = '2.0.1'
3
+ VERSION = '2.1.0.beta1'
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.1
4
+ version: 2.1.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-04-10 00:00:00.000000000 Z
11
+ date: 2016-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -116,6 +116,7 @@ files:
116
116
  - lib/github/nippou/commands.rb
117
117
  - lib/github/nippou/concerns/sawyer_resource_github.rb
118
118
  - lib/github/nippou/concerns/string_markdown.rb
119
+ - lib/github/nippou/format.rb
119
120
  - lib/github/nippou/user_events.rb
120
121
  - lib/github/nippou/version.rb
121
122
  homepage: https://github.com/masutaka/github-nippou
@@ -133,9 +134,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
134
  version: '0'
134
135
  required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  requirements:
136
- - - ">="
137
+ - - ">"
137
138
  - !ruby/object:Gem::Version
138
- version: '0'
139
+ version: 1.3.1
139
140
  requirements: []
140
141
  rubyforge_project:
141
142
  rubygems_version: 2.5.1