Files
ubicloud/helpers/runtime.rb
Jeremy Evans e5fe2baf4c Configure Octokit timeouts
This uses 10 seconds for both open_timeout and timeout, which
should ensure no more than 20 seconds total, assuming there is a
single Octokit request per Clover request.  That leaves 10 seconds
for Clover's processing before exceeding Heroku's 30 second limit.

Add Faraday::TimeoutError to the list of errors to rescue.
2025-05-06 03:31:38 +09:00

37 lines
1.4 KiB
Ruby

# frozen_string_literal: true
class Clover < Roda
def get_runtime_jwt_payload
return unless (v = request.env["HTTP_AUTHORIZATION"])
jwt_token = v.sub(%r{\ABearer:?\s+}, "")
begin
JWT.decode(jwt_token, Config.clover_runtime_token_secret, true, {algorithm: "HS256"})[0]
rescue JWT::DecodeError
end
end
def get_scope_from_github(runner, run_id)
log_context = {runner_ubid: runner.ubid, repository_ubid: runner.repository.ubid, run_id: run_id}
if run_id.nil? || run_id.empty?
Clog.emit("The run_id is blank") { {runner_scope_failure: log_context} }
return
end
Clog.emit("Get runner scope from GitHub API") { {get_runner_scope: log_context} }
begin
client = Github.installation_client(runner.installation.installation_id)
jobs = client.workflow_run_jobs(runner.repository_name, run_id)[:jobs]
rescue Octokit::ClientError, Octokit::ServerError, Faraday::ConnectionFailed, Faraday::TimeoutError => ex
log_context[:expection] = Util.exception_to_hash(ex)
Clog.emit("Could not list the jobs of the workflow run ") { {runner_scope_failure: log_context} }
return
end
if (job = jobs.find { it[:runner_name] == runner.ubid })
job[:head_branch]
else
Clog.emit("The workflow run does not have given runner") { {runner_scope_failure: log_context} }
nil
end
end
end