Class: CIRunner::Client::Github

Inherits:
Base
  • Object
show all
Defined in:
lib/ci_runner/client/github.rb

Overview

A simple client to interact the GitHub API.

Examples:

Using the client

Github.new("access_token").me

Constant Summary collapse

API_ENDPOINT =
"api.github.com"

Instance Method Summary collapse

Methods inherited from Base

default_client, #initialize

Constructor Details

This class inherits a constructor from CIRunner::Client::Base

Instance Method Details

#check_runs(repository, commit) ⇒ Hash

Makes an API request to get the CI checks for the commit.

Parameters:

  • repository (String)

    The full repository name, including the owner (rails/rails)

  • commit (String)

    The Git commit that has been pushed to GitHub.

Returns:

  • (Hash)

    See GitHub documentation.

See Also:



33
34
35
# File 'lib/ci_runner/client/github.rb', line 33

def check_runs(repository, commit)
  get("/repos/#{repository}/commits/#{commit}/check-runs")
end

#commit_statuses(repository, commit) ⇒ Hash

Makes an API request to get the Commit statuses for the commit.

Parameters:

  • repository (String)

    The full repository name, including the owner (rails/rails)

  • commit (String)

    The Git commit that has been pushed to GitHub.

Returns:

  • (Hash)

    See GitHub documentation.

See Also:



45
46
47
# File 'lib/ci_runner/client/github.rb', line 45

def commit_statuses(repository, commit)
  get("/repos/#{repository}/commits/#{commit}/statuses")
end

#download_log(repository, check_run_id) ⇒ Tempfile, IO

Makes two requests to get the CI log for a check run. The first request returns a 302 containing a Location header poiting to a short lived url to download the log. The second request is to actually download the log.

Parameters:

  • repository (String)

    The full repository name, including the owner (rails/rails)

  • check_run_id (Integer)

    The GitHub ID of the check run.

Returns:

  • (Tempfile, IO)

    Depending on the size of the response. Quirk of URI.open.

See Also:



59
60
61
62
63
# File 'lib/ci_runner/client/github.rb', line 59

def download_log(repository, check_run_id)
  download_url = get("/repos/#{repository}/actions/jobs/#{check_run_id}/logs")

  URI.open(download_url)
end

#meHash

Make an API request to get the authenticated user. Used to verify if the access token the user has stored in its config is valid.

Returns:

  • (Hash)

    See GitHub documentation.

See Also:



21
22
23
# File 'lib/ci_runner/client/github.rb', line 21

def me
  get("/user")
end