Add function to request latest github tag
This commit is contained in:
parent
04b24eeb99
commit
f564676cb6
@ -3,5 +3,6 @@
|
||||
CONFIG = {
|
||||
remote_path: 'example.com:/srv/httpd/some/path',
|
||||
download_url: 'https://example.com/some/path',
|
||||
branch: 'user/nick/updates'
|
||||
branch: 'user/nick/updates',
|
||||
gh_token: ''
|
||||
}.freeze
|
||||
|
39
lib/up2date.rb
Normal file
39
lib/up2date.rb
Normal file
@ -0,0 +1,39 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'net/http'
|
||||
require 'json'
|
||||
require_relative '../config/config'
|
||||
|
||||
module SlackBuilder
|
||||
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
|
||||
private_constant :GITHUB_QUERY
|
||||
|
||||
# Request the latest tag in the given repository.
|
||||
def self.github_latest_tag(owner, name)
|
||||
post_data = {
|
||||
'query' => GITHUB_QUERY,
|
||||
'variables' => { 'name' => name, 'owner' => owner }
|
||||
}
|
||||
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
|
Loading…
Reference in New Issue
Block a user