Check the latest version from the LATEST text file

This commit is contained in:
2023-06-30 11:02:20 +02:00
parent e0b98189eb
commit df4c9b4ae9
2 changed files with 21 additions and 3 deletions

View File

@ -20,6 +20,7 @@ module SlackBuilder
end
end
# Reads the list fo tags from the GitHub API.
class GitHub < Repository
GITHUB_QUERY = <<~GQL
query ($name: String!, $owner: String!) {
@ -66,6 +67,7 @@ module SlackBuilder
end
end
# Request the latest version from the packagist API.
class Packagist < Repository
def initialize(vendor, name)
super()
@ -74,7 +76,6 @@ module SlackBuilder
@name = name
end
# Request the latest version from the packagist API.
def latest
full_name = [@vendor, @name].join '/'
uri = URI "https://repo.packagist.org/p2/#{full_name}.json"
@ -85,6 +86,22 @@ module SlackBuilder
end
end
# Reads a remote LATEST file.
class LatestText < Repository
def initialize(latest_url)
super()
@latest_url = URI latest_url
end
def latest
response = Net::HTTP.get @latest_url, {
'content-type' => 'text/plain'
}
response.strip
end
end
module_function
# Checks if there is a new version for the package and returns the latest