github-nippou 2.1.0.beta1 → 3.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: 0ef358687064ffbca6c80ab96136c0a81c36e154
4
- data.tar.gz: adddcb9ff77d0afddfa4da8c177d10e0f8cb7bab
3
+ metadata.gz: bfc8acb06e7f4d5971323ca515e9c6395e2f0e15
4
+ data.tar.gz: f17aca19e5918f47a96447e184ced1d51a8166de
5
5
  SHA512:
6
- metadata.gz: 1ff50591fd5d01d3c6ca25fcc5818e6ece3576f907ab92e671f8a96294840cfa1bab5f9ed6a562532ee6c803dec0c2af1134710febc1514aa4e68aa2950a73ed
7
- data.tar.gz: b5461b0c1b574930aa9b3add56abd818292a38f55a7def443c96fe8483f47db9595bfc0fd04a20191bc15a05f49a083e8de6ceb7bc1c25d497767042f78d3c53
6
+ metadata.gz: d5598fbc8daf144ef77bc82ff48812d1f219dbd61491d987817b23ab470ca55caebf2596eb038873ad026eca4866c64aacc212771c05dbda30e2aba63fe717db
7
+ data.tar.gz: 4ec3ecf571db54972a3f768d2278778aa560d3e3697f6957b066a1a77a0892d525783b191c3561b99387dc0b8ed88d876c0c5c1d818e812630fefd8e07ccaad9
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --format documentation
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github-nippou (2.1.0.beta1)
4
+ github-nippou (3.0.0.beta1)
5
5
  activesupport
6
6
  octokit
7
7
  parallel
@@ -17,6 +17,7 @@ GEM
17
17
  tzinfo (~> 1.1)
18
18
  addressable (2.4.0)
19
19
  concurrent-ruby (1.0.2)
20
+ diff-lcs (1.3)
20
21
  faraday (0.9.2)
21
22
  multipart-post (>= 1.2, < 3)
22
23
  i18n (0.7.0)
@@ -26,6 +27,19 @@ GEM
26
27
  sawyer (~> 0.7.0, >= 0.5.3)
27
28
  parallel (1.9.0)
28
29
  rake (11.2.2)
30
+ rspec (3.6.0)
31
+ rspec-core (~> 3.6.0)
32
+ rspec-expectations (~> 3.6.0)
33
+ rspec-mocks (~> 3.6.0)
34
+ rspec-core (3.6.0)
35
+ rspec-support (~> 3.6.0)
36
+ rspec-expectations (3.6.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.6.0)
39
+ rspec-mocks (3.6.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.6.0)
42
+ rspec-support (3.6.0)
29
43
  sawyer (0.7.0)
30
44
  addressable (>= 2.3.5, < 2.5)
31
45
  faraday (~> 0.8, < 0.10)
@@ -41,6 +55,7 @@ DEPENDENCIES
41
55
  bundler
42
56
  github-nippou!
43
57
  rake
58
+ rspec
44
59
 
45
60
  BUNDLED WITH
46
- 1.12.5
61
+ 1.15.3
data/README.md CHANGED
@@ -65,5 +65,11 @@ You can omit the sub command `list`.
65
65
  4. Push to the branch (`git push origin my-new-feature`)
66
66
  5. Create a new Pull Request
67
67
 
68
+ ## External article
69
+
70
+ In Japanese
71
+
72
+ [github-nippou - GitHubから日報を作成 MOONGIFT](http://www.moongift.jp/2016/06/github-nippou-github%E3%81%8B%E3%82%89%E6%97%A5%E5%A0%B1%E3%82%92%E4%BD%9C%E6%88%90/)
73
+
68
74
  [gem-badge]: https://badge.fury.io/rb/github-nippou.svg
69
75
  [gem-link]: http://badge.fury.io/rb/github-nippou
@@ -0,0 +1,7 @@
1
+ format:
2
+ subject: '### %{subject}'
3
+ line: '* [%{title}](%{url}) by %{user} %{status}'
4
+ dictionary:
5
+ status:
6
+ merged: '**merged!**'
7
+ closed: '**closed!**'
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_development_dependency 'bundler'
29
29
  spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'rspec'
30
31
  end
@@ -1,5 +1,6 @@
1
1
  require 'parallel'
2
2
  require 'thor'
3
+ require 'yaml'
3
4
 
4
5
  module Github
5
6
  module Nippou
@@ -16,8 +17,8 @@ module Github
16
17
  desc 'list', "Displays today's GitHub events formatted for Nippou"
17
18
  def list
18
19
  lines = []
19
- mutex = Mutex::new
20
- format = Format.new(client, thread_num, debug)
20
+ mutex = Mutex.new
21
+ format = Format.new(client, thread_num, settings, debug)
21
22
 
22
23
  Parallel.each_with_index(user_events, in_threads: thread_num) do |user_event, i|
23
24
  # Contain GitHub access.
@@ -29,6 +30,41 @@ module Github
29
30
  puts format.all(lines)
30
31
  end
31
32
 
33
+ desc 'init', 'Synchronize github-nippou settings on your gist'
34
+ def init
35
+ unless client.scopes.include? 'gist'
36
+ puts <<~MESSAGE
37
+ ** Gist scope required.
38
+
39
+ You need personal access token which has gist scope.
40
+ Please add gist scope on your personal access token if you use this command.
41
+ MESSAGE
42
+ exit!
43
+ end
44
+ unless `git config github-nippou.settings-gist-id`.chomp.empty?
45
+ puts <<~MESSAGE
46
+ ** Already initialized.
47
+
48
+ It already have gist id that github-nippou.settings-gist-id on your .gitconfig.
49
+ MESSAGE
50
+ exit!
51
+ end
52
+
53
+ result = client.create_gist(
54
+ description: 'github-nippou settings',
55
+ public: true,
56
+ files: { 'settings.yml' => { content: settings.to_yaml }}
57
+ ).to_h
58
+ `git config --global github-nippou.settings-gist-id #{result[:id]}`
59
+
60
+ puts <<~MESSAGE
61
+ The github-nippou settings was created on following url: #{result[:html_url]}
62
+ And the gist id was set your .gitconfig
63
+ You can check the gist id with following command
64
+ $ git config --global github-nippou.settings-gist-id
65
+ MESSAGE
66
+ end
67
+
32
68
  desc 'version', 'Displays version'
33
69
  def version
34
70
  puts VERSION
@@ -54,12 +90,12 @@ module Github
54
90
  when !`git config github-nippou.user`.chomp.empty?
55
91
  `git config github-nippou.user`.chomp
56
92
  else
57
- puts <<MESSAGE
58
- ** User required.
93
+ puts <<~MESSAGE
94
+ ** User required.
59
95
 
60
- Please set github-nippou.user to your .gitconfig.
61
- $ git config --global github-nippou.user [Your GitHub account]
62
- MESSAGE
96
+ Please set github-nippou.user to your .gitconfig.
97
+ $ git config --global github-nippou.user [Your GitHub account]
98
+ MESSAGE
63
99
  exit!
64
100
  end
65
101
  end
@@ -72,19 +108,50 @@ MESSAGE
72
108
  when !`git config github-nippou.token`.chomp.empty?
73
109
  `git config github-nippou.token`.chomp
74
110
  else
75
- puts <<MESSAGE
76
- ** Authorization required.
111
+ puts <<~MESSAGE
112
+ ** Authorization required.
77
113
 
78
- Please set github-nippou.token to your .gitconfig.
79
- $ git config --global github-nippou.token [Your GitHub access token]
114
+ Please set github-nippou.token to your .gitconfig.
115
+ $ git config --global github-nippou.token [Your GitHub access token]
80
116
 
81
- To get new token with `repo` scope, visit
82
- https://github.com/settings/tokens/new
83
- MESSAGE
117
+ To get new token with `repo` scope, visit
118
+ https://github.com/settings/tokens/new
119
+ MESSAGE
84
120
  exit!
85
121
  end
86
122
  end
87
123
 
124
+ def settings
125
+ return @settings if @settings.present?
126
+
127
+ yaml_data =
128
+ case
129
+ when ENV['GITHUB_NIPPOU_SETTINGS']
130
+ ENV['GITHUB_NIPPOU_SETTINGS'].chomp
131
+ when !`git config github-nippou.settings`.chomp.empty?
132
+ `git config github-nippou.settings`.chomp
133
+ when !`git config github-nippou.settings-gist-id`.chomp.empty?
134
+ gist_id = `git config github-nippou.settings-gist-id`.chomp
135
+ gist = client.gist(gist_id)
136
+ gist[:files][:'settings.yml'][:content]
137
+ end
138
+
139
+ @settings =
140
+ if yaml_data
141
+ YAML.load(yaml_data).deep_symbolize_keys
142
+ else
143
+ YAML.load_file(File.expand_path('../../../config/settings.yml', __dir__)).deep_symbolize_keys
144
+ end
145
+ rescue Psych::SyntaxError => e
146
+ puts <<~MESSAGE
147
+ ** YAML syntax error.
148
+
149
+ #{e.message}
150
+ #{yaml_data}
151
+ MESSAGE
152
+ exit
153
+ end
154
+
88
155
  def thread_num
89
156
  @thread_num ||=
90
157
  case
@@ -4,9 +4,12 @@ module Github
4
4
  using SawyerResourceGithub
5
5
  using StringMarkdown
6
6
 
7
- def initialize(client, thread_num, debug)
7
+ attr_reader :settings
8
+
9
+ def initialize(client, thread_num, settings, debug)
8
10
  @client = client
9
11
  @thread_num = thread_num
12
+ @settings = settings
10
13
  @debug = debug
11
14
  end
12
15
 
@@ -34,18 +37,17 @@ module Github
34
37
  def all(lines)
35
38
  result = ""
36
39
  prev_repo_name = nil
37
- curr_repo_name = nil
40
+ current_repo_name = nil
38
41
 
39
42
  sort(lines).each do |line|
40
43
  current_repo_name = line[:repo_name]
41
44
 
42
45
  unless current_repo_name == prev_repo_name
43
46
  prev_repo_name = current_repo_name
44
- result << "\n### #{current_repo_name}\n\n"
47
+ result << "\n#{format_subject(current_repo_name)}\n\n"
45
48
  end
46
49
 
47
- result << "* [%s](%s) by %s%s\n" %
48
- [line[:title].markdown_escape, line[:url], line[:user], format_status(line[:status])]
50
+ result << "#{format_line(line)}\n"
49
51
  end
50
52
 
51
53
  result
@@ -70,14 +72,21 @@ module Github
70
72
  end
71
73
 
72
74
  def format_status(status)
73
- case status
74
- when :merged
75
- ' **merged!**'
76
- when :closed
77
- ' **closed!**'
78
- else
79
- ''
80
- end
75
+ settings[:dictionary][:status][status]
76
+ end
77
+
78
+ def format_subject(subject)
79
+ sprintf(settings[:format][:subject], subject: subject)
80
+ end
81
+
82
+ def format_line(line)
83
+ sprintf(
84
+ settings[:format][:line],
85
+ title: line[:title].markdown_escape,
86
+ url: line[:url],
87
+ user: line[:user],
88
+ status: format_status(line[:status])
89
+ ).strip
81
90
  end
82
91
  end
83
92
  end
@@ -1,5 +1,5 @@
1
1
  module Github
2
2
  module Nippou
3
- VERSION = '2.1.0.beta1'
3
+ VERSION = '3.0.0.beta1'
4
4
  end
5
5
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Nippou::Commands do
4
+ let(:commands) { described_class.new }
5
+
6
+ describe '#settings' do
7
+ subject(:execute) { commands.send(:settings) }
8
+
9
+ let(:settings) do
10
+ {
11
+ format: {
12
+ subject: '### %{subject}',
13
+ line: '* [%{title}](%{url}) by %{user} %{status}',
14
+ },
15
+ }
16
+ end
17
+
18
+ let(:yaml) { settings.to_yaml }
19
+
20
+ context "when ENV['GITHUB_NIPPOU_SETTINGS'] present" do
21
+ before { ENV['GITHUB_NIPPOU_SETTINGS'] = yaml }
22
+
23
+ context 'given valid YAML syntax' do
24
+ it 'should set YAML value to @settings' do
25
+ expect { execute }
26
+ .to change { commands.instance_variable_get(:@settings) }
27
+ .to settings
28
+ end
29
+ end
30
+
31
+ context 'given invalid YAML syntax' do
32
+ before do
33
+ ENV['GITHUB_NIPPOU_SETTINGS'] = <<~INVALID_YAML
34
+ format:
35
+ **!!invalid!!**
36
+ line: '* [%{title}](%{url}) by %{user} %{status}'
37
+ INVALID_YAML
38
+ end
39
+
40
+ it 'should output YAML syntax error message' do
41
+ expect {
42
+ begin
43
+ execute
44
+ rescue SystemExit
45
+ nil
46
+ end
47
+ }.to output(<<~ERROR).to_stdout
48
+ ** YAML syntax error.
49
+
50
+ (<unknown>): did not find expected alphabetic or numeric character while scanning an alias at line 2 column 3
51
+ format:
52
+ **!!invalid!!**
53
+ line: '* [%{title}](%{url}) by %{user} %{status}'
54
+ ERROR
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,102 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+
15
+ require 'github/nippou'
16
+
17
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
+ RSpec.configure do |config|
19
+ # rspec-expectations config goes here. You can use an alternate
20
+ # assertion/expectation library such as wrong or the stdlib/minitest
21
+ # assertions if you prefer.
22
+ config.expect_with :rspec do |expectations|
23
+ # This option will default to `true` in RSpec 4. It makes the `description`
24
+ # and `failure_message` of custom matchers include text for helper methods
25
+ # defined using `chain`, e.g.:
26
+ # be_bigger_than(2).and_smaller_than(4).description
27
+ # # => "be bigger than 2 and smaller than 4"
28
+ # ...rather than:
29
+ # # => "be bigger than 2"
30
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ end
32
+
33
+ # rspec-mocks config goes here. You can use an alternate test double
34
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43
+ # have no way to turn it off -- the option exists only for backwards
44
+ # compatibility in RSpec 3). It causes shared context metadata to be
45
+ # inherited by the metadata hash of host groups and examples, rather than
46
+ # triggering implicit auto-inclusion in groups with matching metadata.
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ =begin
52
+ # This allows you to limit a spec run to individual examples or groups
53
+ # you care about by tagging them with `:focus` metadata. When nothing
54
+ # is tagged with `:focus`, all examples get run. RSpec also provides
55
+ # aliases for `it`, `describe`, and `context` that include `:focus`
56
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
57
+ config.filter_run_when_matching :focus
58
+
59
+ # Allows RSpec to persist some state between runs in order to support
60
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
61
+ # you configure your source control system to ignore this file.
62
+ config.example_status_persistence_file_path = "spec/examples.txt"
63
+
64
+ # Limits the available syntax to the non-monkey patched syntax that is
65
+ # recommended. For more details, see:
66
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
67
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
68
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
69
+ config.disable_monkey_patching!
70
+
71
+ # This setting enables warnings. It's recommended, but in some cases may
72
+ # be too noisy due to issues in dependencies.
73
+ config.warnings = true
74
+
75
+ # Many RSpec users commonly either run the entire suite or an individual
76
+ # file, and it's useful to allow more verbose output when running an
77
+ # individual spec file.
78
+ if config.files_to_run.one?
79
+ # Use the documentation formatter for detailed output,
80
+ # unless a formatter has already been configured
81
+ # (e.g. via a command-line flag).
82
+ config.default_formatter = "doc"
83
+ end
84
+
85
+ # Print the 10 slowest examples and example groups at the
86
+ # end of the spec run, to help surface which specs are running
87
+ # particularly slow.
88
+ config.profile_examples = 10
89
+
90
+ # Run specs in random order to surface order dependencies. If you find an
91
+ # order dependency and want to debug it, you can fix the order by providing
92
+ # the seed, which is printed after each run.
93
+ # --seed 1234
94
+ config.order = :random
95
+
96
+ # Seed global randomization in this process using the `--seed` CLI option.
97
+ # Setting this allows you to use `--seed` to deterministically reproduce
98
+ # test failures related to randomization by passing the same `--seed` value
99
+ # as the one that triggered the failure.
100
+ Kernel.srand config.seed
101
+ =end
102
+ 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.1.0.beta1
4
+ version: 3.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-08-07 00:00:00.000000000 Z
11
+ date: 2017-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: |2
98
112
  This is a helpful tool when you write a daily report in reference to
99
113
  GitHub. nippou is a japanese word which means a daily report.
@@ -105,12 +119,14 @@ extensions: []
105
119
  extra_rdoc_files: []
106
120
  files:
107
121
  - ".gitignore"
122
+ - ".rspec"
108
123
  - Gemfile
109
124
  - Gemfile.lock
110
125
  - LICENSE.txt
111
126
  - README.md
112
127
  - Rakefile
113
128
  - bin/github-nippou
129
+ - config/settings.yml
114
130
  - github-nippou.gemspec
115
131
  - lib/github/nippou.rb
116
132
  - lib/github/nippou/commands.rb
@@ -119,6 +135,8 @@ files:
119
135
  - lib/github/nippou/format.rb
120
136
  - lib/github/nippou/user_events.rb
121
137
  - lib/github/nippou/version.rb
138
+ - spec/github/nippou/commands_spec.rb
139
+ - spec/spec_helper.rb
122
140
  homepage: https://github.com/masutaka/github-nippou
123
141
  licenses:
124
142
  - MIT
@@ -139,8 +157,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
157
  version: 1.3.1
140
158
  requirements: []
141
159
  rubyforge_project:
142
- rubygems_version: 2.5.1
160
+ rubygems_version: 2.6.11
143
161
  signing_key:
144
162
  specification_version: 4
145
163
  summary: Print today's your GitHub action.
146
- test_files: []
164
+ test_files:
165
+ - spec/github/nippou/commands_spec.rb
166
+ - spec/spec_helper.rb