summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-05-22 13:04:45 +0200
committerEugen Wissner <belka@caraus.de>2023-05-22 13:04:45 +0200
commitf564676cb6576dd8e980770b0ffa3311a060e348 (patch)
treea14bb18a9b8aae97a6428e2e967c0044d120bca2 /lib
parent04b24eeb9963939b64abdd505d665cf892b1bd5d (diff)
downloadslackbuilder-f564676cb6576dd8e980770b0ffa3311a060e348.tar.gz
Add function to request latest github tag
Diffstat (limited to 'lib')
-rw-r--r--lib/up2date.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/up2date.rb b/lib/up2date.rb
new file mode 100644
index 0000000..f51a89e
--- /dev/null
+++ b/lib/up2date.rb
@@ -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