Skip to content

GitProviderInterface

Reads repositories from a Git host's API, such as GitHub's.


  • Full name: \Drupal\git_host\GitProviderInterface

Methods

getApiUrl

Gets the base URL of a host's API.

public getApiUrl(string $host): string

Parameters:

Parameter Type Description
$host string
The host, such as github.com.

Return Value:

The API's base URL, ending with a slash.


getRequestHeaders

Gets the headers to send with every API request.

public getRequestHeaders(string|null $token): array

Parameters:

Parameter Type Description
$token string|null
The host's token, or NULL to send the request without one.

Return Value:

The request headers.


getFileContents

Gets the contents of a file in a repository.

public getFileContents(\Drupal\git_host\GitApi $api, string $host, string $repository, string $path, string $ref = ''): string

Parameters:

Parameter Type Description
$api \Drupal\git_host\GitApi
The API service, for the request.
$host string
The repository's host.
$repository string
The repository's path on the host, such as owner/name.
$path string
The file's path in the repository.
$ref string
(optional) A branch, tag or commit. Defaults to the default branch.

Return Value:

The file's contents.

Throws:

  • GuzzleException
  • JsonException
  • RuntimeException

getReleases

Gets a repository's published releases.

public getReleases(\Drupal\git_host\GitApi $api, string $host, string $repository): array

Parameters:

Parameter Type Description
$api \Drupal\git_host\GitApi
The API service, for the requests.
$host string
The repository's host.
$repository string
The repository's path on the host, such as owner/name.

Return Value:

Releases, newest first, each with its 'tag', the 'url' of its page on the host, the 'download_url' of its archive, and its 'date' as a Unix timestamp. Draft and upcoming releases are left out.

Throws:

  • GuzzleException
  • JsonException
  • RuntimeException

getProtectedBranches

Gets a repository's protected branches.

public getProtectedBranches(\Drupal\git_host\GitApi $api, string $host, string $repository): array

Parameters:

Parameter Type Description
$api \Drupal\git_host\GitApi
The API service, for the requests.
$host string
The repository's host.
$repository string
The repository's path on the host, such as owner/name.

Return Value:

Branches, each with its 'name', the 'url' of its page on the host, the 'download_url' of its archive, and the 'date' of its latest commit as a Unix timestamp.

Throws:

  • GuzzleException
  • JsonException
  • RuntimeException