gem_comet 0.3.0 → 0.4.0

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
  SHA256:
3
- metadata.gz: d5518bdb07a7f391789dd4a92dfab7da680516d056043f53f89cc90b6369bf2c
4
- data.tar.gz: bd74b2883f594bf6a8f8ef8d16f7e5b6523e51e99b78c2204ad7d59d13715746
3
+ metadata.gz: b13645ee861e799d64559a1d4b41de38fe7e11061073387bece2f18c9f6d595f
4
+ data.tar.gz: 7d83a76d83b2812cb74afbcc7dd406d0980a6ad000caa9901395e0f8e9671ad2
5
5
  SHA512:
6
- metadata.gz: 04115a41944981972f6ff88c7ec3d91facd4125ed05376b65341f94251910568a00bfc5d6b7aa968ffc2a47088adb8d41e0d9a230681e346999ea0e4402d5151
7
- data.tar.gz: a654c0dc19960e482c4db8a049a35df9a741440b6806a361aabce616bc1eb212df794b41f55436c38ce2ada34a11f86f1bcb6d9a36d9439041377266f1ac4fcd
6
+ metadata.gz: 57d0c128ffe107140aafb153bd8ec3e858bd7643fbd878348bb3f7e0531163e60da7884f1e56116f948523b85d8f4d530ebee3a4e079528db82e4f700ea5c8d9
7
+ data.tar.gz: 59dd23a66be1ac4fec13fd6fb2d2c7f92edbeae79ce7d02ae4e31e465e10c92babfe25e2bff52380188fc4adf1cd8bba2a8c9bcac14a7eb5ba3eb9f56ab86520
@@ -16,7 +16,7 @@ Metrics/LineLength:
16
16
  Max: 100
17
17
 
18
18
  RSpec/MultipleExpectations:
19
- Max: 4
19
+ Max: 6
20
20
 
21
21
  RSpec/NestedGroups:
22
22
  Max: 4
@@ -1,5 +1,26 @@
1
1
  # Change log
2
2
 
3
+ ## v0.4.0 (Oct 27, 2019)
4
+
5
+ ### Feature
6
+
7
+ * Modify to display gem versions sorted by tagged date ([#32](https://github.com/ryz310/gem_comet/pull/32))
8
+ * Add the legend to creating pull requests ([#33](https://github.com/ryz310/gem_comet/pull/33))
9
+ * Open the GitHub pull request page at release ([#36](https://github.com/ryz310/gem_comet/pull/36))
10
+
11
+ ### Bugfix
12
+
13
+ * Fix broken links included by the modified change log ([#34](https://github.com/ryz310/gem_comet/pull/34))
14
+
15
+ ### Breaking Change
16
+
17
+ * Changelog initializer ([#35](https://github.com/ryz310/gem_comet/pull/35))
18
+ * The `$ gem_comet changelog` command options has changed:
19
+ * Before:
20
+ * `$ gem_comet changelog --from=0.1.0 --to=0.1.1`
21
+ * After:
22
+ * `$ gem_comet changelog --version=v0.1.1`
23
+
3
24
  ## 0.3.0 (Oct 19, 2019)
4
25
 
5
26
  ### Feature
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gem_comet (0.3.0)
4
+ gem_comet (0.4.0)
5
5
  pr_comet (~> 0.3.0)
6
6
  thor
7
7
  type_struct
@@ -8,11 +8,20 @@ require 'yaml'
8
8
  require 'gem_comet/version'
9
9
  require 'gem_comet/service_abstract'
10
10
  require 'gem_comet/config'
11
+ require 'gem_comet/bundle_updater'
11
12
  require 'gem_comet/version_editor'
13
+ require 'gem_comet/version_history'
12
14
  require 'gem_comet/changelog'
15
+ require 'gem_comet/changelog/initializer'
13
16
  require 'gem_comet/changelog/editor'
14
17
  require 'gem_comet/changelog/generator'
18
+ require 'gem_comet/open_github_pulls_page'
19
+ require 'gem_comet/repository_url'
15
20
  require 'gem_comet/release'
16
21
  require 'gem_comet/release/update_pr'
17
22
  require 'gem_comet/release/release_pr'
18
23
  require 'gem_comet/cli'
24
+
25
+ module GemComet
26
+ LEGEND = 'Generated by [gem_comet](https://github.com/ryz310/gem_comet)'
27
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemComet
4
+ # Executes `$ bundle update` command
5
+ class BundleUpdater < ServiceAbstract
6
+ def initialize; end
7
+
8
+ private
9
+
10
+ def call
11
+ `bundle update`
12
+ end
13
+ end
14
+ end
@@ -3,29 +3,19 @@
3
3
  module GemComet
4
4
  # Generates changelog from git log
5
5
  class Changelog < ServiceAbstract
6
- # @param from_version [String]
7
- # The beginning of version number to create a changelog.
8
- # Default is specified current version.
9
- # @param to_version [String]
10
- # The end of version number to create a changelog.
11
- # Default is specified `HEAD`.
12
- # @param append [Boolean]
13
- # Appends execution result to CHANGELOG.md.
14
- # @param prepend [Boolean]
15
- # Prepends execution result to CHANGELOG.md.
16
- def initialize(from_version: nil, to_version: nil, append: false, prepend: false)
17
- @version_editor = VersionEditor.new
6
+ # @param version [String] The version number to create a changelog.
7
+ # @param append [Boolean] Appends execution result to CHANGELOG.md.
8
+ # @param prepend [Boolean] Prepends execution result to CHANGELOG.md.
9
+ def initialize(version:, append: false, prepend: false)
18
10
  @changelog_editor = Changelog::Editor.new
19
- @from_version = from_version || version_editor.current_version
20
- @to_version = to_version
11
+ @version = version
21
12
  @append = append
22
13
  @prepend = prepend
23
14
  end
24
15
 
25
16
  private
26
17
 
27
- attr_reader :version_editor, :changelog_editor,
28
- :from_version, :to_version, :append, :prepend
18
+ attr_reader :changelog_editor, :version, :append, :prepend
29
19
 
30
20
  # Displays changelogs. If specified a `append` or `prepend` option, updates
31
21
  # CHANGELOG.md with generated changelog.
@@ -44,7 +34,7 @@ module GemComet
44
34
  #
45
35
  # @return [String] Ganalated changelog
46
36
  def changelog
47
- @changelog ||= Generator.call(from_version: from_version, to_version: to_version)
37
+ @changelog ||= Generator.call(version: version)
48
38
  end
49
39
  end
50
40
  end
@@ -4,17 +4,14 @@ module GemComet
4
4
  class Changelog
5
5
  # Generates changelog from git log
6
6
  class Generator < ServiceAbstract
7
- attr_reader :from, :to, :new_version
8
-
9
- # @param from_version [String] The beginning of version number to create a changelog
10
- # @param to_version [String]
11
- # The end of version number to create a changelog. If ommit this option,
12
- # it's specified `HEAD`.
13
- # @param new_version [String] Next version of your gem
14
- def initialize(from_version:, to_version: nil, new_version: nil)
15
- @from = "v#{from_version}"
16
- @to = to_version.nil? ? 'HEAD' : "v#{to_version}"
17
- @new_version = new_version || to
7
+ attr_reader :version, :title, :origin_url
8
+
9
+ # @param version [String] The end of version number to create a changelog.
10
+ # @param title [String] Next version of your gem
11
+ def initialize(version:, title: nil)
12
+ @version = version
13
+ @title = title || version
14
+ @origin_url = RepositoryUrl.call
18
15
  end
19
16
 
20
17
  private
@@ -24,10 +21,11 @@ module GemComet
24
21
  # Returns changelogs as markdown format from current version to HEAD commit.
25
22
  #
26
23
  # @return [String] Changelogs as markdown format
24
+ # @raise [RuntimeError] The specified version cannot be found
27
25
  def call
28
26
  <<~MARKDOWN
29
27
 
30
- ## #{new_version} (#{Date.today.strftime('%b %d, %Y')})
28
+ ## #{title} (#{versioning_date})
31
29
 
32
30
  ### Feature
33
31
  ### Bugfix
@@ -38,6 +36,13 @@ module GemComet
38
36
  MARKDOWN
39
37
  end
40
38
 
39
+ # Returns the versioning date
40
+ #
41
+ # @return [String] The versioning date. e.g. "Oct 26, 2019"
42
+ def versioning_date
43
+ VersionHistory.new.versioning_date_of(version).strftime('%b %d, %Y')
44
+ end
45
+
41
46
  # Returns array of changelogs as markdown format.
42
47
  #
43
48
  # @return [Array<String>] Array of changelogs as markdown format
@@ -98,14 +103,14 @@ module GemComet
98
103
  #
99
104
  # @return [String] Get only merge commit logs
100
105
  def merge_commit_log
101
- @merge_commit_log ||= `git log --merges #{from}..#{to}`
106
+ @merge_commit_log ||= `git log --merges #{prev_version}..#{version}`
102
107
  end
103
108
 
104
- # Returns the git origin URL via git command.
109
+ # Get a previous version number from the specified version number
105
110
  #
106
- # @return [String] The origin URL
107
- def origin_url
108
- @origin_url ||= `git remote get-url --push origin`.sub('.git', '').chomp
111
+ # @raise [RuntimeError] The specified version cannot be found
112
+ def prev_version
113
+ @prev_version ||= VersionHistory.new.previous_version_from(version)
109
114
  end
110
115
  end
111
116
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemComet
4
+ class Changelog
5
+ # Initializes the CHANGELOG.md to append past version change-logs
6
+ class Initializer < ServiceAbstract
7
+ def initialize
8
+ @changelog_editor = Changelog::Editor.new
9
+ @version_history = VersionHistory.new
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :changelog_editor, :version_history
15
+
16
+ def call
17
+ version_history.versions.each do |version|
18
+ changelog = Changelog::Generator.call(version: version)
19
+ changelog_editor.prepend!(content: changelog)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -14,24 +14,26 @@ module GemComet
14
14
  template '../../template/.gem_comet.yml.erb', '.gem_comet.yml',
15
15
  version: GemComet::Config::CURRENT_VERSION
16
16
  template '../../template/CHANGELOG.md.erb', 'CHANGELOG.md'
17
+ Changelog::Initializer.call
18
+ rescue StandardError => e
19
+ puts e.message
17
20
  end
18
21
 
19
22
  desc 'release VERSION', 'Creates update PR and release PR'
20
23
  def release(version)
21
24
  Release.call(version: version)
25
+ rescue StandardError => e
26
+ puts e.message
22
27
  end
23
28
 
24
29
  desc 'changelog', 'Displays changelogs'
25
- option :from,
30
+ option :version,
26
31
  type: :string,
27
- aliases: :f,
28
- desc: 'The beginning of version number to create a changelog. ' \
29
- 'Default is specified current version.'
30
- option :to,
31
- type: :string,
32
- aliases: :t,
33
- desc: 'The end of version number to create a changelog. ' \
34
- 'Default is specified `HEAD`.'
32
+ aliases: :v,
33
+ default: 'HEAD',
34
+ desc: 'The version number to create a changelog. ' \
35
+ 'Default is specified `HEAD`.',
36
+ banner: 'v1.2.3'
35
37
  option :append,
36
38
  type: :boolean,
37
39
  aliases: :a,
@@ -44,16 +46,19 @@ module GemComet
44
46
  desc: 'Prepends execution result to CHANGELOG.md.'
45
47
  def changelog
46
48
  puts Changelog.call(
47
- from_version: options[:from],
48
- to_version: options[:to],
49
+ version: options[:version],
49
50
  append: options[:append],
50
51
  prepend: options[:prepend]
51
52
  )
53
+ rescue StandardError => e
54
+ puts e.message
52
55
  end
53
56
 
54
57
  desc 'versions', 'Displays version numbers of your gem.'
55
58
  def versions
56
- puts `git tag`
59
+ puts VersionHistory.new.versions
60
+ rescue StandardError => e
61
+ puts e.message
57
62
  end
58
63
 
59
64
  desc 'version', 'Shows current version'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemComet
4
+ # Creates pull requests for gem release and that preparation
5
+ class OpenGithubPullsPage < ServiceAbstract
6
+ attr_reader :origin_url
7
+
8
+ def initialize
9
+ @origin_url = RepositoryUrl.call
10
+ end
11
+
12
+ private
13
+
14
+ def call
15
+ `open #{origin_url}/pulls`
16
+ end
17
+ end
18
+ end
@@ -17,6 +17,7 @@ module GemComet
17
17
  def call
18
18
  UpdatePR.call(update_pr_args)
19
19
  ReleasePR.call(release_pr_args)
20
+ OpenGithubPullsPage.call
20
21
  end
21
22
 
22
23
  def update_pr_args
@@ -18,7 +18,7 @@ module GemComet
18
18
  end
19
19
 
20
20
  def create_pull_request
21
- pr_comet.create!(title: "Release v#{version}", body: '', validate: false)
21
+ pr_comet.create!(title: "Release v#{version}", body: LEGEND, validate: false)
22
22
  end
23
23
  end
24
24
  end
@@ -24,10 +24,7 @@ module GemComet
24
24
 
25
25
  def update_changelog
26
26
  pr_comet.commit ':comet: Update CHANGELOG.md' do
27
- changelog = Changelog::Generator.call(
28
- from_version: version_editor.current_version,
29
- new_version: version
30
- )
27
+ changelog = Changelog::Generator.call(version: 'HEAD', title: "v#{version}")
31
28
  changelog_editor.prepend!(content: changelog)
32
29
  end
33
30
  end
@@ -39,11 +36,11 @@ module GemComet
39
36
  end
40
37
 
41
38
  def bundle_update
42
- pr_comet.commit(':comet: $ bundle update') { `bundle update` }
39
+ pr_comet.commit(':comet: $ bundle update') { BundleUpdater.call }
43
40
  end
44
41
 
45
42
  def create_pull_request
46
- pr_comet.create!(title: "Update v#{version}", body: '')
43
+ pr_comet.create!(title: "Update v#{version}", body: LEGEND)
47
44
  end
48
45
  end
49
46
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemComet
4
+ # Gets the repository URL on the GitHub
5
+ class RepositoryUrl < ServiceAbstract
6
+ def initialize; end
7
+
8
+ private
9
+
10
+ # Returns the git origin URL via git command.
11
+ #
12
+ # @return [String] The origin URL
13
+ def call
14
+ if git_remote_command =~ /git@github.com:(.+).git/
15
+ "https://github.com/#{Regexp.last_match(1)}"
16
+ else
17
+ git_remote_command.sub('.git', '').chomp
18
+ end
19
+ end
20
+
21
+ def git_remote_command
22
+ @git_remote_command ||= `git remote get-url --push origin`
23
+ end
24
+ end
25
+ end
@@ -9,12 +9,12 @@ module GemComet
9
9
  new(*args).send(:call)
10
10
  end
11
11
 
12
- private
13
-
14
12
  def initialize(_args)
15
13
  raise "Please implement #{self.class}##{__method__}"
16
14
  end
17
15
 
16
+ private
17
+
18
18
  def call
19
19
  raise "Please implement #{self.class}##{__method__}"
20
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GemComet
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemComet
4
+ # Reads versions by `git tag` command
5
+ class VersionHistory
6
+ # Gets all version numbers
7
+ #
8
+ # @return [Array<String>] An array of version numbers
9
+ def versions
10
+ array_of_version_and_date.map(&:first).push('HEAD')
11
+ end
12
+
13
+ # Gets a previous version number from the specified version number
14
+ #
15
+ # @param version [String] Any version number
16
+ # @return [String] A previous version number
17
+ # @raise [RuntimeError] The specified version cannot be found
18
+ def previous_version_from(version)
19
+ index = find_version_index(version)
20
+ return nil if index.zero?
21
+
22
+ versions.at(index - 1)
23
+ end
24
+
25
+ # Gets the verioning date of the version number
26
+ #
27
+ # @param version [String] Any version number
28
+ # @return [Date] The verioning date
29
+ # @raise [RuntimeError] The specified version cannot be found
30
+ def versioning_date_of(version)
31
+ return Date.today if version == 'HEAD'
32
+
33
+ index = find_version_index(version)
34
+ Date.parse(array_of_version_and_date[index].last)
35
+ end
36
+
37
+ private
38
+
39
+ # Processes `git tag` command result
40
+ #
41
+ # @return [Array<Array<String>>] An array of versions and date
42
+ # e.g. [['v0.1.0', '2019-07-15'], ['v0.2.0', '2019-10-14']]
43
+ def array_of_version_and_date
44
+ @array_of_version_and_date ||= git_tag_list.lines.map(&:chomp).map(&:split).sort_by(&:last)
45
+ end
46
+
47
+ # Finds an index of the specified version number
48
+ #
49
+ # @param version [String] Any version number
50
+ # @return [Integer] The index of the specified version number
51
+ # @raise [RuntimeError] The specified version cannot be found
52
+ def find_version_index(version)
53
+ index = versions.index(version)
54
+ raise 'The specified version cannot be found' if index.nil?
55
+
56
+ index
57
+ end
58
+
59
+ # Executes `git tag` command
60
+ #
61
+ # @return [String] Output result
62
+ def git_tag_list
63
+ `git tag --list 'v*' --format='%(tag) %(taggerdate:short)'`
64
+ end
65
+ end
66
+ end
@@ -1,7 +1,10 @@
1
1
  # [Usage]
2
2
  #
3
3
  # $ gem install gem_comet
4
+ # $ gem_comet init
4
5
  # $ gem_comet release {version number, like as "1.2.3"}
6
+ # $ gem_comet changelog
7
+ # $ gem_comet versions
5
8
 
6
9
  version: <%= config[:version] %>
7
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_comet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryz310
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-19 00:00:00.000000000 Z
11
+ date: 2019-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pr_comet
@@ -219,17 +219,22 @@ files:
219
219
  - exe/gem_comet
220
220
  - gem_comet.gemspec
221
221
  - lib/gem_comet.rb
222
+ - lib/gem_comet/bundle_updater.rb
222
223
  - lib/gem_comet/changelog.rb
223
224
  - lib/gem_comet/changelog/editor.rb
224
225
  - lib/gem_comet/changelog/generator.rb
226
+ - lib/gem_comet/changelog/initializer.rb
225
227
  - lib/gem_comet/cli.rb
226
228
  - lib/gem_comet/config.rb
229
+ - lib/gem_comet/open_github_pulls_page.rb
227
230
  - lib/gem_comet/release.rb
228
231
  - lib/gem_comet/release/release_pr.rb
229
232
  - lib/gem_comet/release/update_pr.rb
233
+ - lib/gem_comet/repository_url.rb
230
234
  - lib/gem_comet/service_abstract.rb
231
235
  - lib/gem_comet/version.rb
232
236
  - lib/gem_comet/version_editor.rb
237
+ - lib/gem_comet/version_history.rb
233
238
  - template/.gem_comet.yml.erb
234
239
  - template/CHANGELOG.md.erb
235
240
  homepage: https://github.com/ryz310/gem_comet