bake-modernize 0.13.5 → 0.14.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2047cc401761b2a99b5e702ee54e45500f4b1dae3d01079754023c07797ea7ea
4
- data.tar.gz: 73ead30a3b412d0010321ab7ce4a88abebc978e14ac912cb06375da1ddd4a457
3
+ metadata.gz: a7c628b23ad3f6c917cecca7b5f0b81cd18047eeb4b60e64146394638a5cb141
4
+ data.tar.gz: 01a578fd9f4a36e9881b1954317dcca8ab78bbf6234701a8818b0aa0eb88fa4b
5
5
  SHA512:
6
- metadata.gz: c628b25804a29175e23d2d9a34d8f2609eea158799d9a51b68f71f5327d463f050881b7a246c0b98422d17ed6aa7a90e8c68110ef9597425e94433cd49f572a8
7
- data.tar.gz: 35ae365477c6f1c2d287771635870eb58132c651e73dfcc43741cb7b55933d71ab64a8d38b614b1cd33abb11db8ca29edc203809c7a0230f4ceeca9c55d00ab8
6
+ metadata.gz: f133f854aaf6d0b309d4ae29efe814563541eb781b8d3882654ff6a80a144213ddcf582b1b1f3727c3e3fb6bc66b7548e17ac3af508b59e7b74db6b8bc1ccdcd
7
+ data.tar.gz: 20a7299113e214c81a26aebda737a604218c33353e9258e27ad1ffaf5df2a477a86bd093e4ff6aadcac53bee1c0e2eb6a5dd086c110d5ac2d77df4747d2effd9
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2022, by Samuel Williams.
4
+ # Copyright, 2021-2023, by Samuel Williams.
5
5
 
6
6
  require 'bake/modernize'
7
7
 
@@ -10,7 +10,7 @@ def git
10
10
  end
11
11
 
12
12
  def update(root:)
13
- if current_branch != "main"
13
+ if current_branch == "master"
14
14
  # https://github.com/github/renaming
15
15
  system("git", "branch", "-M", "main")
16
16
  system("git", "push", "-u", "origin", "main")
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2022, by Samuel Williams.
5
5
 
6
- require 'console'
6
+ require 'bake/modernize'
7
7
 
8
8
  LICENSE = <<~LICENSE
9
9
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -31,16 +31,15 @@ def license
31
31
  end
32
32
 
33
33
  def update(root:)
34
- authors, paths = self.authors(root)
34
+ authorship = Bake::Modernize::License::Authorship.new
35
+ authorship.extract(root)
35
36
 
36
37
  buffer = StringIO.new
37
38
  buffer.puts "# MIT License"
38
39
  buffer.puts
39
40
 
40
- authors.map do |author, dates|
41
- years = dates.map(&:year).uniq
42
-
43
- buffer.puts "Copyright, #{years.join('-')}, by #{author}. "
41
+ authorship.copyrights.each do |copyright|
42
+ buffer.puts "#{copyright.statement} "
44
43
  end
45
44
 
46
45
  buffer.puts
@@ -50,19 +49,21 @@ def update(root:)
50
49
  file.write(buffer.string)
51
50
  end
52
51
 
53
- paths.each do |path, authors|
52
+ authorship.paths.each do |path, modifications|
54
53
  next unless File.exist?(path)
55
54
 
56
55
  case path
57
56
  when /\.rb$/
58
- self.update_source_file_authors(path, authors)
57
+ self.update_source_file_authors(authorship, path, modifications)
59
58
  end
60
59
  end
61
60
  end
62
61
 
63
62
  private
64
63
 
65
- def update_source_file_authors(path, authors)
64
+ def update_source_file_authors(authorship, path, modifications)
65
+ copyrights = authorship.copyrights_for_modifications(modifications)
66
+
66
67
  input = File.readlines(path)
67
68
  output = []
68
69
 
@@ -90,10 +91,8 @@ def update_source_file_authors(path, authors)
90
91
 
91
92
  output << "# Released under the MIT License.\n"
92
93
 
93
- authors.each do |author, dates|
94
- years = dates.map(&:year).uniq
95
-
96
- output << "# Copyright, #{years.join('-')}, by #{author}.\n"
94
+ copyrights.each do |copyright|
95
+ output << "# #{copyright.statement}\n"
97
96
  end
98
97
 
99
98
  output << "\n"
@@ -104,67 +103,3 @@ def update_source_file_authors(path, authors)
104
103
  file.puts(output)
105
104
  end
106
105
  end
107
-
108
- def authors(root)
109
- paths = {}
110
- authors = {}
111
-
112
- total = `git rev-list --count HEAD`.to_i
113
-
114
- input, output = IO.pipe
115
- pid = Process.spawn("git", "log", "--name-only", "--pretty=format:%ad\t%an", out: output, chdir: root)
116
-
117
- output.close
118
-
119
- progress = Console.logger.progress(self, total)
120
-
121
- while header = (input.readline.chomp rescue nil)
122
- break if header.empty?
123
- progress.increment
124
-
125
- date, author = header.split("\t", 2)
126
- date = Date.parse(date)
127
-
128
- while path = (input.readline.chomp rescue nil)
129
- break if path.empty?
130
-
131
- paths[path] ||= {}
132
- paths[path][author] ||= []
133
- paths[path][author] << date
134
-
135
- authors[author] ||= []
136
- authors[author] << date
137
- end
138
- end
139
-
140
- input.close
141
- Process.wait2(pid)
142
-
143
- paths.each do |path, authors|
144
- authors.transform_values! do |dates|
145
- dates.minmax
146
- end
147
- end
148
-
149
- paths.transform_values! do |authors|
150
- authors.transform_values! do |dates|
151
- dates.minmax
152
- end
153
-
154
- authors.sort_by do |author, dates|
155
- dates
156
- end
157
- end
158
-
159
- authors.transform_values! do |dates|
160
- dates.minmax
161
- end
162
-
163
- authors = authors.to_a
164
-
165
- authors.sort_by! do |author, dates|
166
- dates
167
- end
168
-
169
- return authors, paths
170
- end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2022, by Samuel Williams.
5
+
6
+ require 'rugged'
7
+
8
+ module Bake
9
+ module Modernize
10
+ module License
11
+ class Mailmap
12
+ def self.for(root)
13
+ full_path = File.join(root, '.mailmap')
14
+
15
+ if File.exist?(full_path)
16
+ mailmap = self.new
17
+ mailmap.extract(full_path)
18
+ return mailmap
19
+ end
20
+ end
21
+
22
+ def initialize
23
+ @names = {}
24
+ end
25
+
26
+ attr :names
27
+
28
+ def extract(path)
29
+ File.open(path, 'r') do |file|
30
+ file.each_line do |line|
31
+ # Skip comments
32
+ next if line =~ /^#/
33
+ # Skip empty lines
34
+ next if line =~ /^\s*$/
35
+ # Parse line
36
+ # Format: Full Name <email@address>
37
+ line.match(/^(.*) <(.*)>$/) do |match|
38
+ @names[match[2]] = match[1]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ class Authorship
46
+ Modification = Struct.new(:author, :time, :path) do
47
+ def full_name
48
+ author[:name]
49
+ end
50
+ end
51
+
52
+ Copyright = Struct.new(:dates, :author) do
53
+ def <=> other
54
+ self.to_a <=> other.to_a
55
+ end
56
+
57
+ def statement
58
+ years = self.dates.map(&:year).uniq
59
+ return "Copyright, #{years.join('-')}, by #{author}."
60
+ end
61
+ end
62
+
63
+ def initialize
64
+ @paths = {}
65
+ end
66
+
67
+ attr :paths
68
+
69
+ def extract(root = Dir.pwd)
70
+ mailmap = Mailmap.for(root)
71
+
72
+ walk(Rugged::Repository.discover(root), mailmap: mailmap)
73
+
74
+ return self
75
+ end
76
+
77
+ def copyrights
78
+ copyrights_for_modifications(@paths.values.flatten)
79
+ end
80
+
81
+ def copyrights_for_path(path)
82
+ copyrights_for_modifications(@paths[path])
83
+ end
84
+
85
+ def copyrights_for_modifications(modifications)
86
+ authors = modifications.group_by{|modification| modification.full_name}
87
+
88
+ authors.map do |name, modifications|
89
+ Copyright.new(modifications.map(&:time).minmax, name)
90
+ end.sort
91
+ end
92
+
93
+ private
94
+
95
+ DEFAULT_SORT = Rugged::SORT_DATE | Rugged::SORT_TOPO | Rugged::SORT_REVERSE
96
+
97
+ def walk(repository, mailmap: nil, show: "HEAD")
98
+ Rugged::Walker.walk(repository, show: show, sort: DEFAULT_SORT) do |commit|
99
+ diff = commit.diff
100
+ diff.find_similar!
101
+
102
+ diff.each_delta do |delta|
103
+ old_path = delta.old_file[:path]
104
+ new_path = delta.new_file[:path]
105
+
106
+ @paths[new_path] ||= []
107
+
108
+ if old_path != new_path
109
+ # The file was moved, move copyright information too:
110
+ @paths[new_path].concat(@paths[old_path])
111
+ end
112
+
113
+ author = commit.author
114
+
115
+ if mailmap
116
+ if name = mailmap.names[author[:email]]
117
+ author[:name] = name
118
+ end
119
+ end
120
+
121
+ @paths[new_path] << Modification.new(author, commit.time, new_path)
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Bake
7
7
  module Modernize
8
- VERSION = "0.13.5"
8
+ VERSION = "0.14.1"
9
9
  end
10
10
  end
@@ -3,7 +3,8 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2020-2022, by Samuel Williams.
5
5
 
6
- require "bake/modernize/version"
6
+ require_relative 'modernize/license'
7
+ require_relative 'modernize/version'
7
8
  require 'build/files/glob'
8
9
  require 'fileutils'
9
10
 
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2020-2022, by Samuel Williams.
3
+ Copyright, 2020-2023, by Samuel Williams.
4
4
  Copyright, 2021-2022, by Olle Jonsson.
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -21,7 +21,7 @@ jobs:
21
21
  - macos
22
22
 
23
23
  ruby:
24
- - "3.1"
24
+ - "3.2"
25
25
 
26
26
  steps:
27
27
  - uses: actions/checkout@v3
@@ -47,7 +47,7 @@ jobs:
47
47
  - uses: actions/checkout@v3
48
48
  - uses: ruby/setup-ruby@v1
49
49
  with:
50
- ruby-version: "3.1"
50
+ ruby-version: "3.2"
51
51
  bundler-cache: true
52
52
 
53
53
  - uses: actions/download-artifact@v3
@@ -32,7 +32,7 @@ jobs:
32
32
 
33
33
  - uses: ruby/setup-ruby@v1
34
34
  with:
35
- ruby-version: "3.1"
35
+ ruby-version: "3.2"
36
36
  bundler-cache: true
37
37
 
38
38
  - name: Installing packages
@@ -23,6 +23,7 @@ jobs:
23
23
  - "2.7"
24
24
  - "3.0"
25
25
  - "3.1"
26
+ - "3.2"
26
27
 
27
28
  steps:
28
29
  - uses: actions/checkout@v3
@@ -24,6 +24,7 @@ jobs:
24
24
  - "2.7"
25
25
  - "3.0"
26
26
  - "3.1"
27
+ - "3.2"
27
28
 
28
29
  experimental: [false]
29
30
 
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.13.5
4
+ version: 0.14.1
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: 2022-08-27 00:00:00.000000000 Z
41
+ date: 2023-01-07 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: async-http
@@ -141,6 +141,7 @@ files:
141
141
  - bake/modernize/readme.rb
142
142
  - bake/modernize/signing.rb
143
143
  - lib/bake/modernize.rb
144
+ - lib/bake/modernize/license.rb
144
145
  - lib/bake/modernize/version.rb
145
146
  - license.md
146
147
  - readme.md
@@ -171,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  - !ruby/object:Gem::Version
172
173
  version: '0'
173
174
  requirements: []
174
- rubygems_version: 3.3.7
175
+ rubygems_version: 3.4.1
175
176
  signing_key:
176
177
  specification_version: 4
177
178
  summary: Automatically modernize parts of your project/gem.
metadata.gz.sig CHANGED
Binary file