bake-modernize 0.26.0 → 0.27.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bake/modernize/actions.rb +1 -1
- data/bake/modernize/rubocop.rb +21 -0
- data/bake/modernize.rb +13 -2
- data/lib/bake/modernize/license.rb +36 -2
- data/lib/bake/modernize/version.rb +1 -1
- data/lib/bake/modernize.rb +8 -0
- data/template/rubocop/.github/workflows/rubocop.yaml +36 -0
- data/template/rubocop/.rubocop.yml +46 -0
- data.tar.gz.sig +0 -0
- metadata +6 -4
- metadata.gz.sig +0 -0
- data/bake/modernize/frozen_string_literal.rb +0 -53
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1400d55cce047ae23e05f6103b5895209c78b30900503faaea26d149b3035c9
|
|
4
|
+
data.tar.gz: 49b2ff82aaa4dbde6f6aed09166c40b8d836f60101913080339c612cdcf89638
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9818500ac4ae7af1000527f9008ad4bfc202a4372e5069d5eda5d99aed1c7a89558f0a5f3ca4099420c3bc3cff0f41741c5011efd36eaca34da87517f50d76f6
|
|
7
|
+
data.tar.gz: 4900ea0f2307f4186d8b7a854a45239891d30462ac34480dba311a06c2b8cbba89230c78eca7835f1dabe90bd56d598323433b14421528285ad3c07c75ead2ee
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/bake/modernize/actions.rb
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2024, by Samuel Williams.
|
|
5
|
+
|
|
6
|
+
require 'bake/modernize'
|
|
7
|
+
require 'build/files/system'
|
|
8
|
+
|
|
9
|
+
def rubocop
|
|
10
|
+
update(root: Dir.pwd)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def update(root:)
|
|
14
|
+
system("bundle", "add", "rubocop", "--group", "test", chdir: root)
|
|
15
|
+
|
|
16
|
+
template_root = Bake::Modernize.template_path_for('rubocop')
|
|
17
|
+
Bake::Modernize.copy_template(template_root, root)
|
|
18
|
+
|
|
19
|
+
system("bundle", "update", chdir: root)
|
|
20
|
+
system("bundle", "exec", "rubocop", chdir: root)
|
|
21
|
+
end
|
data/bake/modernize.rb
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2020-
|
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
def modernize
|
|
7
|
-
call(
|
|
7
|
+
call(
|
|
8
|
+
'modernize:git',
|
|
9
|
+
'modernize:readme',
|
|
10
|
+
'modernize:actions',
|
|
11
|
+
'modernize:editorconfig',
|
|
12
|
+
'modernize:gemfile',
|
|
13
|
+
'modernize:rubocop',
|
|
14
|
+
'modernize:signing',
|
|
15
|
+
'modernize:gemspec',
|
|
16
|
+
'modernize:license',
|
|
17
|
+
'modernize:contributing',
|
|
18
|
+
)
|
|
8
19
|
end
|
|
@@ -8,10 +8,13 @@ require 'yaml'
|
|
|
8
8
|
|
|
9
9
|
module Bake
|
|
10
10
|
module Modernize
|
|
11
|
+
# Support the analysis of authorship and license details.
|
|
11
12
|
module License
|
|
12
13
|
GIT_BLAME_IGNORE_REVS = ".git-blame-ignore-revs"
|
|
13
14
|
|
|
15
|
+
# Represents revisions to skip when analyzing authorship.
|
|
14
16
|
class SkipList
|
|
17
|
+
# Load the skip list from a directory.
|
|
15
18
|
def self.for(root)
|
|
16
19
|
full_path = File.join(root, GIT_BLAME_IGNORE_REVS)
|
|
17
20
|
|
|
@@ -22,10 +25,14 @@ module Bake
|
|
|
22
25
|
end
|
|
23
26
|
end
|
|
24
27
|
|
|
28
|
+
# Create a new skip list with the given revisions.
|
|
29
|
+
#
|
|
30
|
+
# @parameter revisions [Array(String)] The revisions to skip.
|
|
25
31
|
def initialize(revisions = [])
|
|
26
32
|
@revisions = Set.new(revisions)
|
|
27
33
|
end
|
|
28
34
|
|
|
35
|
+
# Extract the revisions from the given path.
|
|
29
36
|
def extract(path)
|
|
30
37
|
File.open(path, 'r') do |file|
|
|
31
38
|
file.each_line do |line|
|
|
@@ -37,12 +44,15 @@ module Bake
|
|
|
37
44
|
end
|
|
38
45
|
end
|
|
39
46
|
|
|
47
|
+
# Check if the given commit should be ignored.
|
|
40
48
|
def ignore?(commit)
|
|
41
49
|
@revisions.include?(commit.oid)
|
|
42
50
|
end
|
|
43
51
|
end
|
|
44
52
|
|
|
53
|
+
# Represents a mailmap file which maps commit emails to proper names.
|
|
45
54
|
class Mailmap
|
|
55
|
+
# Load the mailmap from a directory.
|
|
46
56
|
def self.for(root)
|
|
47
57
|
full_path = File.join(root, '.mailmap')
|
|
48
58
|
|
|
@@ -53,12 +63,15 @@ module Bake
|
|
|
53
63
|
end
|
|
54
64
|
end
|
|
55
65
|
|
|
66
|
+
# Create a new, empty, mailmap.
|
|
56
67
|
def initialize
|
|
57
68
|
@names = {}
|
|
58
69
|
end
|
|
59
70
|
|
|
71
|
+
# @attribute [Hash(String, String)] The mapping of commit emails to proper names.
|
|
60
72
|
attr :names
|
|
61
73
|
|
|
74
|
+
# Extract the mailmap from the given path.
|
|
62
75
|
def extract(path)
|
|
63
76
|
File.open(path, 'r') do |file|
|
|
64
77
|
file.each_line do |line|
|
|
@@ -85,6 +98,7 @@ module Bake
|
|
|
85
98
|
\s+<(?<commit_email>[^>]+)>
|
|
86
99
|
/x
|
|
87
100
|
|
|
101
|
+
# Extract the mailmap format from a line of input.
|
|
88
102
|
def extract_from_line(line)
|
|
89
103
|
line.match(PATTERN)
|
|
90
104
|
end
|
|
@@ -95,6 +109,7 @@ module Bake
|
|
|
95
109
|
# The default path is the root of the repository and for authors who have contributed to the entire repository or unspecified paths in the past.
|
|
96
110
|
DEFAULT_PATH = '.'
|
|
97
111
|
|
|
112
|
+
# Load contributors from a directory.
|
|
98
113
|
def self.for(root)
|
|
99
114
|
full_path = File.join(root, '.contributors.yaml')
|
|
100
115
|
|
|
@@ -104,11 +119,13 @@ module Bake
|
|
|
104
119
|
return contributors
|
|
105
120
|
end
|
|
106
121
|
end
|
|
107
|
-
|
|
122
|
+
|
|
123
|
+
# Create a new, empty, contributors list.
|
|
108
124
|
def initialize
|
|
109
125
|
@contributions = []
|
|
110
126
|
end
|
|
111
127
|
|
|
128
|
+
# Iterate over each contribution.
|
|
112
129
|
def each(&block)
|
|
113
130
|
@contributions.each do |contribution|
|
|
114
131
|
author = contribution[:author]
|
|
@@ -120,13 +137,17 @@ module Bake
|
|
|
120
137
|
end
|
|
121
138
|
end
|
|
122
139
|
|
|
140
|
+
# Extract the contributors from the given path.
|
|
123
141
|
def extract(path)
|
|
124
142
|
@contributions.concat(
|
|
125
143
|
YAML.load_file(path, aliases: true, symbolize_names: true, permitted_classes: [Symbol, Date, Time])
|
|
126
144
|
)
|
|
127
145
|
end
|
|
128
146
|
|
|
147
|
+
# @attribute [Array(Hash)] The list of paths from a given contribution.
|
|
129
148
|
def paths_for(contribution)
|
|
149
|
+
return to_enum(:paths_for, contribution) unless block_given?
|
|
150
|
+
|
|
130
151
|
if path = contribution[:path]
|
|
131
152
|
yield path
|
|
132
153
|
# elsif paths = contribution[:paths]
|
|
@@ -138,8 +159,10 @@ module Bake
|
|
|
138
159
|
end
|
|
139
160
|
end
|
|
140
161
|
end
|
|
141
|
-
|
|
162
|
+
|
|
163
|
+
# Represents the authorship of a repository.
|
|
142
164
|
class Authorship
|
|
165
|
+
# Represents a modification to a file.
|
|
143
166
|
Modification = Struct.new(:author, :time, :path, :id) do
|
|
144
167
|
def full_name
|
|
145
168
|
author[:name]
|
|
@@ -159,6 +182,7 @@ module Bake
|
|
|
159
182
|
end
|
|
160
183
|
end
|
|
161
184
|
|
|
185
|
+
# Represents the copyright for an author.
|
|
162
186
|
Copyright = Struct.new(:dates, :author) do
|
|
163
187
|
def <=> other
|
|
164
188
|
self.to_a <=> other.to_a
|
|
@@ -170,14 +194,19 @@ module Bake
|
|
|
170
194
|
end
|
|
171
195
|
end
|
|
172
196
|
|
|
197
|
+
# Create a new, empty, authorship.
|
|
173
198
|
def initialize
|
|
174
199
|
@paths = Hash.new{|h,k| h[k] = []}
|
|
175
200
|
@commits = Hash.new{|h,k| h[k] = []}
|
|
176
201
|
end
|
|
177
202
|
|
|
203
|
+
# @attribute [Hash(String, Array(Modification))] The mapping of paths to modifications.
|
|
178
204
|
attr :paths
|
|
205
|
+
|
|
206
|
+
# @attribute [Hash(String, Array(Modification))] The mapping of commits to modifications.
|
|
179
207
|
attr :commits
|
|
180
208
|
|
|
209
|
+
# Add a modification to the authorship.
|
|
181
210
|
def add(path, author, time, id = nil)
|
|
182
211
|
modification = Modification.new(author, time, path, id)
|
|
183
212
|
|
|
@@ -185,6 +214,7 @@ module Bake
|
|
|
185
214
|
@paths[path] << modification
|
|
186
215
|
end
|
|
187
216
|
|
|
217
|
+
# Extract the authorship from the given root directory.
|
|
188
218
|
def extract(root = Dir.pwd)
|
|
189
219
|
mailmap = Mailmap.for(root)
|
|
190
220
|
skip_list = SkipList.for(root)
|
|
@@ -200,6 +230,7 @@ module Bake
|
|
|
200
230
|
return self
|
|
201
231
|
end
|
|
202
232
|
|
|
233
|
+
# Authors, sorted by contribution date.
|
|
203
234
|
def sorted_authors
|
|
204
235
|
authors = Hash.new{|h,k| h[k] = 0}
|
|
205
236
|
|
|
@@ -212,14 +243,17 @@ module Bake
|
|
|
212
243
|
return authors.sort_by{|k,v| [-v, k]}.map(&:first)
|
|
213
244
|
end
|
|
214
245
|
|
|
246
|
+
# All copyrights.
|
|
215
247
|
def copyrights
|
|
216
248
|
copyrights_for_modifications(@paths.values.flatten)
|
|
217
249
|
end
|
|
218
250
|
|
|
251
|
+
# All copyrights for a given path.
|
|
219
252
|
def copyrights_for_path(path)
|
|
220
253
|
copyrights_for_modifications(@paths[path])
|
|
221
254
|
end
|
|
222
255
|
|
|
256
|
+
# All copyrights for a given modification.
|
|
223
257
|
def copyrights_for_modifications(modifications)
|
|
224
258
|
authors = modifications.group_by{|modification| modification.full_name}
|
|
225
259
|
|
data/lib/bake/modernize.rb
CHANGED
|
@@ -8,16 +8,20 @@ require_relative 'modernize/version'
|
|
|
8
8
|
require 'build/files/glob'
|
|
9
9
|
require 'fileutils'
|
|
10
10
|
|
|
11
|
+
# @namespace
|
|
11
12
|
module Bake
|
|
13
|
+
# @namespace
|
|
12
14
|
module Modernize
|
|
13
15
|
ROOT = File.expand_path("../..", __dir__)
|
|
14
16
|
|
|
15
17
|
TEMPLATE_ROOT = Build::Files::Path.new(ROOT) + "template"
|
|
16
18
|
|
|
19
|
+
# Compute the template root path relative to the gem root.
|
|
17
20
|
def self.template_path_for(path)
|
|
18
21
|
TEMPLATE_ROOT + path
|
|
19
22
|
end
|
|
20
23
|
|
|
24
|
+
# Check if the destination path is stale compared to the source path.
|
|
21
25
|
def self.stale?(source_path, destination_path)
|
|
22
26
|
if File.exist?(destination_path)
|
|
23
27
|
return !FileUtils.identical?(source_path, destination_path)
|
|
@@ -26,6 +30,10 @@ module Bake
|
|
|
26
30
|
return true
|
|
27
31
|
end
|
|
28
32
|
|
|
33
|
+
# Copy files from the source path to the destination path.
|
|
34
|
+
#
|
|
35
|
+
# @parameter source_path [String] The source path.
|
|
36
|
+
# @parameter destination_path [String] The destination path.
|
|
29
37
|
def self.copy_template(source_path, destination_path)
|
|
30
38
|
glob = Build::Files::Glob.new(source_path, '**/*')
|
|
31
39
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Test External
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
permissions:
|
|
6
|
+
contents: read
|
|
7
|
+
|
|
8
|
+
env:
|
|
9
|
+
CONSOLE_OUTPUT: XTerm
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
name: ${{matrix.ruby}} on ${{matrix.os}}
|
|
14
|
+
runs-on: ${{matrix.os}}-latest
|
|
15
|
+
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
os:
|
|
19
|
+
- ubuntu
|
|
20
|
+
- macos
|
|
21
|
+
|
|
22
|
+
ruby:
|
|
23
|
+
- "3.1"
|
|
24
|
+
- "3.2"
|
|
25
|
+
- "3.3"
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
- uses: ruby/setup-ruby@v1
|
|
30
|
+
with:
|
|
31
|
+
ruby-version: ${{matrix.ruby}}
|
|
32
|
+
bundler-cache: true
|
|
33
|
+
|
|
34
|
+
- name: Run RuboCop
|
|
35
|
+
timeout-minutes: 10
|
|
36
|
+
run: bundle exec rubocop
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
DisabledByDefault: true
|
|
3
|
+
|
|
4
|
+
Layout/IndentationStyle:
|
|
5
|
+
Enabled: true
|
|
6
|
+
EnforcedStyle: tabs
|
|
7
|
+
|
|
8
|
+
Layout/InitialIndentation:
|
|
9
|
+
Enabled: true
|
|
10
|
+
|
|
11
|
+
Layout/IndentationWidth:
|
|
12
|
+
Enabled: true
|
|
13
|
+
Width: 1
|
|
14
|
+
|
|
15
|
+
Layout/IndentationConsistency:
|
|
16
|
+
Enabled: true
|
|
17
|
+
EnforcedStyle: normal
|
|
18
|
+
|
|
19
|
+
Layout/EndAlignment:
|
|
20
|
+
Enabled: true
|
|
21
|
+
EnforcedStyleAlignWith: start_of_line
|
|
22
|
+
|
|
23
|
+
Layout/BeginEndAlignment:
|
|
24
|
+
Enabled: true
|
|
25
|
+
EnforcedStyleAlignWith: start_of_line
|
|
26
|
+
|
|
27
|
+
Layout/ElseAlignment:
|
|
28
|
+
Enabled: true
|
|
29
|
+
|
|
30
|
+
Layout/DefEndAlignment:
|
|
31
|
+
Enabled: true
|
|
32
|
+
|
|
33
|
+
Layout/CaseIndentation:
|
|
34
|
+
Enabled: true
|
|
35
|
+
|
|
36
|
+
Layout/CommentIndentation:
|
|
37
|
+
Enabled: true
|
|
38
|
+
|
|
39
|
+
Layout/EmptyLinesAroundClassBody:
|
|
40
|
+
Enabled: true
|
|
41
|
+
|
|
42
|
+
Layout/EmptyLinesAroundModuleBody:
|
|
43
|
+
Enabled: true
|
|
44
|
+
|
|
45
|
+
Style/FrozenStringLiteralComment:
|
|
46
|
+
Enabled: true
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bake-modernize
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.27.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -38,7 +38,7 @@ cert_chain:
|
|
|
38
38
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
|
39
39
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
|
40
40
|
-----END CERTIFICATE-----
|
|
41
|
-
date: 2024-07-
|
|
41
|
+
date: 2024-07-18 00:00:00.000000000 Z
|
|
42
42
|
dependencies:
|
|
43
43
|
- !ruby/object:Gem::Dependency
|
|
44
44
|
name: async-http
|
|
@@ -121,12 +121,12 @@ files:
|
|
|
121
121
|
- bake/modernize/contributing.rb
|
|
122
122
|
- bake/modernize/contributors.rb
|
|
123
123
|
- bake/modernize/editorconfig.rb
|
|
124
|
-
- bake/modernize/frozen_string_literal.rb
|
|
125
124
|
- bake/modernize/gemfile.rb
|
|
126
125
|
- bake/modernize/gemspec.rb
|
|
127
126
|
- bake/modernize/git.rb
|
|
128
127
|
- bake/modernize/license.rb
|
|
129
128
|
- bake/modernize/readme.rb
|
|
129
|
+
- bake/modernize/rubocop.rb
|
|
130
130
|
- bake/modernize/signing.rb
|
|
131
131
|
- lib/bake/modernize.rb
|
|
132
132
|
- lib/bake/modernize/license.rb
|
|
@@ -141,6 +141,8 @@ files:
|
|
|
141
141
|
- template/editorconfig/.editorconfig
|
|
142
142
|
- template/git/.gitignore
|
|
143
143
|
- template/readme/readme.md
|
|
144
|
+
- template/rubocop/.github/workflows/rubocop.yaml
|
|
145
|
+
- template/rubocop/.rubocop.yml
|
|
144
146
|
homepage: https://github.com/ioquatix/bake-modernize
|
|
145
147
|
licenses:
|
|
146
148
|
- MIT
|
|
@@ -163,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
163
165
|
- !ruby/object:Gem::Version
|
|
164
166
|
version: '0'
|
|
165
167
|
requirements: []
|
|
166
|
-
rubygems_version: 3.5.
|
|
168
|
+
rubygems_version: 3.5.11
|
|
167
169
|
signing_key:
|
|
168
170
|
specification_version: 4
|
|
169
171
|
summary: Automatically modernize parts of your project/gem.
|
metadata.gz.sig
CHANGED
|
Binary file
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2022, by Samuel Williams.
|
|
5
|
-
|
|
6
|
-
def frozen_string_literal
|
|
7
|
-
update(root: Dir.pwd)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def update(root:)
|
|
11
|
-
Dir.glob("**/*.rb", base: root).each do |path|
|
|
12
|
-
case path
|
|
13
|
-
when /\.rb$/
|
|
14
|
-
update_source_file(path)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def update_source_file(path)
|
|
22
|
-
input = File.readlines(path)
|
|
23
|
-
output = []
|
|
24
|
-
|
|
25
|
-
# Skip the hash-bang line:
|
|
26
|
-
if input.first =~ /^\#!/
|
|
27
|
-
output.push input.shift
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
options = {}
|
|
31
|
-
|
|
32
|
-
while input.first =~ /^\#\s*(.*?):(.*)$/
|
|
33
|
-
options[$1.strip] = $2.strip
|
|
34
|
-
input.shift
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
options['frozen_string_literal'] ||= 'true'
|
|
38
|
-
|
|
39
|
-
options.each do |key, value|
|
|
40
|
-
output.push "# #{key}: #{value}"
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
unless input.first&.chomp&.empty?
|
|
44
|
-
output.push "\n"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Add the rest of the file:
|
|
48
|
-
output.push(*input)
|
|
49
|
-
|
|
50
|
-
File.open(path, "w") do |file|
|
|
51
|
-
file.puts(output)
|
|
52
|
-
end
|
|
53
|
-
end
|