Created
May 17, 2022 12:41
-
-
Save rks/72b9a4303fe3aa0354e5489af4c81036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'octokit' | |
require 'time' | |
def log | |
file = './github_api_latest_release.json' | |
File.open(file, 'a+') { |f| f << yield } | |
end | |
def get_latest_tag_name(github_client, repository_owner_and_name) | |
timestamp = Time.now.utc.iso8601 | |
release = github_client.latest_release(repository_owner_and_name) | |
response = github_client.last_response | |
tag_name = release.tag_name | |
log do | |
JSON.dump( | |
'timestamp' => timestamp, | |
'githubRequestID' => response.headers['x-github-request-id'], | |
'rateLimit' => { | |
'remaining' => github_client.rate_limit.remaining | |
}, | |
'caching' => { | |
'etag' => response.headers['etag'], | |
'lastModified' => response.headers['last-modified'] | |
}, | |
'repository' => repository_owner_and_name, | |
'releaseTag' => tag_name | |
) | |
end | |
tag_name | |
rescue StandardError => e | |
puts e.to_s | |
nil | |
end | |
tag_list = [] | |
client = Octokit::Client.new(access_token: ENV['ACCESS_TOKEN']) | |
repository = ENV.fetch('REPOSITORY', 'mmikaitis/anymatrix') | |
while tag = get_latest_tag_name(client, ) | |
unless tag_list.include?(tag) | |
puts "New tag: #{tag}" | |
tag_list << tag | |
end | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment