hoe-halostatue 2.1.2 → 3.0.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.
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "markdown/linkify"
4
+
5
+ module Hoe::Halostatue::Markdown
6
+ # Specify which markdown files to linkify.
7
+ #
8
+ # Should always be a list. May contain `:default` or `{exclude: patterns}` for special
9
+ # handling.
10
+ #
11
+ # `:default` ensures that all `.md` files in the manifest are included.
12
+ #
13
+ # `{exclude: patterns}` excludes files matching any of the provided patterns (a glob
14
+ # string, a regular expression, or a list of glob strings or regular expressions).
15
+ #
16
+ # [default: `[:default]`, any markdown files found in `spec.files`]
17
+ attr_accessor :markdown_linkify_files
18
+
19
+ # The style for producing links. The options are:
20
+ #
21
+ # - `:reference`, which will produce named reference links (e.g., `[#123][gh-issue-123]`)
22
+ # - `:inline`, which produces inline links (e.g., `[#123](https://…)`)
23
+ #
24
+ # Existing links _will not be modified_.
25
+ #
26
+ # When using reference links, existing reference link definitions will not be moved, but
27
+ # new definitions will be appended to the end of the file.
28
+ attr_accessor :markdown_linkify_style
29
+
30
+ # Controls whether shortened URIs for the current repository have prefixes added to
31
+ # them. This is either falsy (no prefixes added), `true` default prefixes are added, or
32
+ # a map with one or more type (`issue`, `pull`, `discussion`) and the prefix to be
33
+ # applied. The default prefixes (when `true`) are
34
+ # `{issue: 'issue', pull: 'pull', discussion: 'discussion'}`.
35
+ #
36
+ # Examples (assuming `true`):
37
+ #
38
+ # ```markdown
39
+ # [issue #123](https://github.com/cogswellcogs/sprocketkiller/issues/123
40
+ # [pull #246](https://github.com/cogswellcogs/sprocketkiller/pull/246)
41
+ # [discussion #369](https://github.com/cogswellcogs/sprocketkiller/discussions/369)
42
+ # ```
43
+ attr_accessor :markdown_linkify_uri_prefixes
44
+
45
+ private
46
+
47
+ def default_markdown_linkify_files
48
+ spec.files.grep(/\.md$/)
49
+ end
50
+
51
+ def initialize_halostatue_markdown
52
+ self.markdown_linkify_files = [:default]
53
+ self.markdown_linkify_style = :reference
54
+ self.markdown_linkify_uri_prefixes = nil
55
+
56
+ # TODO: We should check for `Changelog.md`, `ChangeLog.md` and `History.md`, etc., as
57
+ # documented
58
+
59
+ if File.exist?("CHANGELOG.md")
60
+ self.history_file = "CHANGELOG.md"
61
+ end
62
+
63
+ # TODO: Be case insensitive here, too
64
+
65
+ if File.exist?("README.md")
66
+ self.readme_file = "README.md"
67
+ end
68
+ end
69
+
70
+ def define_halostatue_markdown_tasks
71
+ return unless resolve_linkify_options
72
+
73
+ namespace_name = "markdown:linkify"
74
+ linkify_tasks = []
75
+
76
+ namespace namespace_name do
77
+ markdown_linkify_files.each do |mdfile_path|
78
+ mdfile_name = File.basename(mdfile_path)
79
+ task_name = mdfile_name.downcase.split(".")[0..-2].join(".")
80
+
81
+ linkifier = Hoe::Halostatue::Markdown::Linkify.new(
82
+ bug_tracker_uri: spec.metadata["bug_tracker_uri"],
83
+ style: markdown_linkify_style,
84
+ uri_prefixes: markdown_linkify_uri_prefixes
85
+ )
86
+
87
+ desc "hyperlink github issues and usernames in #{mdfile_name}"
88
+ task task_name do
89
+ original_markdown = File.read(mdfile_path)
90
+
91
+ linkifier.linkify(original_markdown) => {markdown:, changed:}
92
+
93
+ if changed
94
+ puts "markdown:linkify: updating #{mdfile_path}"
95
+ File.write(mdfile_path, markdown)
96
+ else
97
+ puts "markdown:linkify: no changes to #{mdfile_path}"
98
+ end
99
+ end
100
+
101
+ linkify_tasks << "#{namespace_name}:#{task_name}"
102
+ end
103
+ end
104
+
105
+ desc "hyperlink github issues and usernames in markdown files"
106
+ task namespace_name => linkify_tasks
107
+ end
108
+
109
+ def resolve_linkify_options
110
+ unless [:reference, :inline].include? markdown_linkify_style
111
+ raise ArgumentError, "Invalid markdown_linkify_style: #{markdown_linkify_style.inspect}"
112
+ end
113
+
114
+ self.markdown_linkify_uri_prefixes =
115
+ Hoe::Halostatue::Markdown::Linkify.normalize_uri_prefixes(markdown_linkify_uri_prefixes)
116
+
117
+ resolve_linkify_files
118
+ end
119
+
120
+ def resolve_linkify_files
121
+ @markdown_linkify_files ||= [:default]
122
+ return false if markdown_linkify_files.empty?
123
+
124
+ exclude_patterns =
125
+ markdown_linkify_files
126
+ .select { _1.is_a?(Hash) && _1.key?(:exclude) }
127
+ .flat_map { Array(_1[:exclude]) }.uniq
128
+
129
+ unless exclude_patterns.all? { _1.is_a?(Regexp) || _1.is_a?(String) }
130
+ raise ArgumentError, "exclude patterns must be Regexp or String"
131
+ end
132
+
133
+ markdown_linkify_files.reject! { _1.is_a?(Hash) }
134
+
135
+ if markdown_linkify_files.include?(:default)
136
+ markdown_linkify_files
137
+ .concat(default_markdown_linkify_files)
138
+ .delete(:default)
139
+ end
140
+
141
+ markdown_linkify_files.flatten!
142
+
143
+ markdown_linkify_files.reject! do |file|
144
+ exclude_patterns.any? { |pattern|
145
+ pattern.is_a?(Regexp) ? file.match?(pattern) : File.fnmatch?(pattern, file)
146
+ }
147
+ end
148
+
149
+ markdown_linkify_files.uniq!
150
+ !markdown_linkify_files.empty?
151
+ end
152
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hoe::Halostatue
4
- VERSION = "2.1.2" # :nodoc:
4
+ VERSION = "3.0.0" # :nodoc:
5
5
  end
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "shellwords"
4
3
  require_relative "halostatue/version"
4
+ require_relative "halostatue/checklist"
5
+ require_relative "halostatue/gemspec"
6
+ require_relative "halostatue/git"
7
+ require_relative "halostatue/markdown"
5
8
 
6
9
  class Hoe; end # :nodoc:
7
10
 
8
- Hoe.plugin :gemspec2
9
- Hoe.plugin :markdown
10
- Hoe.plugin :rubygems
11
+ Hoe.plugins.delete :git
12
+ Hoe.plugins.delete :newb
13
+ Hoe.plugins.delete :publish
14
+ Hoe.plugins.delete :signing
11
15
 
12
16
  # This module is a Hoe plugin which applies extremely opinionated reconfiguration to Hoe.
13
17
  # You can set its options in your Rakefile Hoe spec, like this:
@@ -55,94 +59,39 @@ Hoe.plugin :rubygems
55
59
  #
56
60
  # - `git_tag_enabled`: Whether a git tag should be created on release. The default is
57
61
  # `true`.
62
+ #
63
+ # - `reproducible_gemspec`: Whether a fixed date should be used for reproducible gemspec
64
+ # values. This is ignored if `$SOURCE_DATE_EPOCH` is set. Acceptable values are:
65
+ #
66
+ # - `:default` or `true`: uses the RubyGems default source date epoch
67
+ # - `:current`: uses the date stored in the most recent gemspec file
68
+ # - `false`: sets the release date to the current date
69
+ # - An epoch value, either as an Integer or a String
70
+ #
71
+ # The default is `:default`.
72
+ #
73
+ # - `trusted_release`: Indicates that this release is being run as part of a trusted
74
+ # release workflow.
58
75
  module Hoe::Halostatue
76
+ include Hoe::Halostatue::Checklist
77
+ include Hoe::Halostatue::Gemspec
78
+ include Hoe::Halostatue::Git
79
+ include Hoe::Halostatue::Markdown
80
+
59
81
  # Indicates that this release is being run as part of a trusted release workflow.
60
82
  # [default: `false`]
61
83
  attr_accessor :trusted_release
62
84
 
63
- # An array of reminder questions that should be asked before a release, in the form,
64
- attr_accessor :checklist
65
-
66
- # What do you want at the front of your release tags?
67
- # [default: `"v"`]
68
- attr_accessor :git_release_tag_prefix
69
-
70
- # Which remotes do you want to push tags, etc. to?
71
- # [default: `%w[origin]`]
72
- attr_accessor :git_remotes
73
-
74
- # Should git tags be created on release? [default: `true`]
75
- attr_accessor :git_tag_enabled
76
-
77
85
  def initialize_halostatue # :nodoc:
78
- Hoe::URLS_TO_META_MAP.update({
79
- "bugs" => "bug_tracker_uri",
80
- "changelog" => "changelog_uri",
81
- "changes" => "changelog_uri",
82
- "clog" => "changelog_uri",
83
- "code" => "source_code_uri",
84
- "doco" => "documentation_uri",
85
- "docs" => "documentation_uri",
86
- "documentation" => "documentation_uri",
87
- "history" => "changelog_uri",
88
- "home" => "homepage_uri",
89
- "issues" => "bug_tracker_uri",
90
- "mail" => "mailing_list_uri",
91
- "tickets" => "bug_tracker_uri",
92
- "wiki" => "wiki_uri"
93
- })
94
- Hoe.prepend Hoe::Halostatue::ParseUrls
95
-
96
- self.checklist = [
97
- "bump the version",
98
- "check everything in",
99
- "review the manifest",
100
- "update the README and RDocs",
101
- "update the changelog",
102
- "regenerate the gemspec"
103
- ]
104
-
105
- self.git_release_tag_prefix = "v"
106
- self.git_remotes = %w[origin]
107
- self.git_tag_enabled = true
86
+ initialize_halostatue_checklist
87
+ initialize_halostatue_gemspec
88
+ initialize_halostatue_git
89
+ initialize_halostatue_markdown
90
+
108
91
  self.trusted_release = false
109
92
  end
110
93
 
111
- LINKS = /\[(?<name>.+?)\](?:\(.+?\)|\[.+?\])/ # :nodoc:
112
-
113
94
  def define_halostatue_tasks # :nodoc:
114
- desc "Show a reminder for steps frequently forgotten in a manual release"
115
- task :checklist do
116
- if checklist.nil? || checklist.empty?
117
- puts "Checklist is empty."
118
- else
119
- puts "\n### HEY! Did you...\n\n"
120
-
121
- checklist.each do |question|
122
- question = question[0..0].upcase + question[1..]
123
- question = "#{question}?" unless question.end_with?("?")
124
- puts " * #{question}"
125
- end
126
-
127
- puts
128
- end
129
- end
130
-
131
- task :release_sanity do
132
- unless checklist.nil? || checklist.empty? || trusted_release
133
- Rake::Task[:checklist].invoke
134
- puts "Hit return if you're sure, Ctrl-C if you forgot something."
135
- $stdin.gets
136
- end
137
- end
138
-
139
- task :spec_clean_markdown_links do
140
- spec.description = spec.description.gsub(LINKS, '\k<name>').gsub(/\r?\n/, " ")
141
- spec.summary = spec.summary.gsub(LINKS, '\k<name>').gsub(/\r?\n/, " ")
142
- end
143
-
144
- task "#{spec.name}.gemspec" => :spec_clean_markdown_links
145
-
146
95
  if trusted_release
147
96
  task :trusted_release do
148
97
  vm = %r{^(?<version>\d+(?:\.\d+)+)(?:\.(?<pre>[a-z]\w+(?:\.\d+)+))?}
@@ -155,63 +104,30 @@ module Hoe::Halostatue
155
104
  task release_sanity: :trusted_release
156
105
  end
157
106
 
158
- return unless __run_git("rev-parse", "--is-inside-work-tree") == "true"
159
-
160
- desc "Update the manifest with Git's file list. Use Hoe's excludes."
161
- task "git:manifest" do
162
- with_config do |config, _|
163
- files = __run_git("ls-files")
164
- .split($/)
165
- .grep_v(config["exclude"])
166
-
167
- File.write "Manifest.txt", files.sort.join("\n") + "\n"
168
- end
169
- end
170
-
171
- desc "Create and push a TAG (default #{git_release_tag_prefix}#{version})."
172
- task "git:tag" do
173
- if git_tag_enabled
174
- tag = ENV["TAG"]
175
- ver = ENV["VERSION"] || version
176
- pre = ENV["PRERELEASE"] || ENV["PRE"]
177
- ver += ".#{pre}" if pre && !ver.ends_with?(pre)
178
- tag ||= "#{git_release_tag_prefix}#{ver}"
179
-
180
- git_tag_and_push tag
181
- end
182
- end
183
-
184
- task :release_sanity do
185
- unless __run_git("status", "--porcelain").empty?
186
- abort "Won't release: Dirty index or untracked files present!"
187
- end
188
- end
189
-
190
- task release_to: "git:tag"
107
+ define_halostatue_checklist_tasks
108
+ define_halostatue_gemspec_tasks
109
+ define_halostatue_git_tasks
110
+ define_halostatue_markdown_tasks
191
111
  end
192
112
 
193
113
  private
194
114
 
195
- def __git(command, *params)
196
- "git #{command.shellescape} #{params.compact.shelljoin}"
197
- end
198
-
199
- def __run_git(command, *params)
200
- `#{__git(command, *params)}`.strip.chomp
201
- end
202
-
203
- def git_svn?
204
- File.exist?(File.join(__run_git("rev-parse", "--show-toplevel"), ".git/svn"))
205
- end
206
-
207
- def git_tag_and_push tag
208
- msg = "Tagging #{tag}."
209
-
210
- flags = "-s" unless __run_git("config", "--get", "user.signingkey").empty?
211
-
212
- sh __git("tag", flags, "-f", tag, "-m", msg)
213
- git_remotes.each { |remote| sh __git("push", "-f", remote, "tag", tag) }
214
- end
115
+ ::Hoe::URLS_TO_META_MAP.update({
116
+ "bugs" => "bug_tracker_uri",
117
+ "changelog" => "changelog_uri",
118
+ "changes" => "changelog_uri",
119
+ "clog" => "changelog_uri",
120
+ "code" => "source_code_uri",
121
+ "doco" => "documentation_uri",
122
+ "docs" => "documentation_uri",
123
+ "documentation" => "documentation_uri",
124
+ "history" => "changelog_uri",
125
+ "home" => "homepage_uri",
126
+ "issues" => "bug_tracker_uri",
127
+ "mail" => "mailing_list_uri",
128
+ "tickets" => "bug_tracker_uri",
129
+ "wiki" => "wiki_uri"
130
+ })
215
131
 
216
132
  # This replaces Hoe#parse_urls with something that works better for Markdown.
217
133
  module ParseUrls # :nodoc:
@@ -221,5 +137,7 @@ module Hoe::Halostatue
221
137
 
222
138
  text.scan(pattern).to_h
223
139
  end
140
+
141
+ ::Hoe.prepend self
224
142
  end
225
143
  end