Class: Ghamma::GithubApiClient
- Inherits:
-
Object
- Object
- Ghamma::GithubApiClient
- Defined in:
- lib/ghamma/github_api_client.rb
Constant Summary collapse
- BASE_URL =
"https://api.github.com".freeze
Instance Method Summary collapse
- #fetch_workflow_duration_history(workflow_id, since, progressbar) ⇒ Object
-
#initialize(owner:, repo:, token:) ⇒ GithubApiClient
constructor
A new instance of GithubApiClient.
Constructor Details
#initialize(owner:, repo:, token:) ⇒ GithubApiClient
Returns a new instance of GithubApiClient.
7 8 9 10 |
# File 'lib/ghamma/github_api_client.rb', line 7 def initialize(owner:, repo:, token:) @repo_base_url = "#{BASE_URL}/repos/#{owner}/#{repo}" @authorization_header = "Bearer #{token}" end |
Instance Method Details
#fetch_workflow_duration_history(workflow_id, since, progressbar) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ghamma/github_api_client.rb', line 12 def fetch_workflow_duration_history(workflow_id, since, ) pages = 2 # enough to do the first loop page = 1 timings = [] while page <= pages since_param = ">#{since}" if since response = get( "/workflows/#{workflow_id}/runs", {page: page, per_page: 100, status: "success", exclude_pull_requests: true, created: since_param}.compact ) total_count = response["total_count"] .update(total: total_count) pages = total_count / 100 page += 1 response.fetch("workflow_runs").each do |workflow_run| run_timing = get("/runs/#{workflow_run["id"]}/timing") timings << [ workflow_run["id"], workflow_run["created_at"], run_timing["run_duration_ms"] ] .advance sleep 0.1 # Try to keep under the Github rate limit end sleep 1 # Try to keep under the Github rate limit end timings end |