|
5 | 5 | module Pgpm
|
6 | 6 | class Package
|
7 | 7 | module Git
|
8 |
| - Config = Data.define(:url, :download_version_tags) |
| 8 | + Config = Data.define(:url, :download_version_tags, :tag_prefix) |
9 | 9 |
|
10 | 10 | module ClassMethods
|
11 | 11 | attr_reader :git_config
|
12 | 12 |
|
13 | 13 | 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-]+)*))?$/ |
15 | 15 |
|
16 | 16 | def package_versions
|
17 | 17 | if !git_config.download_version_tags
|
18 | 18 | super
|
19 | 19 | 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) |
20 | 22 | git_term_prompt = ENV["GIT_TERMINAL_PROMPT"]
|
21 | 23 | ENV["GIT_TERMINAL_PROMPT"] = "0"
|
22 | 24 | begin
|
23 | 25 | @tags ||=
|
24 | 26 | ::Git.ls_remote(git_config.url)["tags"].keys
|
25 | 27 | .filter { |key| !key.end_with?("^{}") }
|
26 |
| - .filter { |key| key.match?(SEMVER) } |
| 28 | + .filter { |key| key.match?(/^(#{prefix_re})#{SEMVER}/) } |
27 | 29 | rescue StandardError
|
28 | 30 | @tags ||= []
|
29 | 31 | end
|
30 | 32 | 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) } |
32 | 34 | @tag_versions = Hash[@tags.zip(versions)]
|
33 | 35 | @version_tags = Hash[versions.zip(@tags)]
|
34 | 36 | versions
|
35 | 37 | end
|
36 | 38 | end
|
37 | 39 | end
|
38 | 40 |
|
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:) |
41 | 43 | extend Methods
|
42 | 44 | end
|
43 | 45 | end
|
|
0 commit comments