bake/modernize/gemspec.rb in bake-modernize-0.21.0 vs bake/modernize/gemspec.rb in bake-modernize-0.22.0

- old
+ new

@@ -1,9 +1,9 @@ # frozen_string_literal: true # Released under the MIT License. -# Copyright, 2020-2023, by Samuel Williams. +# Copyright, 2020-2024, by Samuel Williams. # Rewrite the current gemspec. def gemspec path = default_gemspec_path buffer = StringIO.new @@ -27,12 +27,15 @@ constant = File.read(version_path) .scan(/(?:class|module)\s+(.*?)$/) .flatten .join("::") + normalize_homepage(spec) + spec.metadata["funding_uri"] ||= detect_funding_uri(spec) spec.metadata["documentation_uri"] ||= detect_documentation_uri(spec) + spec.metadata["source_code_uri"] ||= detect_source_code_uri(spec) spec.authors = sorted_authors(Dir.pwd) spec.metadata.delete_if{|_, value| value.nil?} @@ -182,12 +185,18 @@ response.success? end end -GITHUB_PROJECT = /github.com\/(?<account>.*?)\/(?<project>.*?)\/?/ +GITHUB_PROJECT = /github.com\/(?<account>.*?)\/(?<project>.*?)(\/|\Z)/ +def normalize_homepage(spec) + if homepage = spec.homepage + spec.homepage = homepage.chomp("/") + end +end + def detect_funding_uri(spec) if match = spec.homepage&.match(GITHUB_PROJECT) account = match[:account] funding_uri = "https://github.com/sponsors/#{account}/" @@ -206,9 +215,18 @@ documentation_uri = "https://#{account}.github.io/#{project}/" if valid_uri?(documentation_uri) return documentation_uri end + end +end + +def detect_source_code_uri(spec) + if match = spec.homepage.match(GITHUB_PROJECT) + account = match[:account] + project = match[:project] + + return "https://github.com/#{account}/#{project}.git" end end def sorted_authors(root) authorship = Bake::Modernize::License::Authorship.new