Skip to content

GitLab

Reads repositories on gitlab.com and self-managed GitLab hosts.


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 $token): array

Parameters:

Parameter Type Description
$token ?string
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.


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.


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.


getArchiveUrl

Gets the URL of a ZIP archive of a tag or branch.

protected getArchiveUrl(string $host, string $repository, string $ref): string

Parameters:

Parameter Type Description
$host string
The repository's host.
$repository string
The repository's path on the host, such as group/project.
$ref string
The tag or branch.

Return Value:

The archive's URL.