github-nippou 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Dockerfile +1 -1
- data/Gemfile.lock +3 -1
- data/README.md +18 -34
- data/github-nippou.gemspec +1 -0
- data/lib/github/nippou.rb +1 -0
- data/lib/github/nippou/commands.rb +8 -101
- data/lib/github/nippou/format.rb +5 -9
- data/lib/github/nippou/init.rb +165 -0
- data/lib/github/nippou/settings.rb +75 -6
- data/lib/github/nippou/version.rb +1 -1
- data/spec/github/nippou/init_spec.rb +9 -0
- data/spec/github/nippou/settings_spec.rb +46 -24
- data/spec/support/interface_init.rb +4 -0
- data/spec/support/interface_settings.rb +13 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 349f38fdb868cf41f91c42342cb661ed61b0b83b
|
4
|
+
data.tar.gz: 3c367704be774eaaec5fe1c7a1d06e257bbc1ae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96d3efeaee086c9271d186e9e3fb6fd9ac1b08a1fef591b14949cd3f355181e47098dcac6ac2402819ee2f67b80fceefba3e4108898002244872c158371335f2
|
7
|
+
data.tar.gz: e671dfbd90b1ed1d265aced4f02aeb3fd22328aa7e1b8c468b3873aa7eacc27198693aacd856f66e0bc7e655aded85f33e44c809ee857d87e44ea2a63377f777
|
data/.gitignore
CHANGED
data/Dockerfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
github-nippou (3.
|
4
|
+
github-nippou (3.2.0)
|
5
5
|
activesupport
|
6
6
|
highline
|
7
7
|
launchy
|
@@ -54,6 +54,7 @@ GEM
|
|
54
54
|
thread_safe (0.3.6)
|
55
55
|
tzinfo (1.2.3)
|
56
56
|
thread_safe (~> 0.1)
|
57
|
+
yard (0.9.9)
|
57
58
|
|
58
59
|
PLATFORMS
|
59
60
|
ruby
|
@@ -63,6 +64,7 @@ DEPENDENCIES
|
|
63
64
|
github-nippou!
|
64
65
|
rake
|
65
66
|
rspec
|
67
|
+
yard
|
66
68
|
|
67
69
|
BUNDLED WITH
|
68
70
|
1.15.3
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
[gem-link]: http://badge.fury.io/rb/github-nippou
|
13
13
|
[dockerhub]: https://hub.docker.com/r/masutaka/github-nippou/
|
14
14
|
|
15
|
-
|
15
|
+
Print today's your GitHub action.
|
16
16
|
|
17
17
|
This is a helpful tool when you write a daily report in reference to
|
18
18
|
GitHub. Nippou is a japanese word which means a daily report.
|
@@ -35,8 +35,13 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
## Setup
|
37
37
|
|
38
|
-
$
|
39
|
-
|
38
|
+
$ github-nippou init
|
39
|
+
|
40
|
+
The initialization will be update your `~/.gitconfig`.
|
41
|
+
|
42
|
+
1. Add `github-nippou.user`
|
43
|
+
2. Add `github-nippou.token`
|
44
|
+
3. Create Gist, and add `github-nippou.settings-gist-id` for customizing output format (optional)
|
40
45
|
|
41
46
|
## Usage
|
42
47
|
|
@@ -44,16 +49,16 @@ Or install it yourself as:
|
|
44
49
|
$ github-nippou help
|
45
50
|
Commands:
|
46
51
|
github-nippou help [COMMAND] # Describe available commands or one specific command
|
47
|
-
github-nippou init #
|
48
|
-
github-nippou list #
|
52
|
+
github-nippou init # Initialize github-nippou settings
|
53
|
+
github-nippou list # Print today's your GitHub action (Default)
|
49
54
|
github-nippou open-settings # Open settings url with web browser
|
50
|
-
github-nippou version #
|
55
|
+
github-nippou version # Print version
|
51
56
|
|
52
57
|
Options:
|
53
58
|
s, [--since-date=SINCE_DATE] # Retrieves GitHub user_events since the date
|
54
|
-
# Default:
|
59
|
+
# Default: 20170819
|
55
60
|
u, [--until-date=UNTIL_DATE] # Retrieves GitHub user_events until the date
|
56
|
-
# Default:
|
61
|
+
# Default: 20170819
|
57
62
|
d, [--debug], [--no-debug] # Debug mode
|
58
63
|
|
59
64
|
```
|
@@ -65,32 +70,11 @@ $ github-nippou
|
|
65
70
|
|
66
71
|
### masutaka/github-nippou
|
67
72
|
|
68
|
-
* [v3.0.0](https://github.com/masutaka/github-nippou/issues/59) by masutaka
|
69
|
-
* [Enable to inject settings_gist_id instead of the settings](https://github.com/masutaka/github-nippou/pull/63) by masutaka **merged!**
|
70
|
-
* [Add y/n prompt to sub command \`init\`](https://github.com/masutaka/github-nippou/pull/64) by masutaka **merged!**
|
71
|
-
* [Add sub command \`open-settings\`](https://github.com/masutaka/github-nippou/pull/65) by masutaka **merged!**
|
72
|
-
* [Dockerize](https://github.com/masutaka/github-nippou/pull/66) by masutaka **merged!**
|
73
|
-
```
|
74
|
-
|
75
|
-
## Customize output format
|
76
|
-
|
77
|
-
```
|
78
|
-
$ github-nippou init
|
79
|
-
This command will create a gist and update your `~/.gitconfig`.
|
80
|
-
Are you sure? [y/n] y
|
81
|
-
The github-nippou settings was created on https://gist.github.com/ecfa35cb546d8462277d133a91b13be9
|
82
|
-
|
83
|
-
And the gist_id was appended to your `~/.gitconfig`. You can
|
84
|
-
check the gist_id with following command.
|
85
|
-
|
86
|
-
$ git config --global github-nippou.settings-gist-id
|
87
|
-
```
|
88
|
-
|
89
|
-
Open the Gist URL with your web browser.
|
90
|
-
|
91
|
-
```
|
92
|
-
$ github-nippou open-settings
|
93
|
-
Open https://gist.github.com/ecfa35cb546d8462277d133a91b13be9
|
73
|
+
* [v3.0.0](https://github.com/masutaka/github-nippou/issues/59) by @[masutaka](https://github.com/masutaka)
|
74
|
+
* [Enable to inject settings_gist_id instead of the settings](https://github.com/masutaka/github-nippou/pull/63) by @[masutaka](https://github.com/masutaka) **merged!**
|
75
|
+
* [Add y/n prompt to sub command \`init\`](https://github.com/masutaka/github-nippou/pull/64) by @[masutaka](https://github.com/masutaka) **merged!**
|
76
|
+
* [Add sub command \`open-settings\`](https://github.com/masutaka/github-nippou/pull/65) by @[masutaka](https://github.com/masutaka) **merged!**
|
77
|
+
* [Dockerize](https://github.com/masutaka/github-nippou/pull/66) by @[masutaka](https://github.com/masutaka) **merged!**
|
94
78
|
```
|
95
79
|
|
96
80
|
## Docker
|
data/github-nippou.gemspec
CHANGED
data/lib/github/nippou.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'highline/import'
|
2
1
|
require 'launchy'
|
3
2
|
require 'parallel'
|
4
3
|
require 'thor'
|
@@ -16,13 +15,13 @@ module Github
|
|
16
15
|
aliases: :u, desc: 'Retrieves GitHub user_events until the date'
|
17
16
|
class_option :debug, type: :boolean, default: false, aliases: :d, desc: 'Debug mode'
|
18
17
|
|
19
|
-
desc 'list', "
|
18
|
+
desc 'list', "Print today's your GitHub action (Default)"
|
20
19
|
def list
|
21
20
|
lines = []
|
22
21
|
mutex = Mutex.new
|
23
|
-
format = Format.new(
|
22
|
+
format = Format.new(settings, debug)
|
24
23
|
|
25
|
-
Parallel.each_with_index(user_events, in_threads: thread_num) do |user_event, i|
|
24
|
+
Parallel.each_with_index(user_events, in_threads: settings.thread_num) do |user_event, i|
|
26
25
|
# Contain GitHub access.
|
27
26
|
# So should not put into the mutex block.
|
28
27
|
line = format.line(user_event, i)
|
@@ -32,46 +31,9 @@ module Github
|
|
32
31
|
puts format.all(lines)
|
33
32
|
end
|
34
33
|
|
35
|
-
desc 'init', '
|
34
|
+
desc 'init', 'Initialize github-nippou settings'
|
36
35
|
def init
|
37
|
-
|
38
|
-
puts <<~MESSAGE
|
39
|
-
** Gist scope required.
|
40
|
-
|
41
|
-
You need personal access token which has `gist` scope.
|
42
|
-
Please add `gist` scope to your personal access token, visit
|
43
|
-
https://github.com/settings/tokens
|
44
|
-
MESSAGE
|
45
|
-
exit!
|
46
|
-
end
|
47
|
-
|
48
|
-
if settings.gist_id.present?
|
49
|
-
puts <<~MESSAGE
|
50
|
-
** Already initialized.
|
51
|
-
|
52
|
-
Your `~/.gitconfig` already has gist_id as `github-nippou.settings-gist-id`.
|
53
|
-
MESSAGE
|
54
|
-
exit
|
55
|
-
end
|
56
|
-
|
57
|
-
puts 'This command will create a gist and update your `~/.gitconfig`.'
|
58
|
-
|
59
|
-
unless HighLine.agree('Are you sure? [y/n] ')
|
60
|
-
puts 'Canceled.'
|
61
|
-
abort
|
62
|
-
end
|
63
|
-
|
64
|
-
gist = settings.create_gist
|
65
|
-
`git config --global github-nippou.settings-gist-id #{gist.id}`
|
66
|
-
|
67
|
-
puts <<~MESSAGE
|
68
|
-
The github-nippou settings was created on #{gist.html_url}
|
69
|
-
|
70
|
-
And the gist_id was appended to your `~/.gitconfig`. You can
|
71
|
-
check the gist_id with following command.
|
72
|
-
|
73
|
-
$ git config --global github-nippou.settings-gist-id
|
74
|
-
MESSAGE
|
36
|
+
Init.new(settings: settings).run
|
75
37
|
end
|
76
38
|
|
77
39
|
desc 'open-settings', 'Open settings url with web browser'
|
@@ -80,7 +42,7 @@ module Github
|
|
80
42
|
Launchy.open(settings.url)
|
81
43
|
end
|
82
44
|
|
83
|
-
desc 'version', '
|
45
|
+
desc 'version', 'Print version'
|
84
46
|
def version
|
85
47
|
puts VERSION
|
86
48
|
end
|
@@ -89,67 +51,12 @@ module Github
|
|
89
51
|
|
90
52
|
def user_events
|
91
53
|
@user_events ||= UserEvents.new(
|
92
|
-
client, user, options[:since_date], options[:until_date]
|
54
|
+
settings.client, settings.user, options[:since_date], options[:until_date]
|
93
55
|
).collect
|
94
56
|
end
|
95
57
|
|
96
|
-
def client
|
97
|
-
@client ||= Octokit::Client.new(login: user, access_token: access_token)
|
98
|
-
end
|
99
|
-
|
100
|
-
def user
|
101
|
-
@user ||=
|
102
|
-
case
|
103
|
-
when ENV['GITHUB_NIPPOU_USER']
|
104
|
-
ENV['GITHUB_NIPPOU_USER']
|
105
|
-
when !`git config github-nippou.user`.chomp.empty?
|
106
|
-
`git config github-nippou.user`.chomp
|
107
|
-
else
|
108
|
-
puts <<~MESSAGE
|
109
|
-
** User required.
|
110
|
-
|
111
|
-
Please set github-nippou.user to your `~/.gitconfig`.
|
112
|
-
$ git config --global github-nippou.user [Your GitHub account]
|
113
|
-
MESSAGE
|
114
|
-
exit!
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def access_token
|
119
|
-
@access_token ||=
|
120
|
-
case
|
121
|
-
when ENV['GITHUB_NIPPOU_ACCESS_TOKEN']
|
122
|
-
ENV['GITHUB_NIPPOU_ACCESS_TOKEN']
|
123
|
-
when !`git config github-nippou.token`.chomp.empty?
|
124
|
-
`git config github-nippou.token`.chomp
|
125
|
-
else
|
126
|
-
puts <<~MESSAGE
|
127
|
-
** Authorization required.
|
128
|
-
|
129
|
-
Please set github-nippou.token to your `~/.gitconfig`.
|
130
|
-
$ git config --global github-nippou.token [Your GitHub access token]
|
131
|
-
|
132
|
-
To get new token with `repo` and `gist` scope, visit
|
133
|
-
https://github.com/settings/tokens/new
|
134
|
-
MESSAGE
|
135
|
-
exit!
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
58
|
def settings
|
140
|
-
@settings ||= Settings.new
|
141
|
-
end
|
142
|
-
|
143
|
-
def thread_num
|
144
|
-
@thread_num ||=
|
145
|
-
case
|
146
|
-
when ENV['GITHUB_NIPPOU_THREAD_NUM']
|
147
|
-
ENV['GITHUB_NIPPOU_THREAD_NUM']
|
148
|
-
when !`git config github-nippou.thread-num`.chomp.empty?
|
149
|
-
`git config github-nippou.thread-num`.chomp
|
150
|
-
else
|
151
|
-
5
|
152
|
-
end.to_i
|
59
|
+
@settings ||= Settings.new
|
153
60
|
end
|
154
61
|
|
155
62
|
def debug
|
data/lib/github/nippou/format.rb
CHANGED
@@ -4,19 +4,15 @@ module Github
|
|
4
4
|
using SawyerResourceGithub
|
5
5
|
using StringMarkdown
|
6
6
|
|
7
|
-
# @param client [Octokit::Client]
|
8
|
-
# @param thread_num [Integer]
|
9
7
|
# @param settings [Settings]
|
10
8
|
# @param debug [Boolean]
|
11
|
-
def initialize(
|
12
|
-
@client = client
|
13
|
-
@thread_num = thread_num
|
9
|
+
def initialize(settings, debug)
|
14
10
|
@settings = settings
|
15
11
|
@debug = debug
|
16
12
|
end
|
17
13
|
|
18
14
|
def line(user_event, i)
|
19
|
-
STDERR.puts "#{i %
|
15
|
+
STDERR.puts "#{i % settings.thread_num} : #{user_event.html_url}\n" if @debug
|
20
16
|
issue = issue(user_event)
|
21
17
|
|
22
18
|
line = {
|
@@ -62,12 +58,12 @@ module Github
|
|
62
58
|
def issue(user_event)
|
63
59
|
case
|
64
60
|
when user_event.payload.pull_request
|
65
|
-
|
61
|
+
settings.client.pull_request(user_event.repo.name, user_event.payload.pull_request.number)
|
66
62
|
when user_event.payload.issue.pull_request
|
67
63
|
# a pull_request like an issue
|
68
|
-
|
64
|
+
settings.client.pull_request(user_event.repo.name, user_event.payload.issue.number)
|
69
65
|
else
|
70
|
-
|
66
|
+
settings.client.issue(user_event.repo.name, user_event.payload.issue.number)
|
71
67
|
end
|
72
68
|
end
|
73
69
|
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'highline/import'
|
2
|
+
|
3
|
+
module Github
|
4
|
+
module Nippou
|
5
|
+
class Init
|
6
|
+
# @param settings [Settings]
|
7
|
+
def initialize(settings:)
|
8
|
+
@settings = settings
|
9
|
+
end
|
10
|
+
|
11
|
+
# Run the initialization
|
12
|
+
#
|
13
|
+
# @raise [SystemExit] failed the initialization,
|
14
|
+
# or don't need, or canceled
|
15
|
+
def run
|
16
|
+
puts '** github-nippou Initialization **'
|
17
|
+
set_user!
|
18
|
+
sleep 0.5
|
19
|
+
set_access_token!
|
20
|
+
sleep 0.5
|
21
|
+
create_and_set_gist!
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :settings
|
27
|
+
|
28
|
+
def set_user!
|
29
|
+
puts <<~MESSAGE
|
30
|
+
|
31
|
+
== [Step: 1/3] GitHub user ==
|
32
|
+
|
33
|
+
MESSAGE
|
34
|
+
|
35
|
+
begin
|
36
|
+
settings.user(verbose: false)
|
37
|
+
msg = 'Already initialized.'
|
38
|
+
rescue Github::Nippou::Settings::GettingUserError
|
39
|
+
user = HighLine.new.ask("What's your GitHub account? ")
|
40
|
+
|
41
|
+
if user.present?
|
42
|
+
puts <<~MESSAGE
|
43
|
+
|
44
|
+
The following command will be executed.
|
45
|
+
|
46
|
+
$ git config --global github-nippou.user #{user}
|
47
|
+
|
48
|
+
MESSAGE
|
49
|
+
|
50
|
+
unless HighLine.agree('Are you sure? [y/n] ')
|
51
|
+
puts 'Canceled.'
|
52
|
+
abort
|
53
|
+
end
|
54
|
+
|
55
|
+
`git config --global github-nippou.user #{user}`
|
56
|
+
msg = 'Thanks!'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
puts <<~MESSAGE
|
61
|
+
#{msg} You can get it with the following command.
|
62
|
+
|
63
|
+
$ git config --global github-nippou.user
|
64
|
+
|
65
|
+
MESSAGE
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_access_token!
|
69
|
+
puts <<~MESSAGE
|
70
|
+
|
71
|
+
== [Step: 2/3] GitHub personal access token ==
|
72
|
+
|
73
|
+
To get new token with `repo` and `gist` scope, visit
|
74
|
+
https://github.com/settings/tokens/new
|
75
|
+
|
76
|
+
MESSAGE
|
77
|
+
|
78
|
+
begin
|
79
|
+
settings.access_token(verbose: false)
|
80
|
+
msg = 'Already initialized.'
|
81
|
+
rescue Github::Nippou::Settings::GettingAccessTokenError
|
82
|
+
token = HighLine.new.ask("What's your GitHub personal access token? ")
|
83
|
+
|
84
|
+
if token.present?
|
85
|
+
puts <<~MESSAGE
|
86
|
+
|
87
|
+
The following command will be executed.
|
88
|
+
|
89
|
+
$ git config --global github-nippou.token #{token}
|
90
|
+
|
91
|
+
MESSAGE
|
92
|
+
|
93
|
+
unless HighLine.agree('Are you sure? [y/n] ')
|
94
|
+
puts 'Canceled.'
|
95
|
+
abort
|
96
|
+
end
|
97
|
+
|
98
|
+
`git config --global github-nippou.token #{token}`
|
99
|
+
msg = 'Thanks!'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
puts <<~MESSAGE
|
104
|
+
#{msg} You can get it with the following command.
|
105
|
+
|
106
|
+
$ git config --global github-nippou.token
|
107
|
+
|
108
|
+
MESSAGE
|
109
|
+
|
110
|
+
unless settings.client.scopes.include?('repo') &&
|
111
|
+
settings.client.scopes.include?('gist')
|
112
|
+
puts <<~MESSAGE
|
113
|
+
!!!! `repo` and `gist` scopes are required. !!!!
|
114
|
+
|
115
|
+
You need personal access token which has `repo` and `gist`
|
116
|
+
scopes. Please add these scopes to your personal access
|
117
|
+
token, visit https://github.com/settings/tokens
|
118
|
+
|
119
|
+
MESSAGE
|
120
|
+
abort
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_and_set_gist!
|
125
|
+
puts <<~MESSAGE
|
126
|
+
|
127
|
+
== [Step: 3/3] Gist (optional) ==
|
128
|
+
|
129
|
+
MESSAGE
|
130
|
+
|
131
|
+
if settings.gist_id.present?
|
132
|
+
msg = 'Already initialized.'
|
133
|
+
else
|
134
|
+
puts <<~MESSAGE
|
135
|
+
1. Create a gist with the content of #{settings.default_url}
|
136
|
+
2. The following command will be executed
|
137
|
+
|
138
|
+
$ git config --global github-nippou.settings-gist-id <created gist id>
|
139
|
+
|
140
|
+
MESSAGE
|
141
|
+
|
142
|
+
unless HighLine.agree('Are you sure? [y/n] ')
|
143
|
+
puts 'Canceled.'
|
144
|
+
abort
|
145
|
+
end
|
146
|
+
|
147
|
+
gist = settings.create_gist
|
148
|
+
`git config --global github-nippou.settings-gist-id #{gist.id}`
|
149
|
+
msg = 'Thanks!'
|
150
|
+
end
|
151
|
+
|
152
|
+
puts <<~MESSAGE
|
153
|
+
#{msg} You can get it with the following command.
|
154
|
+
|
155
|
+
$ git config --global github-nippou.settings-gist-id
|
156
|
+
|
157
|
+
And you can easily open the gist URL with web browser.
|
158
|
+
|
159
|
+
$ github-nippou open-settings
|
160
|
+
|
161
|
+
MESSAGE
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -4,9 +4,51 @@ require 'ostruct'
|
|
4
4
|
module Github
|
5
5
|
module Nippou
|
6
6
|
class Settings
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
class GettingUserError < SystemExit; end
|
8
|
+
class GettingAccessTokenError < SystemExit; end
|
9
|
+
|
10
|
+
# Getting GitHub user
|
11
|
+
#
|
12
|
+
# @param verbose [Boolean] Print error message
|
13
|
+
# @return [String]
|
14
|
+
# @raise [SystemExit] cannot get the user
|
15
|
+
def user(verbose: true)
|
16
|
+
@user ||=
|
17
|
+
case
|
18
|
+
when ENV['GITHUB_NIPPOU_USER']
|
19
|
+
ENV['GITHUB_NIPPOU_USER']
|
20
|
+
when !`git config github-nippou.user`.chomp.empty?
|
21
|
+
`git config github-nippou.user`.chomp
|
22
|
+
else
|
23
|
+
puts <<~MESSAGE if verbose
|
24
|
+
!!!! GitHub User required. Please execute the following command. !!!!
|
25
|
+
|
26
|
+
$ github-nippou init
|
27
|
+
MESSAGE
|
28
|
+
raise GettingUserError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Getting GitHub personal access token
|
33
|
+
#
|
34
|
+
# @param verbose [Boolean] Print error message
|
35
|
+
# @return [String]
|
36
|
+
# @raise [SystemExit] cannot get the access token
|
37
|
+
def access_token(verbose: true)
|
38
|
+
@access_token ||=
|
39
|
+
case
|
40
|
+
when ENV['GITHUB_NIPPOU_ACCESS_TOKEN']
|
41
|
+
ENV['GITHUB_NIPPOU_ACCESS_TOKEN']
|
42
|
+
when !`git config github-nippou.token`.chomp.empty?
|
43
|
+
`git config github-nippou.token`.chomp
|
44
|
+
else
|
45
|
+
puts <<~MESSAGE if verbose
|
46
|
+
!!!! GitHub Personal access token required. Please execute the following command. !!!!
|
47
|
+
|
48
|
+
$ github-nippou init
|
49
|
+
MESSAGE
|
50
|
+
raise GettingAccessTokenError
|
51
|
+
end
|
10
52
|
end
|
11
53
|
|
12
54
|
# Getting gist id which has settings.yml
|
@@ -23,6 +65,28 @@ module Github
|
|
23
65
|
end
|
24
66
|
end
|
25
67
|
|
68
|
+
# Getting thread number
|
69
|
+
#
|
70
|
+
# @return [Integer]
|
71
|
+
def thread_num
|
72
|
+
@thread_num ||=
|
73
|
+
case
|
74
|
+
when ENV['GITHUB_NIPPOU_THREAD_NUM']
|
75
|
+
ENV['GITHUB_NIPPOU_THREAD_NUM']
|
76
|
+
when !`git config github-nippou.thread-num`.chomp.empty?
|
77
|
+
`git config github-nippou.thread-num`.chomp
|
78
|
+
else
|
79
|
+
5
|
80
|
+
end.to_i
|
81
|
+
end
|
82
|
+
|
83
|
+
# Getting Octokit client
|
84
|
+
#
|
85
|
+
# return [Octokit::Client]
|
86
|
+
def client
|
87
|
+
@client ||= Octokit::Client.new(login: user, access_token: access_token)
|
88
|
+
end
|
89
|
+
|
26
90
|
# Create gist with config/settings.yml
|
27
91
|
#
|
28
92
|
# @return [Sawyer::Resource]
|
@@ -42,10 +106,17 @@ module Github
|
|
42
106
|
if gist_id
|
43
107
|
client.gist(gist_id).html_url
|
44
108
|
else
|
45
|
-
|
109
|
+
default_url
|
46
110
|
end
|
47
111
|
end
|
48
112
|
|
113
|
+
# Getting default settings url
|
114
|
+
#
|
115
|
+
# @return [String]
|
116
|
+
def default_url
|
117
|
+
"https://github.com/masutaka/github-nippou/blob/v#{VERSION}/config/settings.yml"
|
118
|
+
end
|
119
|
+
|
49
120
|
# Getting format settings
|
50
121
|
#
|
51
122
|
# @return [OpenStruct]
|
@@ -62,8 +133,6 @@ module Github
|
|
62
133
|
|
63
134
|
private
|
64
135
|
|
65
|
-
attr_reader :client
|
66
|
-
|
67
136
|
# Getting default settings.yml as Hash
|
68
137
|
#
|
69
138
|
# return [Hash]
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe Github::Nippou::Init do
|
2
|
+
let(:client) { Octokit::Client.new(login: 'taro', access_token: '1234abcd') }
|
3
|
+
let(:settings) { double(:settings, user: nil, access_token: nil, gist_id: nil, thread_num: nil,
|
4
|
+
client: nil, create_gist: nil, url: nil, default_url: nil, format: nil, dictionary: nil) }
|
5
|
+
let(:init) { described_class.new(settings: settings) }
|
6
|
+
|
7
|
+
it_behaves_like 'a settings interface'
|
8
|
+
it_behaves_like 'a init interface'
|
9
|
+
end
|
@@ -1,49 +1,69 @@
|
|
1
1
|
describe Github::Nippou::Settings do
|
2
|
-
let(:
|
3
|
-
let(:settings) { described_class.new(client: client) }
|
2
|
+
let(:settings) { described_class.new }
|
4
3
|
|
5
|
-
|
4
|
+
it_behaves_like 'a settings interface'
|
5
|
+
|
6
|
+
describe '#user' do
|
7
|
+
before { ENV['GITHUB_NIPPOU_USER'] = 'taro' }
|
8
|
+
subject { settings.user }
|
9
|
+
it { is_expected.to eq 'taro' }
|
10
|
+
after { ENV['GITHUB_NIPPOU_USER'] = nil }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#access_token' do
|
14
|
+
before { ENV['GITHUB_NIPPOU_ACCESS_TOKEN'] = '1234abcd' }
|
15
|
+
subject { settings.access_token }
|
16
|
+
it { is_expected.to eq '1234abcd' }
|
17
|
+
after { ENV['GITHUB_NIPPOU_ACCESS_TOKEN'] = nil }
|
18
|
+
end
|
6
19
|
|
7
20
|
describe '#gist_id' do
|
8
21
|
before { ENV['GITHUB_NIPPOU_SETTINGS_GIST_ID'] = '0123456789' }
|
9
|
-
|
10
|
-
it
|
11
|
-
|
12
|
-
end
|
22
|
+
subject { settings.gist_id }
|
23
|
+
it { is_expected.to eq '0123456789' }
|
24
|
+
after { ENV['GITHUB_NIPPOU_SETTINGS_GIST_ID'] = nil }
|
13
25
|
end
|
14
26
|
|
15
|
-
describe '#
|
16
|
-
|
17
|
-
|
18
|
-
|
27
|
+
describe '#thread_num' do
|
28
|
+
before { ENV['GITHUB_NIPPOU_THREAD_NUM'] = '10' }
|
29
|
+
subject { settings.thread_num }
|
30
|
+
it { is_expected.to eq 10 }
|
31
|
+
after { ENV['GITHUB_NIPPOU_THREAD_NUM'] = nil }
|
19
32
|
end
|
20
33
|
|
21
34
|
describe '#url' do
|
35
|
+
subject { settings.url }
|
36
|
+
|
22
37
|
context 'given gist_id' do
|
23
38
|
let(:gist_id) { '0123456789' }
|
24
39
|
|
25
40
|
before do
|
26
|
-
|
27
|
-
|
28
|
-
|
41
|
+
allow(settings).to receive(:gist_id).and_return gist_id
|
42
|
+
allow(settings).to receive_message_chain(:client, :gist) do
|
43
|
+
OpenStruct.new(html_url: "https://gist.github.com/#{gist_id}")
|
44
|
+
end
|
29
45
|
end
|
30
46
|
|
31
|
-
it
|
32
|
-
expect(settings.url).to eq "https://gist.github.com/#{gist_id}"
|
33
|
-
end
|
47
|
+
it { is_expected.to eq "https://gist.github.com/#{gist_id}" }
|
34
48
|
end
|
35
49
|
|
36
50
|
context 'given no gist_id' do
|
37
|
-
|
38
|
-
|
39
|
-
end
|
51
|
+
before { allow(settings).to receive(:gist_id).and_return nil }
|
52
|
+
it { is_expected.to eq "https://github.com/masutaka/github-nippou/blob/v#{Github::Nippou::VERSION}/config/settings.yml" }
|
40
53
|
end
|
41
54
|
end
|
42
55
|
|
56
|
+
describe '#default_url' do
|
57
|
+
subject { settings.default_url }
|
58
|
+
it { is_expected.to eq "https://github.com/masutaka/github-nippou/blob/v#{Github::Nippou::VERSION}/config/settings.yml" }
|
59
|
+
end
|
60
|
+
|
43
61
|
describe '#format' do
|
44
62
|
before do
|
45
|
-
|
46
|
-
allow(
|
63
|
+
allow(settings).to receive(:gist_id).and_return '12345'
|
64
|
+
allow(settings).to receive_message_chain(:client, :gist) do
|
65
|
+
OpenStruct.new(files: { 'settings.yml': { content: settings_yaml } })
|
66
|
+
end
|
47
67
|
end
|
48
68
|
|
49
69
|
context 'given valid settings' do
|
@@ -69,8 +89,10 @@ describe Github::Nippou::Settings do
|
|
69
89
|
|
70
90
|
describe '#dictionary' do
|
71
91
|
before do
|
72
|
-
|
73
|
-
allow(
|
92
|
+
allow(settings).to receive(:gist_id).and_return '12345'
|
93
|
+
allow(settings).to receive_message_chain(:client, :gist) do
|
94
|
+
OpenStruct.new(files: { 'settings.yml': { content: settings_yaml } })
|
95
|
+
end
|
74
96
|
end
|
75
97
|
|
76
98
|
context 'given valid settings' do
|
@@ -0,0 +1,13 @@
|
|
1
|
+
shared_examples_for 'a settings interface' do
|
2
|
+
subject { settings }
|
3
|
+
it { is_expected.to respond_to :user }
|
4
|
+
it { is_expected.to respond_to :access_token }
|
5
|
+
it { is_expected.to respond_to :gist_id }
|
6
|
+
it { is_expected.to respond_to :thread_num }
|
7
|
+
it { is_expected.to respond_to :client }
|
8
|
+
it { is_expected.to respond_to :create_gist }
|
9
|
+
it { is_expected.to respond_to :url }
|
10
|
+
it { is_expected.to respond_to :default_url }
|
11
|
+
it { is_expected.to respond_to :format }
|
12
|
+
it { is_expected.to respond_to :dictionary }
|
13
|
+
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: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Masuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: |2
|
140
154
|
This is a helpful tool when you write a daily report in reference to
|
141
155
|
GitHub. nippou is a japanese word which means a daily report.
|
@@ -167,13 +181,17 @@ files:
|
|
167
181
|
- lib/github/nippou/concerns/sawyer_resource_github.rb
|
168
182
|
- lib/github/nippou/concerns/string_markdown.rb
|
169
183
|
- lib/github/nippou/format.rb
|
184
|
+
- lib/github/nippou/init.rb
|
170
185
|
- lib/github/nippou/settings.rb
|
171
186
|
- lib/github/nippou/user_events.rb
|
172
187
|
- lib/github/nippou/version.rb
|
173
188
|
- spec/fixtures/settings-invalid.yml
|
174
189
|
- spec/fixtures/settings-valid.yml
|
190
|
+
- spec/github/nippou/init_spec.rb
|
175
191
|
- spec/github/nippou/settings_spec.rb
|
176
192
|
- spec/spec_helper.rb
|
193
|
+
- spec/support/interface_init.rb
|
194
|
+
- spec/support/interface_settings.rb
|
177
195
|
- spec/support/load_fixture.rb
|
178
196
|
homepage: https://github.com/masutaka/github-nippou
|
179
197
|
licenses:
|
@@ -202,6 +220,9 @@ summary: Print today's your GitHub action.
|
|
202
220
|
test_files:
|
203
221
|
- spec/fixtures/settings-invalid.yml
|
204
222
|
- spec/fixtures/settings-valid.yml
|
223
|
+
- spec/github/nippou/init_spec.rb
|
205
224
|
- spec/github/nippou/settings_spec.rb
|
206
225
|
- spec/spec_helper.rb
|
226
|
+
- spec/support/interface_init.rb
|
227
|
+
- spec/support/interface_settings.rb
|
207
228
|
- spec/support/load_fixture.rb
|