Skip to content

Commit

Permalink
Problem: some extensions use non-standard tag prefixes
Browse files Browse the repository at this point in the history
Like `rel-` instead of `v`

Solution: make this configurable
  • Loading branch information
yrashk committed Dec 14, 2024
1 parent 24731ad commit 7794144
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions lib/pgpm/package/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,41 @@
module Pgpm
class Package
module Git
Config = Data.define(:url, :download_version_tags)
Config = Data.define(:url, :download_version_tags, :tag_prefix)

module ClassMethods
attr_reader :git_config

module Methods
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-]+)*))?$/
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-]+)*))?$/

def package_versions
if !git_config.download_version_tags
super
else
prefix_re = Regexp.quote(git_config.tag_prefix.to_s)
prefix_re = git_config.tag_prefix if git_config.tag_prefix.is_a?(Regexp)
git_term_prompt = ENV["GIT_TERMINAL_PROMPT"]
ENV["GIT_TERMINAL_PROMPT"] = "0"
begin
@tags ||=
::Git.ls_remote(git_config.url)["tags"].keys
.filter { |key| !key.end_with?("^{}") }
.filter { |key| key.match?(SEMVER) }
.filter { |key| key.match?(/^(#{prefix_re})#{SEMVER}/) }
rescue StandardError
@tags ||= []
end
ENV["GIT_TERMINAL_PROMPT"] = git_term_prompt
versions = @tags.map { |tag| tag.gsub(/^v/, "") }.map { |v| Pgpm::Package::Version.new(v) }
versions = @tags.map { |tag| tag.gsub(/^(#{prefix_re})/, "") }.map { |v| Pgpm::Package::Version.new(v) }
@tag_versions = Hash[@tags.zip(versions)]
@version_tags = Hash[versions.zip(@tags)]
versions
end
end
end

def git(url, download_version_tags: true)
@git_config = Config.new(url:, download_version_tags:)
def git(url, download_version_tags: true, tag_prefix: /v?/)
@git_config = Config.new(url:, download_version_tags:, tag_prefix:)
extend Methods
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pgpm/package/git_hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def source_url_directory_name
module ClassMethods
attr_reader :github_config

def github(name, download_version_tags: true)
def github(name, download_version_tags: true, tag_prefix: /v?/)
@github_config = Config.new(name:, download_version_tags:)
include Pgpm::Package::Git
include Methods
git "https://github.com/#{@github_config.name}", download_version_tags:
git "https://github.com/#{@github_config.name}", download_version_tags:, tag_prefix:
end
end

Expand Down
2 changes: 1 addition & 1 deletion packages/pgmp.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

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

0 comments on commit 7794144

Please sign in to comment.