Skip to content

Commit 7794144

Browse files
committed
Problem: some extensions use non-standard tag prefixes
Like `rel-` instead of `v` Solution: make this configurable
1 parent 24731ad commit 7794144

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

lib/pgpm/package/git.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,41 @@
55
module Pgpm
66
class Package
77
module Git
8-
Config = Data.define(:url, :download_version_tags)
8+
Config = Data.define(:url, :download_version_tags, :tag_prefix)
99

1010
module ClassMethods
1111
attr_reader :git_config
1212

1313
module Methods
14-
SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
14+
SEMVER = /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
1515

1616
def package_versions
1717
if !git_config.download_version_tags
1818
super
1919
else
20+
prefix_re = Regexp.quote(git_config.tag_prefix.to_s)
21+
prefix_re = git_config.tag_prefix if git_config.tag_prefix.is_a?(Regexp)
2022
git_term_prompt = ENV["GIT_TERMINAL_PROMPT"]
2123
ENV["GIT_TERMINAL_PROMPT"] = "0"
2224
begin
2325
@tags ||=
2426
::Git.ls_remote(git_config.url)["tags"].keys
2527
.filter { |key| !key.end_with?("^{}") }
26-
.filter { |key| key.match?(SEMVER) }
28+
.filter { |key| key.match?(/^(#{prefix_re})#{SEMVER}/) }
2729
rescue StandardError
2830
@tags ||= []
2931
end
3032
ENV["GIT_TERMINAL_PROMPT"] = git_term_prompt
31-
versions = @tags.map { |tag| tag.gsub(/^v/, "") }.map { |v| Pgpm::Package::Version.new(v) }
33+
versions = @tags.map { |tag| tag.gsub(/^(#{prefix_re})/, "") }.map { |v| Pgpm::Package::Version.new(v) }
3234
@tag_versions = Hash[@tags.zip(versions)]
3335
@version_tags = Hash[versions.zip(@tags)]
3436
versions
3537
end
3638
end
3739
end
3840

39-
def git(url, download_version_tags: true)
40-
@git_config = Config.new(url:, download_version_tags:)
41+
def git(url, download_version_tags: true, tag_prefix: /v?/)
42+
@git_config = Config.new(url:, download_version_tags:, tag_prefix:)
4143
extend Methods
4244
end
4345
end

lib/pgpm/package/git_hub.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def source_url_directory_name
2525
module ClassMethods
2626
attr_reader :github_config
2727

28-
def github(name, download_version_tags: true)
28+
def github(name, download_version_tags: true, tag_prefix: /v?/)
2929
@github_config = Config.new(name:, download_version_tags:)
3030
include Pgpm::Package::Git
3131
include Methods
32-
git "https://github.com/#{@github_config.name}", download_version_tags:
32+
git "https://github.com/#{@github_config.name}", download_version_tags:, tag_prefix:
3333
end
3434
end
3535

packages/pgmp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
class Pgmp < Pgpm::Package
4-
github "dvarrazzo/pgmp"
4+
github "dvarrazzo/pgmp", tag_prefix: "rel-"
55
end

0 commit comments

Comments
 (0)