hoe-halostatue 2.1.1 → 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.1"
4
+ VERSION = "3.0.0" # :nodoc:
5
5
  end
@@ -1,135 +1,97 @@
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
- Hoe.plugin :gemspec2
7
- Hoe.plugin :markdown
8
- Hoe.plugin :rubygems
9
+ class Hoe; end # :nodoc:
9
10
 
10
- # This module is a Hoe plugin. You can set its options in your Rakefile Hoe spec, like
11
- # this:
11
+ Hoe.plugins.delete :git
12
+ Hoe.plugins.delete :newb
13
+ Hoe.plugins.delete :publish
14
+ Hoe.plugins.delete :signing
15
+
16
+ # This module is a Hoe plugin which applies extremely opinionated reconfiguration to Hoe.
17
+ # You can set its options in your Rakefile Hoe spec, like this:
18
+ #
19
+ # ```ruby
20
+ # Hoe.plugin :halostatue
21
+ #
22
+ # Hoe.spec "myproj" do
23
+ # self.checklist = nil if ENV["rubygems_release_gem"] == "true"
24
+ # self.git_release_tag_prefix = "REL_"
25
+ # self.git_remotes << "myremote"
26
+ # end
27
+ # ```
28
+ #
29
+ # The `:git` plugin (built into Hoe since Hoe 4.5 or present in the `hoe-git` or
30
+ # `hoe-git2` dependencies) should not be enabled as that implementation differs from what
31
+ # is included here.
32
+ #
33
+ # ### Tasks
34
+ #
35
+ # - `checklist`: Show the list of checklist questions.
36
+ # - `git:manifest`: Update the manifest with Git's file list.
37
+ # - `git:tag`: Create and push a tag.
12
38
  #
13
- # Hoe.plugin :git
39
+ # ### Options
14
40
  #
15
- # Hoe.spec "myproj" do
16
- # self.checklist = nil if ENV["rubygems_release_gem"] == "true"
17
- # self.git_release_tag_prefix = "REL_"
18
- # self.git_remotes << "myremote"
19
- # end
41
+ # - `checklist`: An array of reminder questions that should be asked before a release, in
42
+ # the form "Did you... [question]?". The default questions are:
20
43
  #
21
- # === Tasks
44
+ # - `Bump the version?`
45
+ # - `Check everything in?`
46
+ # - `Review the manifest?`
47
+ # - `Update the README and docs?`
48
+ # - `Update the changelog?`
49
+ # - `Regenerate the gemspec?`
22
50
  #
23
- # git:changelog:: Print the current changelog.
24
- # git:manifest:: Update the manifest with Git's file list.
25
- # git:tag:: Create and push a tag.
51
+ # If the checklist is `nil` or empty, or trusted publishing is on, the checklist will
52
+ # not be shown.
26
53
  #
27
- # === Options
54
+ # - `git_release_tag_prefix`: What do you want at the front of your release tags? The
55
+ # default is `"v"`.
28
56
  #
29
- # - +checklist+: An array of reminder questions that should be asked before a release, in
30
- # the form, "Did you... [question]?" You can see the defaults by running <tt>rake
31
- # checklist</tt>. If the checklist is +nil+ or empty, the checklist will not shown
32
- # during release. This is originally from hoe-doofus and called +doofus_checklist+.
57
+ # - `git_remotes`: Which remotes do you want to push tags, etc. to? The default is
58
+ # `%w[origin]`.
33
59
  #
34
- # - +git_release_tag_prefix+: What do you want at the front of your release tags? The
35
- # default is <tt>"v"</tt>.
60
+ # - `git_tag_enabled`: Whether a git tag should be created on release. The default is
61
+ # `true`.
36
62
  #
37
- # - +git_remotes+: Which remotes do you want to push tags, etc. to? The default is
38
- # <tt>%w[origin]</tt>
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:
39
65
  #
40
- # - +git_tag_enabled+: Whether a git tag should be created on release. The default is
41
- # +true+.
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.
42
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
+
43
81
  # Indicates that this release is being run as part of a trusted release workflow.
44
- # [default: +false+]
82
+ # [default: `false`]
45
83
  attr_accessor :trusted_release
46
84
 
47
- # An array of reminder questions that should be asked before a release, in the form,
48
- # "Did you... [question]?" You can see the defaults by running <tt>rake checklist</tt>.
49
- #
50
- # If the checklist is +nil+ or empty, the checklist will not shown during release.
51
- attr_accessor :checklist
52
-
53
- # What do you want at the front of your release tags?
54
- # [default: <tt>"v"</tt>]
55
- attr_accessor :git_release_tag_prefix
56
-
57
- # Which remotes do you want to push tags, etc. to?
58
- # [default: <tt>%w[origin]</tt>]
59
- attr_accessor :git_remotes
60
-
61
- # Should git tags be created on release? [default: +true+]
62
- attr_accessor :git_tag_enabled
63
-
64
85
  def initialize_halostatue # :nodoc:
65
- Hoe::URLS_TO_META_MAP.update({
66
- "bugs" => "bug_tracker_uri",
67
- "changelog" => "changelog_uri",
68
- "changes" => "changelog_uri",
69
- "clog" => "changelog_uri",
70
- "code" => "source_code_uri",
71
- "doco" => "documentation_uri",
72
- "docs" => "documentation_uri",
73
- "documentation" => "documentation_uri",
74
- "history" => "changelog_uri",
75
- "home" => "homepage_uri",
76
- "issues" => "bug_tracker_uri",
77
- "mail" => "mailing_list_uri",
78
- "tickets" => "bug_tracker_uri",
79
- "wiki" => "wiki_uri"
80
- })
81
- Hoe.prepend Hoe::Halostatue::ParseUrls
82
-
83
- self.checklist = [
84
- "bump the version",
85
- "check everything in",
86
- "review the manifest",
87
- "update the README and RDocs",
88
- "update the changelog",
89
- "regenerate the gemspec"
90
- ]
91
-
92
- self.git_release_tag_prefix = "v"
93
- self.git_remotes = %w[origin]
94
- self.git_tag_enabled = true
86
+ initialize_halostatue_checklist
87
+ initialize_halostatue_gemspec
88
+ initialize_halostatue_git
89
+ initialize_halostatue_markdown
90
+
95
91
  self.trusted_release = false
96
92
  end
97
93
 
98
- LINKS = /\[(?<name>.+?)\](?:\(.+?\)|\[.+?\])/
99
-
100
94
  def define_halostatue_tasks # :nodoc:
101
- desc "Show a reminder for steps I frequently forget"
102
- task :checklist do
103
- if checklist.nil? || checklist.empty?
104
- puts "Checklist is empty."
105
- else
106
- puts "\n### HEY! Did you...\n\n"
107
-
108
- checklist.each do |question|
109
- question = question[0..0].upcase + question[1..]
110
- question = "#{question}?" unless question.end_with?("?")
111
- puts " * #{question}"
112
- end
113
-
114
- puts
115
- end
116
- end
117
-
118
- task :release_sanity do
119
- unless checklist.nil? || checklist.empty? || trusted_release
120
- Rake::Task[:checklist].invoke
121
- puts "Hit return if you're sure, Ctrl-C if you forgot something."
122
- $stdin.gets
123
- end
124
- end
125
-
126
- task :spec_clean_markdown_links do
127
- spec.description = spec.description.gsub(LINKS, '\k<name>').gsub(/\r?\n/, " ")
128
- spec.summary = spec.summary.gsub(LINKS, '\k<name>').gsub(/\r?\n/, " ")
129
- end
130
-
131
- task "#{spec.name}.gemspec" => :spec_clean_markdown_links
132
-
133
95
  if trusted_release
134
96
  task :trusted_release do
135
97
  vm = %r{^(?<version>\d+(?:\.\d+)+)(?:\.(?<pre>[a-z]\w+(?:\.\d+)+))?}
@@ -142,79 +104,40 @@ module Hoe::Halostatue
142
104
  task release_sanity: :trusted_release
143
105
  end
144
106
 
145
- return unless __run_git("rev-parse", "--is-inside-work-tree") == "true"
146
-
147
- desc "Update the manifest with Git's file list. Use Hoe's excludes."
148
- task "git:manifest" do
149
- with_config do |config, _|
150
- files = __run_git("ls-files").split($/)
151
- files.reject! { |f| f =~ config["exclude"] }
152
-
153
- File.open "Manifest.txt", "w" do |f|
154
- f.puts files.sort.join("\n")
155
- end
156
- end
157
- end
158
-
159
- desc "Create and push a TAG (default #{git_release_tag_prefix}#{version})."
160
- task "git:tag" do
161
- if git_tag_enabled
162
- tag = ENV["TAG"]
163
- ver = ENV["VERSION"] || version
164
- pre = ENV["PRERELEASE"] || ENV["PRE"]
165
- ver += ".#{pre}" if pre
166
- tag ||= "#{git_release_tag_prefix}#{ver}"
167
-
168
- git_tag_and_push tag
169
- end
170
- end
171
-
172
- task :release_sanity do
173
- unless __run_git("status", "--porcelain").empty?
174
- abort "Won't release: Dirty index or untracked files present!"
175
- end
176
- end
177
-
178
- task release_to: "git:tag"
179
- end
180
-
181
- def __git(command, *params)
182
- "git #{command.shellescape} #{params.compact.shelljoin}"
107
+ define_halostatue_checklist_tasks
108
+ define_halostatue_gemspec_tasks
109
+ define_halostatue_git_tasks
110
+ define_halostatue_markdown_tasks
183
111
  end
184
112
 
185
- def __run_git(command, *params)
186
- `#{__git(command, *params)}`.strip.chomp
187
- end
188
-
189
- def git_svn?
190
- File.exist?(File.join(__run_git("rev-parse", "--show-toplevel"), ".git/svn"))
191
- end
192
-
193
- def git_tag_and_push tag
194
- msg = "Tagging #{tag}."
195
-
196
- if git_svn?
197
- sh __git("svn", "tag", tag, "-m", msg)
198
- else
199
- flags =
200
- if __run_git("config", "--get", "user.signingkey").empty?
201
- nil
202
- else
203
- "-s"
204
- end
205
-
206
- sh __git("tag", flags, "-f", tag, "-m", msg)
207
- git_remotes.each { |remote| sh __git("push", "-f", remote, "tag", tag) }
208
- end
209
- end
113
+ private
114
+
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
+ })
210
131
 
211
132
  # This replaces Hoe#parse_urls with something that works better for Markdown.
212
133
  module ParseUrls # :nodoc:
213
134
  def parse_urls text
214
135
  keys = Hoe::URLS_TO_META_MAP.keys.join("|")
215
- pattern = %r{^[-+*]\s+(#{keys})\s+::\s+[<]?(\w+://[^>\s]+)[>]?}m
136
+ pattern = %r{^[-+*]\s+(#{keys})\s+::\s+<?(\w+://[^>\s]+)>?}m
216
137
 
217
138
  text.scan(pattern).to_h
218
139
  end
140
+
141
+ ::Hoe.prepend self
219
142
  end
220
143
  end
data/licences/dco.txt ADDED
@@ -0,0 +1,34 @@
1
+ Developer Certificate of Origin
2
+ Version 1.1
3
+
4
+ Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
5
+
6
+ Everyone is permitted to copy and distribute verbatim copies of this
7
+ license document, but changing it is not allowed.
8
+
9
+
10
+ Developer's Certificate of Origin 1.1
11
+
12
+ By making a contribution to this project, I certify that:
13
+
14
+ (a) The contribution was created in whole or in part by me and I
15
+ have the right to submit it under the open source license
16
+ indicated in the file; or
17
+
18
+ (b) The contribution is based upon previous work that, to the best
19
+ of my knowledge, is covered under an appropriate open source
20
+ license and I have the right under that license to submit that
21
+ work with modifications, whether created in whole or in part
22
+ by me, under the same open source license (unless I am
23
+ permitted to submit under a different license), as indicated
24
+ in the file; or
25
+
26
+ (c) The contribution was provided directly to me by some other
27
+ person who certified (a), (b) or (c) and I have not modified
28
+ it.
29
+
30
+ (d) I understand and agree that this project and the contribution
31
+ are public and that a record of the contribution (including all
32
+ personal information I submit with it, including my sign-off) is
33
+ maintained indefinitely and may be redistributed consistent with
34
+ this project or the open source license(s) involved.