Created
September 6, 2023 17:28
-
-
Save kejadlen/03fa32bf99d5c4e926488595a0c4112f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "json" | |
require "net/http" | |
require "uri" | |
require "irb" | |
sentry_auth_token = ENV.fetch("SENTRY_AUTH_TOKEN") | |
issue_id = ARGV.shift | |
fail "missing issue id" if issue_id.nil? || issue_id.empty? | |
module Sentry | |
class Paginator | |
def initialize(auth_token, uri) | |
@auth_token, @uri = auth_token, uri | |
@data = [] | |
end | |
def each | |
return enum_for(__method__) unless block_given? | |
fetch! | |
until @data.empty? | |
yield @data.shift | |
fetch! if @data.empty? | |
end | |
end | |
def fetch! | |
return if @uri.nil? | |
uri = URI(@uri) | |
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| | |
request = Net::HTTP::Get.new(uri) | |
request["Authorization"] = "Bearer #@auth_token" | |
response = http.request(request) | |
@data.concat(JSON.parse(response.body)) | |
@uri, _, _ = response["link"].scan(/<((?~>))>;\s*rel="((?~"))";\s*results="((?~"))"/).find {|uri, rel, results| | |
rel == "next" && results == "true" | |
} | |
end | |
end | |
end | |
end | |
paginator = Sentry::Paginator.new(sentry_auth_token, "https://sentry.io/api/0/issues/#{issue_id}/events/?full=true") | |
puts JSON.dump(paginator.each.to_a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment