Query packagist for the latest version
This commit is contained in:
parent
341eafcbf2
commit
6a81f0959d
@ -4,5 +4,6 @@ CONFIG = {
|
|||||||
remote_path: 'example.com:/srv/httpd/some/path',
|
remote_path: 'example.com:/srv/httpd/some/path',
|
||||||
download_url: 'https://example.com/some/path',
|
download_url: 'https://example.com/some/path',
|
||||||
branch: 'user/nick/updates',
|
branch: 'user/nick/updates',
|
||||||
gh_token: ''
|
gh_token: '',
|
||||||
|
repository: '../slackbuilds'
|
||||||
}.freeze
|
}.freeze
|
||||||
|
@ -9,31 +9,79 @@ require 'json'
|
|||||||
require_relative '../config/config'
|
require_relative '../config/config'
|
||||||
|
|
||||||
module SlackBuilder
|
module SlackBuilder
|
||||||
GITHUB_QUERY = <<~GQL
|
# Remote repository for a single package.
|
||||||
query ($name: String!, $owner: String!) {
|
class Repository
|
||||||
repository(name: $name, owner: $owner) {
|
# Request the latest tag in the given repository.
|
||||||
refs(last: 1, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: ASC }) {
|
def latest
|
||||||
nodes {
|
raise NotImplementedError
|
||||||
id,
|
end
|
||||||
name
|
end
|
||||||
|
|
||||||
|
class GitHub < Repository
|
||||||
|
GITHUB_QUERY = <<~GQL
|
||||||
|
query ($name: String!, $owner: String!) {
|
||||||
|
repository(name: $name, owner: $owner) {
|
||||||
|
refs(last: 1, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: ASC }) {
|
||||||
|
nodes {
|
||||||
|
id,
|
||||||
|
name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
GQL
|
||||||
GQL
|
private_constant :GITHUB_QUERY
|
||||||
private_constant :GITHUB_QUERY
|
|
||||||
|
|
||||||
# Request the latest tag in the given repository.
|
def initialize(owner, name)
|
||||||
def self.github_latest_tag(owner, name)
|
super()
|
||||||
post_data = {
|
|
||||||
'query' => GITHUB_QUERY,
|
@owner = owner
|
||||||
'variables' => { 'name' => name, 'owner' => owner }
|
@name = name
|
||||||
}
|
end
|
||||||
uri = URI('https://api.github.com/graphql')
|
|
||||||
response = Net::HTTP.post uri, post_data.to_json, {
|
def latest
|
||||||
'content-type' => 'application/json',
|
post_data = {
|
||||||
'authorization' => "Bearer #{CONFIG[:gh_token]}"
|
'query' => GITHUB_QUERY,
|
||||||
}
|
'variables' => { 'name' => @name, 'owner' => @owner }
|
||||||
JSON.parse(response.body)['data']['repository']['refs']['nodes'].first['name']
|
}
|
||||||
|
uri = URI('https://api.github.com/graphql')
|
||||||
|
response = Net::HTTP.post uri, post_data.to_json, {
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'authorization' => "Bearer #{CONFIG[:gh_token]}"
|
||||||
|
}
|
||||||
|
JSON.parse(response.body)['data']['repository']['refs']['nodes'].first['name']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Packagist < Repository
|
||||||
|
def initialize(vendor, name)
|
||||||
|
super()
|
||||||
|
|
||||||
|
@vendor = vendor
|
||||||
|
@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"
|
||||||
|
response = Net::HTTP.get uri, {
|
||||||
|
'content-type' => 'application/json'
|
||||||
|
}
|
||||||
|
JSON.parse(response)['packages'][full_name].first['version']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.check_for_latest(package_name, repository)
|
||||||
|
package_path = Pathname.new Dir.glob("#{CONFIG[:repository]}/*/#{package_name}").first
|
||||||
|
package_category = package_path.dirname.basename.to_s
|
||||||
|
package = Package.parse("#{package_category}/#{package_name}", File.read("#{package_path}/#{package_name}.info"))
|
||||||
|
latest_version = repository.latest
|
||||||
|
|
||||||
|
if package.version == latest_version
|
||||||
|
puts "#{package_name} is up to date."
|
||||||
|
else
|
||||||
|
puts "#{package_name}: Current version is #{package.version}, #{latest_version} is available."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user