verto 0.7.0 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Verto
2
4
  module DSL
3
5
  module Syntax
@@ -100,6 +102,18 @@ module Verto
100
102
  Verto.config.hooks << Hook.new(moment: 'before_tag_creation', &block)
101
103
  end
102
104
 
105
+ def update_changelog(with: :merged_pull_requests_with_bracketed_labels, confirmation: true, filename: 'CHANGELOG.md')
106
+ permitted_moments = %w[before_tag_creation after_tag_up]
107
+ unless permitted_moments.include? Verto.current_moment.to_s
108
+ raise ExitError, 'update_changelog is only supported in before_tag_creation or after_command_tag_up'
109
+ end
110
+
111
+ UpdateChangelog.new.call(with: with,
112
+ new_version: new_version,
113
+ confirmation: confirmation,
114
+ filename: filename)
115
+ end
116
+
103
117
  def file(filepath)
104
118
  DSL::File.new(filepath)
105
119
  end
@@ -108,8 +122,9 @@ module Verto
108
122
  ENV[environment_name]
109
123
  end
110
124
 
125
+ # TODO: Use delegator
111
126
  def confirm(text)
112
- shell_basic.yes?("#{text} (y/n)")
127
+ CliHelpers.confirm(text)
113
128
  end
114
129
 
115
130
  def error(text)
@@ -128,16 +143,12 @@ module Verto
128
143
  @executors ||= {
129
144
  from_config: Verto::SystemCommandExecutor.new,
130
145
  true => Verto::SystemCommandExecutor.new(stdout: $stdout, stderr: $stderr),
131
- false => Verto::SystemCommandExecutor.new(stdout: nil, stderr: nil),
146
+ false => Verto::SystemCommandExecutor.new(stdout: nil, stderr: nil)
132
147
  }
133
148
 
134
149
  @executors[output]
135
150
  end
136
151
 
137
- def shell_basic
138
- @shell_basic ||= Thor::Shell::Basic.new
139
- end
140
-
141
152
  def stderr
142
153
  Verto.stderr
143
154
  end
@@ -155,7 +166,7 @@ module Verto
155
166
  end
156
167
 
157
168
  def deprecate(current, use:)
158
- warn "[DEPRECATED] `#{current}` is deprecated and wil be removed in a future release, use `#{use}` instead"
169
+ warn "[DEPRECATED] `#{current}` is deprecated and will be removed in a future release, use `#{use}` instead"
159
170
  end
160
171
  end
161
172
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Verto
4
+ module DSL
5
+ class UpdateChangelog
6
+ include Verto.import[:cli_helpers, :stdout,
7
+ executor: 'system_command_executor_without_output', changelog_format: 'changelog.format']
8
+
9
+ InvalidChangelogSource = Class.new(Verto::ExitError)
10
+
11
+ SOURCES = StrictHash.new(
12
+ {
13
+ merged_pull_requests_with_bracketed_labels: lambda do |executor|
14
+ executor.run(
15
+ %q(git log --oneline --decorate | grep -B 100 -m 1 "tag:" | grep "pull request" | awk '{print $1}' | xargs git show --format='%b' | grep -v Approved | grep -v "^$" | grep -E "^[[:space:]]*\[.*\]")
16
+ ).output.split("\n").map(&:strip)
17
+ end
18
+ },
19
+ default_proc: ->(hash, _) { raise InvalidChangelogSource, "Invalid CHANGELOG Source, avaliable options: '#{hash.keys.join(',')}'" }
20
+ )
21
+
22
+ def call(new_version:, confirmation: true, filename: 'CHANGELOG.md', with: :merged_pull_requests_with_bracketed_labels)
23
+ verify_file_presence!(filename)
24
+
25
+ stdout.puts separator
26
+ changelog_changes = format_changes(new_version, version_changes(with))
27
+
28
+ exit if confirmation && !cli_helpers.confirm("Create new Release?\n" \
29
+ "#{separator}\n" \
30
+ "#{changelog_changes}" \
31
+ "#{separator}\n")
32
+ update_file(filename, changelog_changes)
33
+ end
34
+
35
+ private
36
+
37
+ def verify_file_presence!(filename)
38
+ return if Verto.project_path.join(filename).exist?
39
+
40
+ raise Verto::ExitError, "changelog file '#{filename}' doesnt exist"
41
+ end
42
+
43
+ def version_changes(with)
44
+ SOURCES[with].call(executor)
45
+ end
46
+
47
+ def update_file(filename, changelog_changes)
48
+ DSL::File.new(filename).prepend(changelog_changes)
49
+ end
50
+
51
+ def format_changes(new_version, version_changes)
52
+ Mustache.render(changelog_format, { new_version: new_version, version_changes: version_changes }) + "\n"
53
+ end
54
+
55
+ def separator
56
+ '---------------------------'
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Verto
2
4
  class TagRepository
3
5
  include Verto.import[executor: 'system_command_executor_without_output']
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CliHelpers
4
+ class << self
5
+ def confirm(text)
6
+ shell_basic.yes?("#{text} (y/n)")
7
+ end
8
+
9
+ private
10
+
11
+ def shell_basic
12
+ @shell_basic ||= Thor::Shell::Basic.new
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Verto
2
4
  class CommandOptions < Thor::CoreExt::HashWithIndifferentAccess
3
- alias_method :add, :merge!
5
+ alias add merge!
4
6
 
5
7
  def except(*keys)
6
- self.reject { |key, v| keys.include?(key) }
8
+ reject { |key, _v| keys.include?(key) }
7
9
  end
8
10
  end
9
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Verto
2
4
  class SemanticVersion < Vseries::SemanticVersion
3
5
  DEFAULT_PRE_RELEASE_INITIAL_NUMBER = Verto.config.pre_release.initial_number
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StrictHash < Hash
4
+ def initialize(hash, default_proc: nil)
5
+ super()
6
+ self.default_proc = default_proc if default_proc
7
+ merge!(hash)
8
+ end
9
+ end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open3'
2
4
 
3
5
  module Verto
4
6
  class SystemCommandExecutor
5
7
  include Verto.import['project.path', 'stdout', 'stderr']
6
8
 
7
- class Result < Struct.new(:output, :error, :result)
9
+ Result = Struct.new(:output, :error, :result) do
8
10
  def success?
9
11
  result.success?
10
12
  end
@@ -16,7 +18,7 @@ module Verto
16
18
  Error = Class.new(StandardError)
17
19
 
18
20
  def run(command)
19
- stderr.puts running_log(command, path) if stderr
21
+ stderr&.puts running_log(command, path)
20
22
 
21
23
  Open3.popen3(command, chdir: path.to_s) do |_, stdout, stderr, wait_thread|
22
24
  @output = stdout.read
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TagFilter
2
- REALEASE_ONLY = /\d+\.\d+\.\d+$/
3
- PRE_REALEASE_ONLY = /\d+\.\d+\.\d+-.*\d+/
4
+ RELEASE_ONLY = /\d+\.\d+\.\d+$/.freeze
5
+ PRE_RELEASE_ONLY = /\d+\.\d+\.\d+-.*\d+/.freeze
4
6
 
5
7
  FILTERS = {
6
- release_only: REALEASE_ONLY,
7
- pre_release_only: PRE_REALEASE_ONLY,
8
+ release_only: RELEASE_ONLY,
9
+ pre_release_only: PRE_RELEASE_ONLY,
8
10
  all: nil
9
- }
11
+ }.freeze
10
12
 
11
13
  def self.for(tag_key)
12
14
  FILTERS[tag_key.to_sym] if tag_key
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Verto
2
4
  class Template
3
5
  def self.render(template_name, to:)
@@ -1,4 +1,4 @@
1
- verto_version '0.7.0'
1
+ verto_version '0.10.2'
2
2
 
3
3
  config {
4
4
  # version.prefix = 'v' # Adds a version_prefix
@@ -6,32 +6,35 @@ config {
6
6
  # project.path = "#{project_path}" # Configures a custom project path
7
7
  # git.pull_before_tag_creation = true # Pull Changes before tag creation
8
8
  # git.push_after_tag_creation = true # Push changes after tag creation
9
+
10
+ ## CHANGELOG FORMAT
11
+ ## Verto uses Mustache template rendering to render changelog updates, the default value is:
12
+ ##
13
+ ## ## {{new_version}} - #{Time.now.strftime('%d/%m/%Y')}
14
+ ## {{#version_changes}}
15
+ ## * {{.}}
16
+ ## {{/version_changes}}
17
+ ##
18
+ ## A custom format can be specified, eg:
19
+ # changelog.format = <<~CHANGELOG
20
+ # ## {{new_version}}
21
+ # {{#version_changes}}
22
+ # * {{.}}
23
+ # {{/version_changes}}
24
+ # CHANGELOG
9
25
  }
10
26
 
11
27
  context(branch('master')) {
12
28
  before_command_tag_up {
13
- git!('pull origin master')
14
29
  command_options.add(filter: 'release_only')
15
30
  }
16
31
 
17
- before_tag_creation{
18
- version_changes = ""
19
- # Uncomment to get Merged PRs Titles as changes to add in CHANGELOG.
20
- # version_changes = sh(
21
- # %q#git log --oneline --decorate | grep -B 100 -m 1 "tag:" | grep "pull request" | awk '{print $1}' | xargs git show --format='%b' | grep -v Approved | grep -v "^$" | grep -E "^[[:space:]]*\[.*\]" | sed 's/^[[:space:]]*\(.*\)/ * \1/'#, output: false
22
- # ).output
23
-
24
- puts "---------------------------"
25
- version_changes = "## #{new_version} - #{Time.now.strftime('%d/%m/%Y')}\n#{version_changes}\n"
26
- exit unless confirm("Create new Realease?\n" \
27
- "---------------------------\n" \
28
- "#{version_changes}" \
29
- "---------------------------\n"
30
- )
31
-
32
- # CHANGELOG
33
- file('CHANGELOG.md').prepend(version_changes)
34
- git('add CHANGELOG.md')
32
+ before_tag_creation {
33
+ # Uncomment to update CHANGELOG file
34
+ # update_changelog(with: :merged_pull_requests_with_bracketed_labels,
35
+ # confirmation: true,
36
+ # filename: 'CHANGELOG.md')
37
+ # git('add CHANGELOG.md')
35
38
 
36
39
  # Uncomment to update the version in other files, like package.json
37
40
  # file('package.json').replace(/"(\d+)\.(\d+)\.(\d+)(-?.*)"/, %Q{"#{new_version}"})
@@ -39,11 +42,6 @@ context(branch('master')) {
39
42
 
40
43
  git('commit -m "Updates CHANGELOG"')
41
44
  }
42
-
43
- after_command_tag_up {
44
- git('push --tags')
45
- git('push origin master')
46
- }
47
45
  }
48
46
 
49
47
  # Uncomment to get a specific pre_release proccess, like a staging or qa branch
@@ -60,13 +58,12 @@ context(branch('master')) {
60
58
  # }
61
59
 
62
60
  # after_command_tag_up {
63
- # git('push --tags')
64
- # git('push origin staging')
61
+ # sh('some command')
65
62
  # }
66
63
  #}
67
64
 
68
65
  # Uncomment to block tag creation in other branchs
69
66
  #context(!branch('master', 'staging')) {
70
- # error "Tags only can be created in master or staging branch"
67
+ # error 'Tags only can be created in master or staging branch'
71
68
  # exit
72
69
  #}
data/lib/verto/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Verto
2
- VERSION = "0.7.0"
4
+ VERSION = '0.10.2'
3
5
  end
data/verto.gemspec CHANGED
@@ -1,40 +1,44 @@
1
- lib = File.expand_path("lib", __dir__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "verto/version"
5
+ require 'verto/version'
4
6
 
5
7
  Gem::Specification.new do |spec|
6
- spec.name = "verto"
8
+ spec.name = 'verto'
7
9
  spec.version = Verto::VERSION
8
- spec.authors = ["Carlos Atkinson"]
9
- spec.email = ["carlos.atks@gmail.com"]
10
-
11
- spec.summary = %q{Verto helps you to versionate your project}
12
- spec.homepage = "https://github.com/catks/verto"
13
- spec.license = "MIT"
10
+ spec.authors = ['Carlos Atkinson']
11
+ spec.email = ['carlos.atks@gmail.com']
14
12
 
13
+ spec.summary = 'Verto helps you to versionate your project'
14
+ spec.homepage = 'https://github.com/catks/verto'
15
+ spec.license = 'MIT'
15
16
 
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/catks/verto"
18
- spec.metadata["changelog_uri"] = "https://github.com/catks/verto/blob/master/CHANGELOG.md"
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/catks/verto'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/catks/verto/blob/master/CHANGELOG.md'
19
20
 
20
21
  # Specify which files should be added to the gem when it is released.
21
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
25
  end
25
- spec.bindir = "exe"
26
+ spec.bindir = 'exe'
26
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
28
+ spec.require_paths = ['lib']
29
+ spec.required_ruby_version = '>= 2.5'
28
30
 
29
- spec.add_dependency "thor", "~> 1.0.1"
30
- spec.add_dependency "dry-configurable", "~> 0.8"
31
- spec.add_dependency "dry-container", "~> 0.7"
32
- spec.add_dependency "dry-auto_inject", "~> 0.7"
33
- spec.add_dependency "vseries", "~> 0.2"
31
+ spec.add_dependency 'dry-auto_inject', '~> 0.7'
32
+ spec.add_dependency 'dry-configurable', '~> 0.8'
33
+ spec.add_dependency 'dry-container', '~> 0.7'
34
+ spec.add_dependency 'mustache', '~> 1.1.1'
35
+ spec.add_dependency 'thor', '~> 1.0.1'
36
+ spec.add_dependency 'vseries', '~> 0.2'
34
37
 
35
- spec.add_development_dependency "byebug"
36
- spec.add_development_dependency "bundler", "~> 2.0"
37
- spec.add_development_dependency "rake", "~> 13.0"
38
- spec.add_development_dependency "rspec", "~> 3.0"
39
- spec.add_development_dependency "simplecov", "~> 0.18.0"
38
+ spec.add_development_dependency 'bundler', '~> 2.0'
39
+ spec.add_development_dependency 'byebug'
40
+ spec.add_development_dependency 'rake', '~> 13.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ spec.add_development_dependency 'rubocop'
43
+ spec.add_development_dependency 'simplecov', '~> 0.17.0'
40
44
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Atkinson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-29 00:00:00.000000000 Z
11
+ date: 2021-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
14
+ name: dry-auto_inject
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.1
19
+ version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.1
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dry-configurable
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,47 +53,47 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.7'
55
55
  - !ruby/object:Gem::Dependency
56
- name: dry-auto_inject
56
+ name: mustache
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.7'
61
+ version: 1.1.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.7'
68
+ version: 1.1.1
69
69
  - !ruby/object:Gem::Dependency
70
- name: vseries
70
+ name: thor
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.2'
75
+ version: 1.0.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.2'
82
+ version: 1.0.1
83
83
  - !ruby/object:Gem::Dependency
84
- name: byebug
84
+ name: vseries
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
89
+ version: '0.2'
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '0.2'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rake
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -136,20 +150,34 @@ dependencies:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: '3.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: simplecov
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
171
  - - "~>"
144
172
  - !ruby/object:Gem::Version
145
- version: 0.18.0
173
+ version: 0.17.0
146
174
  type: :development
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
178
  - - "~>"
151
179
  - !ruby/object:Gem::Version
152
- version: 0.18.0
180
+ version: 0.17.0
153
181
  description:
154
182
  email:
155
183
  - carlos.atks@gmail.com
@@ -158,10 +186,12 @@ executables:
158
186
  extensions: []
159
187
  extra_rdoc_files: []
160
188
  files:
189
+ - ".github/workflows/ruby.yml"
161
190
  - ".gitignore"
162
191
  - ".rspec"
192
+ - ".rubocop.yml"
193
+ - ".rubocop_todo.yml"
163
194
  - ".ruby-version"
164
- - ".travis.yml"
165
195
  - CHANGELOG.md
166
196
  - Dockerfile
167
197
  - Gemfile
@@ -172,6 +202,7 @@ files:
172
202
  - Vertofile
173
203
  - bin/console
174
204
  - bin/setup
205
+ - djin.yml
175
206
  - docker-entrypoint.sh
176
207
  - exe/verto
177
208
  - lib/verto.rb
@@ -184,9 +215,12 @@ files:
184
215
  - lib/verto/dsl/hook.rb
185
216
  - lib/verto/dsl/interpreter.rb
186
217
  - lib/verto/dsl/syntax.rb
218
+ - lib/verto/dsl/update_changelog.rb
187
219
  - lib/verto/repositories/tag_repository.rb
220
+ - lib/verto/utils/cli_helpers.rb
188
221
  - lib/verto/utils/command_options.rb
189
222
  - lib/verto/utils/semantic_version.rb
223
+ - lib/verto/utils/strict_hash.rb
190
224
  - lib/verto/utils/system_command_executor.rb
191
225
  - lib/verto/utils/tag_filter.rb
192
226
  - lib/verto/utils/template.rb
@@ -208,7 +242,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
242
  requirements:
209
243
  - - ">="
210
244
  - !ruby/object:Gem::Version
211
- version: '0'
245
+ version: '2.5'
212
246
  required_rubygems_version: !ruby/object:Gem::Requirement
213
247
  requirements:
214
248
  - - ">="