gem_comet 0.2.0 → 0.3.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: d4002b63773d5efc2b2c6cb8367b7f4fedc6222f8fc43ccee41eb83497e2deee
4
- data.tar.gz: 6319c6d3b7ff584c6c80da5349639778aabdb580807cd2688508e2d3dded71b1
3
+ metadata.gz: d5518bdb07a7f391789dd4a92dfab7da680516d056043f53f89cc90b6369bf2c
4
+ data.tar.gz: bd74b2883f594bf6a8f8ef8d16f7e5b6523e51e99b78c2204ad7d59d13715746
5
5
  SHA512:
6
- metadata.gz: 590973c76a9a238d97550c5ec6b90f441ab8e3499c2fb5f297d6e8b7d5f50d086d2d98b5305cb5e6646fabf8a7467fb00f433dc3f2964dffa6e438f02b005d88
7
- data.tar.gz: b3eb0b0b8cab1d370136b82ce34faa0e33a8905fbfc89cf1c9b04ed19663d378670b6c31af88a11d4ce64dad5b3cb6c4b665a01a67fdc6844867f592a10770d1
6
+ metadata.gz: 04115a41944981972f6ff88c7ec3d91facd4125ed05376b65341f94251910568a00bfc5d6b7aa968ffc2a47088adb8d41e0d9a230681e346999ea0e4402d5151
7
+ data.tar.gz: a654c0dc19960e482c4db8a049a35df9a741440b6806a361aabce616bc1eb212df794b41f55436c38ce2ada34a11f86f1bcb6d9a36d9439041377266f1ac4fcd
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-09-30 23:30:48 +0000 using RuboCop version 0.75.0.
3
+ # on 2019-10-14 23:40:22 +0000 using RuboCop version 0.75.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change log
2
2
 
3
+ ## 0.3.0 (Oct 19, 2019)
4
+
5
+ ### Feature
6
+
7
+ * Enhance the feature of changelog command ([#27](https://github.com/ryz310/gem_comet/pull/27))
8
+
9
+ ### Misc
10
+
11
+ * Re-generate .rubocop_todo.yml with RuboCop v0.75.1 ([#25](https://github.com/ryz310/gem_comet/pull/25))
12
+
3
13
  ## 0.2.0 (Oct 14, 2019)
4
14
 
5
15
  ### Feature
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gem_comet (0.2.0)
4
+ gem_comet (0.3.0)
5
5
  pr_comet (~> 0.3.0)
6
6
  thor
7
7
  type_struct
@@ -54,7 +54,7 @@ GEM
54
54
  rspec-support (3.9.0)
55
55
  rspec_junit_formatter (0.4.1)
56
56
  rspec-core (>= 2, < 4, != 2.12.0)
57
- rubocop (0.75.0)
57
+ rubocop (0.75.1)
58
58
  jaro_winkler (~> 1.5.1)
59
59
  parallel (~> 1.10)
60
60
  parser (>= 2.6)
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemComet
4
+ class Changelog
5
+ # Edits CHANGELOG.md file of gem
6
+ class Editor
7
+ HEADER = "# Change log\n"
8
+
9
+ attr_reader :changelog_file_path
10
+
11
+ def initialize
12
+ @changelog_file_path = Config.call.release.changelog_file_path
13
+ end
14
+
15
+ # Prepends the content to CHANGELOG.md.
16
+ #
17
+ # @param content [String] Character string you want to prepend
18
+ def prepend!(content:)
19
+ return if changelog_file_path.nil?
20
+
21
+ modify_changelog do |changelog_file|
22
+ position = changelog_file.index(HEADER) + HEADER.length
23
+ changelog_file.insert(position, content)
24
+ end
25
+ end
26
+
27
+ # Appends the content to CHANGELOG.md.
28
+ #
29
+ # @param content [String] Character string you want to append
30
+ def append!(content:)
31
+ return if changelog_file_path.nil?
32
+
33
+ modify_changelog do |changelog_file|
34
+ changelog_file.concat(content)
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def modify_changelog
41
+ changelog_file = File.read(changelog_file_path)
42
+ yield(changelog_file)
43
+ File.write(changelog_file_path, changelog_file)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemComet
4
+ class Changelog
5
+ # Generates changelog from git log
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
18
+ end
19
+
20
+ private
21
+
22
+ MERGE_COMMIT_TITLE = /Merge pull request #(\d+) from (.+)/.freeze
23
+
24
+ # Returns changelogs as markdown format from current version to HEAD commit.
25
+ #
26
+ # @return [String] Changelogs as markdown format
27
+ def call
28
+ <<~MARKDOWN
29
+
30
+ ## #{new_version} (#{Date.today.strftime('%b %d, %Y')})
31
+
32
+ ### Feature
33
+ ### Bugfix
34
+ ### Breaking Change
35
+ ### Misc
36
+
37
+ #{changelogs.reverse.join("\n")}
38
+ MARKDOWN
39
+ end
40
+
41
+ # Returns array of changelogs as markdown format.
42
+ #
43
+ # @return [Array<String>] Array of changelogs as markdown format
44
+ def changelogs
45
+ merge_commits.map do |merge_commit|
46
+ next unless merge_commit.match?(MERGE_COMMIT_TITLE)
47
+
48
+ pull_request_number = extract_pull_request_number(merge_commit)
49
+ pull_request_url = get_pull_request_url(pull_request_number)
50
+ description = extract_description(merge_commit) || extract_branch_name(merge_commit)
51
+
52
+ "* #{description} ([##{pull_request_number}](#{pull_request_url}))"
53
+ end.compact
54
+ end
55
+
56
+ # Extracts PR number from merge commit string.
57
+ #
58
+ # @param merge_commit [String] The target string
59
+ # @return [Integer] The pull request number
60
+ def extract_pull_request_number(merge_commit)
61
+ MERGE_COMMIT_TITLE.match(merge_commit).captures.first.to_i
62
+ end
63
+
64
+ # Get the PR URL. (e.g. https://github.com/ryz310/gem_comet/pull/1)
65
+ #
66
+ # @param pull_request_number [Integer] The target pull request number
67
+ # @return [String] Returns the URL
68
+ def get_pull_request_url(pull_request_number)
69
+ "#{origin_url}/pull/#{pull_request_number}"
70
+ end
71
+
72
+ # Extracts commit desciption from merge commit string.
73
+ #
74
+ # @param merge_commit [String] The target string
75
+ # @return [String] The commit description
76
+ # @return [nil] Returns `nil` if not exists
77
+ def extract_description(merge_commit)
78
+ description = merge_commit.lines.last
79
+ description&.chomp&.strip unless description.match?(MERGE_COMMIT_TITLE)
80
+ end
81
+
82
+ # Extracts the PR branch name from merge commit string.
83
+ #
84
+ # @param merge_commit [String] The target string
85
+ # @return [String] Branch name
86
+ def extract_branch_name(merge_commit)
87
+ MERGE_COMMIT_TITLE.match(merge_commit).captures.last.chomp.strip
88
+ end
89
+
90
+ # Parces the merge commit log, which to separate by each commit.
91
+ #
92
+ # @return [Array<String>] Array of git commit log
93
+ def merge_commits
94
+ merge_commit_log.split(/^commit \w{40}\n/).reject(&:empty?).map(&:chomp)
95
+ end
96
+
97
+ # Returns only merge commit logs via git command.
98
+ #
99
+ # @return [String] Get only merge commit logs
100
+ def merge_commit_log
101
+ @merge_commit_log ||= `git log --merges #{from}..#{to}`
102
+ end
103
+
104
+ # Returns the git origin URL via git command.
105
+ #
106
+ # @return [String] The origin URL
107
+ def origin_url
108
+ @origin_url ||= `git remote get-url --push origin`.sub('.git', '').chomp
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemComet
4
+ # Generates changelog from git log
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
18
+ @changelog_editor = Changelog::Editor.new
19
+ @from_version = from_version || version_editor.current_version
20
+ @to_version = to_version
21
+ @append = append
22
+ @prepend = prepend
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :version_editor, :changelog_editor,
28
+ :from_version, :to_version, :append, :prepend
29
+
30
+ # Displays changelogs. If specified a `append` or `prepend` option, updates
31
+ # CHANGELOG.md with generated changelog.
32
+ #
33
+ # @return [String] Ganalated changelog
34
+ def call
35
+ if append
36
+ changelog_editor.append!(content: changelog)
37
+ elsif prepend
38
+ changelog_editor.prepend!(content: changelog)
39
+ end
40
+ changelog
41
+ end
42
+
43
+ # Generate a changelog. The result is memoized.
44
+ #
45
+ # @return [String] Ganalated changelog
46
+ def changelog
47
+ @changelog ||= Generator.call(from_version: from_version, to_version: to_version)
48
+ end
49
+ end
50
+ end
data/lib/gem_comet/cli.rb CHANGED
@@ -21,10 +21,39 @@ module GemComet
21
21
  Release.call(version: version)
22
22
  end
23
23
 
24
- desc 'changelog', 'Displays changelogs from last release to HEAD commit'
24
+ desc 'changelog', 'Displays changelogs'
25
+ option :from,
26
+ 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`.'
35
+ option :append,
36
+ type: :boolean,
37
+ aliases: :a,
38
+ default: false,
39
+ desc: 'Appends execution result to CHANGELOG.md.'
40
+ option :prepend,
41
+ type: :boolean,
42
+ aliases: :p,
43
+ default: false,
44
+ desc: 'Prepends execution result to CHANGELOG.md.'
25
45
  def changelog
26
- version_editor = VersionEditor.new
27
- puts ChangelogGenerator.call(current_version: version_editor.current_version)
46
+ puts Changelog.call(
47
+ from_version: options[:from],
48
+ to_version: options[:to],
49
+ append: options[:append],
50
+ prepend: options[:prepend]
51
+ )
52
+ end
53
+
54
+ desc 'versions', 'Displays version numbers of your gem.'
55
+ def versions
56
+ puts `git tag`
28
57
  end
29
58
 
30
59
  desc 'version', 'Shows current version'
@@ -8,7 +8,7 @@ module GemComet
8
8
  @version = version
9
9
  @pr_comet = PrComet.new(base: base_branch, branch: "update/v#{version}")
10
10
  @version_editor = VersionEditor.new
11
- @changelog_editor = ChangelogEditor.new
11
+ @changelog_editor = Changelog::Editor.new
12
12
  end
13
13
 
14
14
  private
@@ -24,11 +24,11 @@ module GemComet
24
24
 
25
25
  def update_changelog
26
26
  pr_comet.commit ':comet: Update CHANGELOG.md' do
27
- changelog = ChangelogGenerator.call(
28
- current_version: version_editor.current_version,
27
+ changelog = Changelog::Generator.call(
28
+ from_version: version_editor.current_version,
29
29
  new_version: version
30
30
  )
31
- changelog_editor.append!(content: changelog)
31
+ changelog_editor.prepend!(content: changelog)
32
32
  end
33
33
  end
34
34
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GemComet
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/gem_comet.rb CHANGED
@@ -9,8 +9,9 @@ require 'gem_comet/version'
9
9
  require 'gem_comet/service_abstract'
10
10
  require 'gem_comet/config'
11
11
  require 'gem_comet/version_editor'
12
- require 'gem_comet/changelog_editor'
13
- require 'gem_comet/changelog_generator'
12
+ require 'gem_comet/changelog'
13
+ require 'gem_comet/changelog/editor'
14
+ require 'gem_comet/changelog/generator'
14
15
  require 'gem_comet/release'
15
16
  require 'gem_comet/release/update_pr'
16
17
  require 'gem_comet/release/release_pr'
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.2.0
4
+ version: 0.3.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-13 00:00:00.000000000 Z
11
+ date: 2019-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pr_comet
@@ -219,8 +219,9 @@ files:
219
219
  - exe/gem_comet
220
220
  - gem_comet.gemspec
221
221
  - lib/gem_comet.rb
222
- - lib/gem_comet/changelog_editor.rb
223
- - lib/gem_comet/changelog_generator.rb
222
+ - lib/gem_comet/changelog.rb
223
+ - lib/gem_comet/changelog/editor.rb
224
+ - lib/gem_comet/changelog/generator.rb
224
225
  - lib/gem_comet/cli.rb
225
226
  - lib/gem_comet/config.rb
226
227
  - lib/gem_comet/release.rb
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemComet
4
- # Edits CHANGELOG.md file of gem
5
- class ChangelogEditor
6
- HEADER = "# Change log\n"
7
-
8
- attr_reader :changelog_file_path
9
-
10
- def initialize
11
- @changelog_file_path = Config.call.release.changelog_file_path
12
- end
13
-
14
- # Appends the content to CHANGELOG.md.
15
- #
16
- # @param content [String] Character string you want to append
17
- def append!(content:)
18
- return if changelog_file_path.nil?
19
-
20
- changelog_file = File.read(changelog_file_path)
21
- position = changelog_file.index(HEADER) + HEADER.length
22
- changelog_file.insert(position, content)
23
- File.write(changelog_file_path, changelog_file)
24
- end
25
- end
26
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemComet
4
- # Generates changelog from git log
5
- class ChangelogGenerator < ServiceAbstract
6
- attr_reader :last_label, :new_version
7
-
8
- # @param current_version [String] Current version of your gem
9
- # @param new_version [String] Next version of your gem
10
- def initialize(current_version:, new_version: nil)
11
- @last_label = "v#{current_version}"
12
- @new_version = new_version || 'NEW'
13
- end
14
-
15
- private
16
-
17
- MERGE_COMMIT_TITLE = /Merge pull request #(\d+) from (.+)/.freeze
18
-
19
- # Returns changelogs as markdown format from current version to HEAD commit.
20
- #
21
- # @return [String] Changelogs as markdown format
22
- def call
23
- <<~MARKDOWN
24
-
25
- ## #{new_version} (#{Date.today.strftime('%b %d, %Y')})
26
-
27
- ### Feature
28
- ### Bugfix
29
- ### Breaking Change
30
- ### Misc
31
-
32
- #{changelogs.reverse.join("\n")}
33
-
34
- MARKDOWN
35
- end
36
-
37
- # Returns array of changelogs as markdown format.
38
- #
39
- # @return [Array<String>] Array of changelogs as markdown format
40
- def changelogs
41
- merge_commits.map do |merge_commit|
42
- next unless merge_commit.match?(MERGE_COMMIT_TITLE)
43
-
44
- pull_request_number = extract_pull_request_number(merge_commit)
45
- pull_request_url = get_pull_request_url(pull_request_number)
46
- description = extract_description(merge_commit) || extract_branch_name(merge_commit)
47
-
48
- "* #{description} ([##{pull_request_number}](#{pull_request_url}))"
49
- end.compact
50
- end
51
-
52
- # Extracts PR number from merge commit string.
53
- #
54
- # @param merge_commit [String] The target string
55
- # @return [Integer] The pull request number
56
- def extract_pull_request_number(merge_commit)
57
- MERGE_COMMIT_TITLE.match(merge_commit).captures.first.to_i
58
- end
59
-
60
- # Get the PR URL. (e.g. https://github.com/ryz310/gem_comet/pull/1)
61
- #
62
- # @param pull_request_number [Integer] The target pull request number
63
- # @return [String] Returns the URL
64
- def get_pull_request_url(pull_request_number)
65
- "#{origin_url}/pull/#{pull_request_number}"
66
- end
67
-
68
- # Extracts commit desciption from merge commit string.
69
- #
70
- # @param merge_commit [String] The target string
71
- # @return [String] The commit description
72
- # @return [nil] Returns `nil` if not exists
73
- def extract_description(merge_commit)
74
- description = merge_commit.lines.last
75
- description&.chomp&.strip unless description.match?(MERGE_COMMIT_TITLE)
76
- end
77
-
78
- # Extracts the PR branch name from merge commit string.
79
- #
80
- # @param merge_commit [String] The target string
81
- # @return [String] Branch name
82
- def extract_branch_name(merge_commit)
83
- MERGE_COMMIT_TITLE.match(merge_commit).captures.last.chomp.strip
84
- end
85
-
86
- # Parces the merge commit log, which to separate by each commit.
87
- #
88
- # @return [Array<String>] Array of git commit log
89
- def merge_commits
90
- merge_commit_log.split(/^commit \w{40}\n/).reject(&:empty?).map(&:chomp)
91
- end
92
-
93
- # Returns only merge commit logs via git command.
94
- #
95
- # @return [String] Get only merge commit logs
96
- def merge_commit_log
97
- @merge_commit_log ||= `git log --merges #{last_label}..HEAD`
98
- end
99
-
100
- # Returns the git origin URL via git command.
101
- #
102
- # @return [String] The origin URL
103
- def origin_url
104
- @origin_url ||= `git remote get-url --push origin`.sub('.git', '').chomp
105
- end
106
- end
107
- end