danger-dangermattic 1.1.1 â 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/reusable-retry-buildkite-step-on-events.yml +4 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile.lock +22 -32
- data/Rakefile +88 -1
- data/danger-dangermattic.gemspec +1 -1
- data/lib/dangermattic/gem_version.rb +1 -1
- data/rakelib/changelog_parser.rake +108 -0
- data/rakelib/console.rake +46 -0
- data/rakelib/git_helpers.rake +39 -0
- data/spec/spec_helper.rb +0 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e67bce42d784090d66f708da30837272d7ba007361e0ca5e8a3112934f7662c
|
4
|
+
data.tar.gz: b52fd5c635ff28d370d19cbbcb5ce0149e947fdb7f6f2fd10b8e7e00543adf7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e9316d9415127bfef3be854d7ef5662f15df950f623123f1c325ef282e520f0f75d229d6955ec5980cc4286e7c67a5f4738c76486a7a68f316cdc467da7f812
|
7
|
+
data.tar.gz: 58f1deea10b0c92e769de341fee2e918c04321b8bff563bf872e60cd4c8dba30d6b4dd0caf99c7ccdd2cec0e6c309ff5af17ad069ec2e9c27f194c74c061ec8d
|
@@ -35,7 +35,11 @@ jobs:
|
|
35
35
|
runs-on: ubuntu-latest
|
36
36
|
steps:
|
37
37
|
- name: "đ Retry job on the latest Buildkite Build"
|
38
|
+
env:
|
39
|
+
READ_ONLY_MODE: ${{ github.event.pull_request.head.repo.fork || github.actor == 'dependabot[bot]' }}
|
38
40
|
run: |
|
41
|
+
[ "$READ_ONLY_MODE" = true ] && { echo "âšī¸ Cannot retry a Buildkite job from GitHub when running in read-only mode (from a fork or a Dependabot Pull Request). Please find the Buildkite job and retry manually."; exit 0; }
|
42
|
+
|
39
43
|
ORG_SLUG="${{ inputs.org-slug }}"
|
40
44
|
PIPELINE_SLUG="${{ inputs.pipeline-slug }}"
|
41
45
|
RETRY_STEP_KEY="${{ inputs.retry-step-key }}"
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,30 @@
|
|
2
2
|
|
3
3
|
---
|
4
4
|
|
5
|
+
## Trunk
|
6
|
+
|
7
|
+
### Breaking Changes
|
8
|
+
|
9
|
+
_None_
|
10
|
+
|
11
|
+
### New Features
|
12
|
+
|
13
|
+
_None_
|
14
|
+
|
15
|
+
### Bug Fixes
|
16
|
+
|
17
|
+
_None_
|
18
|
+
|
19
|
+
### Internal Changes
|
20
|
+
|
21
|
+
_None_
|
22
|
+
|
23
|
+
## 1.1.2
|
24
|
+
|
25
|
+
### Internal Changes
|
26
|
+
|
27
|
+
- Bump Ruby dependencies (#76)
|
28
|
+
|
5
29
|
## 1.1.1
|
6
30
|
|
7
31
|
### Internal Changes
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-dangermattic (1.1.
|
4
|
+
danger-dangermattic (1.1.2)
|
5
5
|
danger (~> 9.4)
|
6
6
|
danger-plugin-api (~> 1.0)
|
7
7
|
danger-rubocop (~> 0.13)
|
@@ -10,10 +10,9 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
addressable (2.8.
|
14
|
-
public_suffix (>= 2.0.2, <
|
13
|
+
addressable (2.8.7)
|
14
|
+
public_suffix (>= 2.0.2, < 7.0)
|
15
15
|
ast (2.4.2)
|
16
|
-
base64 (0.2.0)
|
17
16
|
claide (1.1.0)
|
18
17
|
claide-plugins (0.9.2)
|
19
18
|
cork
|
@@ -23,7 +22,7 @@ GEM
|
|
23
22
|
colored2 (3.1.2)
|
24
23
|
cork (0.3.0)
|
25
24
|
colored2 (~> 3.1)
|
26
|
-
danger (9.
|
25
|
+
danger (9.5.0)
|
27
26
|
claide (~> 1.0)
|
28
27
|
claide-plugins (>= 0.9.2)
|
29
28
|
colored2 (~> 3.1)
|
@@ -33,7 +32,6 @@ GEM
|
|
33
32
|
git (~> 1.13)
|
34
33
|
kramdown (~> 2.3)
|
35
34
|
kramdown-parser-gfm (~> 1.0)
|
36
|
-
no_proxy_fix
|
37
35
|
octokit (>= 4.0)
|
38
36
|
terminal-table (>= 1, < 4)
|
39
37
|
danger-plugin-api (1.0.0)
|
@@ -42,13 +40,15 @@ GEM
|
|
42
40
|
danger
|
43
41
|
rubocop (~> 1.0)
|
44
42
|
diff-lcs (1.5.1)
|
45
|
-
faraday (2.
|
43
|
+
faraday (2.10.1)
|
46
44
|
faraday-net_http (>= 2.0, < 3.2)
|
45
|
+
logger
|
47
46
|
faraday-http-cache (2.5.1)
|
48
47
|
faraday (>= 0.8)
|
49
|
-
faraday-net_http (3.1.
|
48
|
+
faraday-net_http (3.1.1)
|
50
49
|
net-http
|
51
|
-
ffi (1.
|
50
|
+
ffi (1.17.0)
|
51
|
+
ffi (1.17.0-arm64-darwin)
|
52
52
|
formatador (1.1.0)
|
53
53
|
git (1.19.1)
|
54
54
|
addressable (~> 2.8)
|
@@ -76,30 +76,29 @@ GEM
|
|
76
76
|
listen (3.9.0)
|
77
77
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
78
78
|
rb-inotify (~> 0.9, >= 0.9.10)
|
79
|
+
logger (1.6.0)
|
79
80
|
lumberjack (1.2.10)
|
80
81
|
method_source (1.1.0)
|
81
82
|
nap (1.1.0)
|
82
83
|
nenv (0.3.0)
|
83
84
|
net-http (0.4.1)
|
84
85
|
uri
|
85
|
-
no_proxy_fix (0.1.2)
|
86
86
|
notiffany (0.1.3)
|
87
87
|
nenv (~> 0.1)
|
88
88
|
shellany (~> 0.0)
|
89
|
-
octokit (
|
90
|
-
base64
|
89
|
+
octokit (9.1.0)
|
91
90
|
faraday (>= 1, < 3)
|
92
91
|
sawyer (~> 0.9)
|
93
92
|
open4 (1.3.4)
|
94
|
-
parallel (1.
|
95
|
-
parser (3.3.
|
93
|
+
parallel (1.25.1)
|
94
|
+
parser (3.3.4.0)
|
96
95
|
ast (~> 2.4.1)
|
97
96
|
racc
|
98
97
|
pry (0.14.2)
|
99
98
|
coderay (~> 1.1)
|
100
99
|
method_source (~> 1.0)
|
101
|
-
public_suffix (
|
102
|
-
racc (1.8.
|
100
|
+
public_suffix (6.0.1)
|
101
|
+
racc (1.8.1)
|
103
102
|
rainbow (3.1.1)
|
104
103
|
rake (13.2.1)
|
105
104
|
rb-fsevent (0.11.2)
|
@@ -107,47 +106,38 @@ GEM
|
|
107
106
|
ffi (~> 1.0)
|
108
107
|
rchardet (1.8.0)
|
109
108
|
regexp_parser (2.9.2)
|
110
|
-
rexml (3.
|
111
|
-
strscan
|
109
|
+
rexml (3.3.4)
|
110
|
+
strscan
|
112
111
|
rspec (3.13.0)
|
113
112
|
rspec-core (~> 3.13.0)
|
114
113
|
rspec-expectations (~> 3.13.0)
|
115
114
|
rspec-mocks (~> 3.13.0)
|
116
115
|
rspec-core (3.13.0)
|
117
116
|
rspec-support (~> 3.13.0)
|
118
|
-
rspec-expectations (3.13.
|
117
|
+
rspec-expectations (3.13.1)
|
119
118
|
diff-lcs (>= 1.2.0, < 2.0)
|
120
119
|
rspec-support (~> 3.13.0)
|
121
120
|
rspec-mocks (3.13.1)
|
122
121
|
diff-lcs (>= 1.2.0, < 2.0)
|
123
122
|
rspec-support (~> 3.13.0)
|
124
123
|
rspec-support (3.13.1)
|
125
|
-
rubocop (1.
|
124
|
+
rubocop (1.65.1)
|
126
125
|
json (~> 2.3)
|
127
126
|
language_server-protocol (>= 3.17.0)
|
128
127
|
parallel (~> 1.10)
|
129
128
|
parser (>= 3.3.0.2)
|
130
129
|
rainbow (>= 2.2.2, < 4.0)
|
131
|
-
regexp_parser (>=
|
130
|
+
regexp_parser (>= 2.4, < 3.0)
|
132
131
|
rexml (>= 3.2.5, < 4.0)
|
133
132
|
rubocop-ast (>= 1.31.1, < 2.0)
|
134
133
|
ruby-progressbar (~> 1.7)
|
135
134
|
unicode-display_width (>= 2.4.0, < 3.0)
|
136
135
|
rubocop-ast (1.31.3)
|
137
136
|
parser (>= 3.3.1.0)
|
138
|
-
rubocop-capybara (2.20.0)
|
139
|
-
rubocop (~> 1.41)
|
140
|
-
rubocop-factory_bot (2.25.1)
|
141
|
-
rubocop (~> 1.41)
|
142
137
|
rubocop-rake (0.6.0)
|
143
138
|
rubocop (~> 1.0)
|
144
|
-
rubocop-rspec (
|
145
|
-
rubocop (~> 1.
|
146
|
-
rubocop-capybara (~> 2.17)
|
147
|
-
rubocop-factory_bot (~> 2.22)
|
148
|
-
rubocop-rspec_rails (~> 2.28)
|
149
|
-
rubocop-rspec_rails (2.28.3)
|
150
|
-
rubocop (~> 1.40)
|
139
|
+
rubocop-rspec (3.0.3)
|
140
|
+
rubocop (~> 1.61)
|
151
141
|
ruby-progressbar (1.13.0)
|
152
142
|
sawyer (0.9.2)
|
153
143
|
addressable (>= 2.3.5)
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ task all: %i[specs lint]
|
|
11
11
|
|
12
12
|
desc 'Ensure that the plugin passes `danger plugins lint`'
|
13
13
|
task :danger_lint do
|
14
|
-
sh
|
14
|
+
sh('bundle', 'exec', 'danger', 'plugins', 'lint')
|
15
15
|
end
|
16
16
|
|
17
17
|
desc 'Runs linting tasks: :rubocop and :danger_lint'
|
@@ -22,3 +22,90 @@ RSpec::Core::RakeTask.new(:specs)
|
|
22
22
|
|
23
23
|
desc 'Run RuboCop on the lib/specs directory'
|
24
24
|
RuboCop::RakeTask.new(:rubocop)
|
25
|
+
|
26
|
+
desc 'Generate the docs using YARD'
|
27
|
+
task :doc do
|
28
|
+
sh('bundle', 'exec', 'yard', 'doc')
|
29
|
+
# Open generated doc in browser
|
30
|
+
sh('open', 'yard-doc/index.html')
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Print stats about undocumented methods. Provide an optional path relative to 'lib/dangermattic/plugins' to only show stats for that subdirectory"
|
34
|
+
task :docstats, [:path] do |_, args|
|
35
|
+
path = File.join('lib/dangermattic/plugins', args[:path] || '.')
|
36
|
+
sh('yard', 'stats', '--list-undoc', path)
|
37
|
+
end
|
38
|
+
|
39
|
+
VERSION_FILE = File.join('lib', 'dangermattic', 'gem_version.rb')
|
40
|
+
|
41
|
+
desc 'Create a new version of the dangermattic gem'
|
42
|
+
task :new_release do
|
43
|
+
require_relative(VERSION_FILE)
|
44
|
+
|
45
|
+
parser = ChangelogParser.new(file: 'CHANGELOG.md')
|
46
|
+
latest_version = parser.parse_pending_section
|
47
|
+
|
48
|
+
## Print current info
|
49
|
+
Console.header "Current version is: #{Dangermattic::VERSION}"
|
50
|
+
Console.warning "Warning: Latest version number does not match latest version title in CHANGELOG (#{latest_version})!" unless latest_version == Dangermattic::VERSION
|
51
|
+
|
52
|
+
Console.header 'Pending CHANGELOG:'
|
53
|
+
changelog = parser.cleaned_pending_changelog_lines
|
54
|
+
Console.print_indented_lines(changelog)
|
55
|
+
|
56
|
+
## Prompt for next version number
|
57
|
+
guess = parser.guessed_next_semantic_version(current: Dangermattic::VERSION)
|
58
|
+
new_version = Console.prompt('New version to release', guess)
|
59
|
+
|
60
|
+
## Checkout branch, update files
|
61
|
+
GitHelper.check_or_create_branch(new_version)
|
62
|
+
Console.header 'Update `VERSION` constant in `version.rb`...'
|
63
|
+
update_version_constant(VERSION_FILE, new_version)
|
64
|
+
Console.header 'Updating CHANGELOG...'
|
65
|
+
parser.update_for_new_release(new_version: new_version)
|
66
|
+
|
67
|
+
# Commit and push
|
68
|
+
Console.header 'Commit and push changes...'
|
69
|
+
GitHelper.commit_files("Bumped to version #{new_version}", [VERSION_FILE, 'Gemfile.lock', 'CHANGELOG.md'])
|
70
|
+
|
71
|
+
Console.header 'Opening PR draft in your default browser...'
|
72
|
+
pr_body = <<~BODY
|
73
|
+
Releasing new version #{new_version}.
|
74
|
+
|
75
|
+
# What's Next
|
76
|
+
|
77
|
+
PR Author: Be sure to create and publish a GitHub Release pointing to `trunk` once this PR gets merged,
|
78
|
+
copy/pasting the following text as the GitHub Release's description:
|
79
|
+
```
|
80
|
+
#{changelog.join}
|
81
|
+
```
|
82
|
+
BODY
|
83
|
+
GitHelper.prepare_github_pr("release/#{new_version}", 'trunk', "Release #{new_version} into trunk", pr_body)
|
84
|
+
|
85
|
+
Console.info <<~INSTRUCTIONS
|
86
|
+
|
87
|
+
---------------
|
88
|
+
|
89
|
+
>>> WHAT'S NEXT
|
90
|
+
|
91
|
+
Once the PR is merged, publish a GitHub release for `#{new_version}`, targeting `trunk`,
|
92
|
+
with the following text as description:
|
93
|
+
|
94
|
+
```
|
95
|
+
#{changelog.join}
|
96
|
+
```
|
97
|
+
|
98
|
+
The publication of the new GitHub release will create a git tag, which in turn will trigger
|
99
|
+
a CI workflow that will take care of doing the `gem push` of the new version to RubyGems.
|
100
|
+
|
101
|
+
INSTRUCTIONS
|
102
|
+
end
|
103
|
+
|
104
|
+
def update_version_constant(version_file, new_version)
|
105
|
+
content = File.read(version_file)
|
106
|
+
content.gsub!(/VERSION = .*/, "VERSION = '#{new_version}'")
|
107
|
+
File.write(version_file, content)
|
108
|
+
|
109
|
+
# Updates the Gemfile.lock with the new dangermattic version
|
110
|
+
sh('bundle', 'install', '--quiet')
|
111
|
+
end
|
data/danger-dangermattic.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.required_ruby_version = '~> 3.2'
|
23
23
|
|
24
24
|
spec.add_dependency 'danger', '~> 9.4'
|
25
|
-
spec.
|
25
|
+
spec.add_dependency 'danger-plugin-api', '~> 1.0'
|
26
26
|
|
27
27
|
# Danger plugins
|
28
28
|
spec.add_dependency 'danger-rubocop', '~> 0.13'
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Parses and updates changelog files for software projects.
|
4
|
+
#
|
5
|
+
# This class provides functionality to parse a changelog file, identify pending
|
6
|
+
# sections for upcoming releases, and update the changelog for new releases based on
|
7
|
+
# semantic versioning conventions.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# parser = ChangelogParser.new(file: 'CHANGELOG.md')
|
11
|
+
# latest_version = parser.parse_pending_section
|
12
|
+
# new_version = parser.guessed_next_semantic_version(current: '1.0.0')
|
13
|
+
# parser.update_for_new_release(new_version: new_version)
|
14
|
+
class ChangelogParser
|
15
|
+
PENDING_SECTION_TITLE = 'Trunk'
|
16
|
+
EMPTY_PLACEHOLDER = '_None_'
|
17
|
+
SUBSECTIONS_SEMVER_MAP = { 'Breaking Changes': 3, 'New Features': 2, 'Bug Fixes': 1, 'Internal Changes': 1 }.freeze
|
18
|
+
|
19
|
+
def initialize(file: 'CHANGELOG.md')
|
20
|
+
@lines = File.readlines(file)
|
21
|
+
@current_index = nil
|
22
|
+
@pending_section = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return the title of the section after the pending one -- which should match the latest released version
|
26
|
+
def parse_pending_section
|
27
|
+
(lines_before_first_section, _, title) = advance_to_next_header(level: 2)
|
28
|
+
raise "Expected #{PENDING_SECTION_TITLE} as first section but found #{title} instead." unless title == PENDING_SECTION_TITLE
|
29
|
+
|
30
|
+
subsections = []
|
31
|
+
prev_subtitle = nil
|
32
|
+
loop do
|
33
|
+
(lines, next_level, next_subtitle) = advance_to_next_header(level: 2..3)
|
34
|
+
subsections.append({ title: prev_subtitle, lines: lines }) unless lines.reject { |l| l.chomp.empty? || l.chomp == EMPTY_PLACEHOLDER }.empty?
|
35
|
+
prev_subtitle = next_subtitle
|
36
|
+
|
37
|
+
break if next_level < 3
|
38
|
+
end
|
39
|
+
@pending_section = { lines_before: lines_before_first_section, subsections: subsections, next_title: prev_subtitle }
|
40
|
+
prev_subtitle
|
41
|
+
end
|
42
|
+
|
43
|
+
def cleaned_pending_changelog_lines
|
44
|
+
lines = []
|
45
|
+
@pending_section[:subsections].map do |s|
|
46
|
+
lines.append "### #{s[:title]}\n" unless s[:title].nil? # subsection title is nil for lines between h2 and first h3
|
47
|
+
lines += s[:lines]
|
48
|
+
end
|
49
|
+
lines
|
50
|
+
end
|
51
|
+
|
52
|
+
def guessed_next_semantic_version(current:)
|
53
|
+
comps = current.split('.')
|
54
|
+
idx_to_bump = 3 - semver_category
|
55
|
+
comps[idx_to_bump] = (comps[idx_to_bump].to_i + 1).to_s
|
56
|
+
((idx_to_bump + 1)...(comps.length)).each { |i| comps[i] = '0' }
|
57
|
+
comps.join('.')
|
58
|
+
end
|
59
|
+
|
60
|
+
def update_for_new_release(new_version:, new_file: 'CHANGELOG.md')
|
61
|
+
raise 'You need to call #parse_pending_section first' if @pending_section.nil?
|
62
|
+
|
63
|
+
File.open(new_file, 'w') do |f|
|
64
|
+
f.puts @pending_section[:lines_before]
|
65
|
+
# Empty placeholder section for next version after this one
|
66
|
+
f.puts placeholder_section
|
67
|
+
# Section for new version, with the non-empty subsections found while parsing first section
|
68
|
+
f.puts "## #{new_version}\n\n"
|
69
|
+
f.puts cleaned_pending_changelog_lines
|
70
|
+
f.puts "## #{@pending_section[:next_title]}"
|
71
|
+
f.puts read_up_to_end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# Advance line pointer to next index of provided `level`
|
78
|
+
# @return [Array] A 3-item array of [scanned_lines, next_header_level, next_header_title]
|
79
|
+
def advance_to_next_header(level:)
|
80
|
+
range = level.is_a?(Range) ? level : level..level
|
81
|
+
regex = /^(\#{#{range.min},#{range.max}}) ?([^#].*)$/ # A line starting with {range.min,range.max} times '#' then optional space then a title
|
82
|
+
start_idx = @current_index.nil? ? 0 : @current_index + 1
|
83
|
+
offset = @lines[start_idx...].index { |l| l =~ regex }
|
84
|
+
@current_index = offset.nil? ? -1 : start_idx + offset
|
85
|
+
|
86
|
+
m = regex.match(@lines[@current_index])
|
87
|
+
[@lines[start_idx...@current_index], m[1].length, m[2]]
|
88
|
+
end
|
89
|
+
|
90
|
+
def read_up_to_end
|
91
|
+
idx = @current_index + 1
|
92
|
+
@current_index = -1
|
93
|
+
@lines[idx...]
|
94
|
+
end
|
95
|
+
|
96
|
+
def placeholder_section
|
97
|
+
lines = ["## #{PENDING_SECTION_TITLE}\n\n"]
|
98
|
+
lines += SUBSECTIONS_SEMVER_MAP.keys.map { |s| "### #{s}\n\n#{EMPTY_PLACEHOLDER}\n\n" }
|
99
|
+
lines.join
|
100
|
+
end
|
101
|
+
|
102
|
+
# @return the SemVer category (as described in Gem::Version doc). 3=major, 2=minor, 1=patch
|
103
|
+
def semver_category
|
104
|
+
raise 'You need to call #parse_pending_section first' if @pending_section.nil?
|
105
|
+
|
106
|
+
@pending_section[:subsections].map { |s| SUBSECTIONS_SEMVER_MAP[s[:title].to_sym] || 1 }.max || 1
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Provides methods for colored console output and user interaction.
|
4
|
+
#
|
5
|
+
# The Console module contains methods for printing colored text to the terminal using
|
6
|
+
# ANSI escape codes. It also includes utility methods for prompting user input.
|
7
|
+
module Console
|
8
|
+
# ANSI colors
|
9
|
+
RED = 1
|
10
|
+
GREEN = 2
|
11
|
+
YELLOW = 3
|
12
|
+
PURPLE = 4
|
13
|
+
|
14
|
+
def self.color_puts(lines, color_code:)
|
15
|
+
puts "\x1b[3#{color_code}m#{lines}\x1b[0m"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.header(title)
|
19
|
+
color_puts(">>> #{title}", color_code: GREEN) # green
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.info(text)
|
23
|
+
color_puts(text, color_code: YELLOW) # yellow
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.warning(text)
|
27
|
+
color_puts(text, color_code: RED) # red
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.print_indented_lines(lines)
|
31
|
+
color_puts(lines.map { |l| "| #{l}" }.join, color_code: YELLOW)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.prompt(text, default_value)
|
35
|
+
color_puts("#{text}? [default: #{default_value}] ", color_code: GREEN)
|
36
|
+
answer = $stdin.gets.chomp
|
37
|
+
answer = default_value if answer.empty?
|
38
|
+
answer
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.confirm(text)
|
42
|
+
color_puts("#{text} [y/n]?", color_code: GREEN)
|
43
|
+
answer = $stdin.gets.chomp
|
44
|
+
answer.downcase == 'y'
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
# Helper methods for common Git operations: checking / creating branches, preparing a pull request and
|
6
|
+
# committing / pushing files.
|
7
|
+
module GitHelper
|
8
|
+
def self.current_branch
|
9
|
+
`git --no-pager branch --show-current`.chomp
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.check_or_create_branch(new_version)
|
13
|
+
release_branch = "release/#{new_version}"
|
14
|
+
branch_exists = !`git --no-pager branch -a --list --no-color #{release_branch}`.chomp.empty?
|
15
|
+
if current_branch == release_branch
|
16
|
+
puts 'Already on release branch'
|
17
|
+
elsif branch_exists
|
18
|
+
Rake.sh('git', 'checkout', release_branch)
|
19
|
+
else # create it
|
20
|
+
abort('Aborted, as not run from trunk nor release branch') unless current_branch == 'trunk' || Console.confirm("You are not on 'trunk', nor already on '#{release_branch}'. Do you really want to cut the release branch from #{current_branch}?")
|
21
|
+
|
22
|
+
Rake.sh('git', 'checkout', '-b', release_branch)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.prepare_github_pr(head, base, title, body)
|
27
|
+
require 'open-uri'
|
28
|
+
qtitle = CGI.escape(title)
|
29
|
+
qbody = CGI.escape(body)
|
30
|
+
uri = "https://github.com/Automattic/dangermattic/compare/#{base}...#{head}?expand=1&title=#{qtitle}&body=#{qbody}"
|
31
|
+
Rake.sh('open', uri)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.commit_files(message, files, push: true)
|
35
|
+
Rake.sh('git', 'add', *files)
|
36
|
+
Rake.sh('git', 'commit', '-m', message)
|
37
|
+
Rake.sh('git', 'push', '-q', '-u', 'origin', current_branch) if push
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -28,7 +28,6 @@ require 'danger_plugin'
|
|
28
28
|
# it comes with an extra function `.string` which will
|
29
29
|
# strip all ANSI colours from the string.
|
30
30
|
|
31
|
-
# rubocop:disable Lint/NestedMethodDefinition
|
32
31
|
def testing_ui
|
33
32
|
@output = StringIO.new
|
34
33
|
def @output.winsize
|
@@ -41,7 +40,6 @@ def testing_ui
|
|
41
40
|
end
|
42
41
|
cork
|
43
42
|
end
|
44
|
-
# rubocop:enable Lint/NestedMethodDefinition
|
45
43
|
|
46
44
|
# Example environment (ENV)
|
47
45
|
def testing_env
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-dangermattic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Automattic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05
|
11
|
+
date: 2024-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger
|
@@ -234,6 +234,9 @@ files:
|
|
234
234
|
- lib/dangermattic/plugins/pr_size_checker.rb
|
235
235
|
- lib/dangermattic/plugins/tracks_checker.rb
|
236
236
|
- lib/dangermattic/plugins/view_changes_checker.rb
|
237
|
+
- rakelib/changelog_parser.rake
|
238
|
+
- rakelib/console.rake
|
239
|
+
- rakelib/git_helpers.rake
|
237
240
|
- spec/android_release_checker_spec.rb
|
238
241
|
- spec/android_strings_checker_spec.rb
|
239
242
|
- spec/android_unit_test_checker_spec.rb
|