Google Cloud Build V2 Client - Class RepositoryManagerClient (0.6.1)

Reference documentation and code samples for the Google Cloud Build V2 Client class RepositoryManagerClient.

Service Description: Manages connections to source code repostiories.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

$repositoryManagerClient = new RepositoryManagerClient();
try {
    $formattedParent = $repositoryManagerClient->connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]');
    $requests = [];
    $operationResponse = $repositoryManagerClient->batchCreateRepositories($formattedParent, $requests);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $repositoryManagerClient->batchCreateRepositories($formattedParent, $requests);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $repositoryManagerClient->resumeOperation($operationName, 'batchCreateRepositories');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $repositoryManagerClient->close();
}

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Methods

connectionName

Formats a string containing the fully-qualified path to represent a connection resource.

Parameters
NameDescription
project string
location string
connection string
Returns
TypeDescription
stringThe formatted connection resource.

locationName

Formats a string containing the fully-qualified path to represent a location resource.

Parameters
NameDescription
project string
location string
Returns
TypeDescription
stringThe formatted location resource.

repositoryName

Formats a string containing the fully-qualified path to represent a repository resource.

Parameters
NameDescription
project string
location string
connection string
repository string
Returns
TypeDescription
stringThe formatted repository resource.

secretVersionName

Formats a string containing the fully-qualified path to represent a secret_version resource.

Parameters
NameDescription
project string
secret string
version string
Returns
TypeDescription
stringThe formatted secret_version resource.

serviceName

Formats a string containing the fully-qualified path to represent a service resource.

Parameters
NameDescription
project string
location string
namespace string
service string
Returns
TypeDescription
stringThe formatted service resource.

parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • connection: projects/{project}/locations/{location}/connections/{connection}
  • location: projects/{project}/locations/{location}
  • repository: projects/{project}/locations/{location}/connections/{connection}/repositories/{repository}
  • secretVersion: projects/{project}/secrets/{secret}/versions/{version}
  • service: projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

getOperationsClient

Return an OperationsClient object with the same endpoint as $this.

Returns
TypeDescription
Google\ApiCore\LongRunning\OperationsClient

resumeOperation

Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.

Parameters
NameDescription
operationName string

The name of the long running operation

methodName string

The name of the method used to start the operation

Returns
TypeDescription
Google\ApiCore\OperationResponse

__construct

Constructor.

Parameters
NameDescription
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

batchCreateRepositories

Creates multiple repositories inside a connection.

Parameters
NameDescription
parent string

Required. The connection to contain all the repositories being created. Format: projects//locations//connections/* The parent field in the CreateRepositoryRequest messages must either be empty or match this field.

requests array<Google\Cloud\Build\V2\CreateRepositoryRequest>

Required. The request messages specifying the repositories to create.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V2\BatchCreateRepositoriesResponse;
use Google\Cloud\Build\V2\CreateRepositoryRequest;
use Google\Cloud\Build\V2\Repository;
use Google\Cloud\Build\V2\RepositoryManagerClient;
use Google\Rpc\Status;

/**
 * @param string $formattedParent             The connection to contain all the repositories being created.
 *                                            Format: projects/&#42;/locations/&#42;/connections/*
 *                                            The parent field in the CreateRepositoryRequest messages
 *                                            must either be empty or match this field. Please see
 *                                            {@see RepositoryManagerClient::connectionName()} for help formatting this field.
 * @param string $formattedRequestsParent     The connection to contain the repository. If the request is part
 *                                            of a BatchCreateRepositoriesRequest, this field should be empty or match
 *                                            the parent specified there. Please see
 *                                            {@see RepositoryManagerClient::connectionName()} for help formatting this field.
 * @param string $requestsRepositoryRemoteUri Git Clone HTTPS URI.
 * @param string $requestsRepositoryId        The ID to use for the repository, which will become the final
 *                                            component of the repository's resource name. This ID should be unique in
 *                                            the connection. Allows alphanumeric characters and any of
 *                                            -._~%!$&'()*+,;=&#64;.
 */
function batch_create_repositories_sample(
    string $formattedParent,
    string $formattedRequestsParent,
    string $requestsRepositoryRemoteUri,
    string $requestsRepositoryId
): void {
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $requestsRepository = (new Repository())
        ->setRemoteUri($requestsRepositoryRemoteUri);
    $createRepositoryRequest = (new CreateRepositoryRequest())
        ->setParent($formattedRequestsParent)
        ->setRepository($requestsRepository)
        ->setRepositoryId($requestsRepositoryId);
    $requests = [$createRepositoryRequest,];

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $repositoryManagerClient->batchCreateRepositories($formattedParent, $requests);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var BatchCreateRepositoriesResponse $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = RepositoryManagerClient::connectionName(
        '[PROJECT]',
        '[LOCATION]',
        '[CONNECTION]'
    );
    $formattedRequestsParent = RepositoryManagerClient::connectionName(
        '[PROJECT]',
        '[LOCATION]',
        '[CONNECTION]'
    );
    $requestsRepositoryRemoteUri = '[REMOTE_URI]';
    $requestsRepositoryId = '[REPOSITORY_ID]';

    batch_create_repositories_sample(
        $formattedParent,
        $formattedRequestsParent,
        $requestsRepositoryRemoteUri,
        $requestsRepositoryId
    );
}

createConnection

Creates a Connection.

Parameters
NameDescription
parent string

Required. Project and location where the connection will be created. Format: projects/*/locations/*.

connection Google\Cloud\Build\V2\Connection

Required. The Connection to create.

connectionId string

Required. The ID to use for the Connection, which will become the final component of the Connection's resource name. Names must be unique per-project per-location. Allows alphanumeric characters and any of -._~%!$&'()*+,;=@.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V2\Connection;
use Google\Cloud\Build\V2\RepositoryManagerClient;
use Google\Rpc\Status;

/**
 * @param string $formattedParent Project and location where the connection will be created.
 *                                Format: `projects/&#42;/locations/*`. Please see
 *                                {@see RepositoryManagerClient::locationName()} for help formatting this field.
 * @param string $connectionId    The ID to use for the Connection, which will become the final
 *                                component of the Connection's resource name. Names must be unique
 *                                per-project per-location. Allows alphanumeric characters and any of
 *                                -._~%!$&'()*+,;=&#64;.
 */
function create_connection_sample(string $formattedParent, string $connectionId): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $connection = new Connection();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $repositoryManagerClient->createConnection(
            $formattedParent,
            $connection,
            $connectionId
        );
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Connection $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = RepositoryManagerClient::locationName('[PROJECT]', '[LOCATION]');
    $connectionId = '[CONNECTION_ID]';

    create_connection_sample($formattedParent, $connectionId);
}

createRepository

Creates a Repository.

Parameters
NameDescription
parent string

Required. The connection to contain the repository. If the request is part of a BatchCreateRepositoriesRequest, this field should be empty or match the parent specified there.

repository Google\Cloud\Build\V2\Repository

Required. The repository to create.

repositoryId string

Required. The ID to use for the repository, which will become the final component of the repository's resource name. This ID should be unique in the connection. Allows alphanumeric characters and any of -._~%!$&'()*+,;=@.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V2\Repository;
use Google\Cloud\Build\V2\RepositoryManagerClient;
use Google\Rpc\Status;

/**
 * @param string $formattedParent     The connection to contain the repository. If the request is part
 *                                    of a BatchCreateRepositoriesRequest, this field should be empty or match
 *                                    the parent specified there. Please see
 *                                    {@see RepositoryManagerClient::connectionName()} for help formatting this field.
 * @param string $repositoryRemoteUri Git Clone HTTPS URI.
 * @param string $repositoryId        The ID to use for the repository, which will become the final
 *                                    component of the repository's resource name. This ID should be unique in
 *                                    the connection. Allows alphanumeric characters and any of
 *                                    -._~%!$&'()*+,;=&#64;.
 */
function create_repository_sample(
    string $formattedParent,
    string $repositoryRemoteUri,
    string $repositoryId
): void {
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $repository = (new Repository())
        ->setRemoteUri($repositoryRemoteUri);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $repositoryManagerClient->createRepository(
            $formattedParent,
            $repository,
            $repositoryId
        );
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Repository $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = RepositoryManagerClient::connectionName(
        '[PROJECT]',
        '[LOCATION]',
        '[CONNECTION]'
    );
    $repositoryRemoteUri = '[REMOTE_URI]';
    $repositoryId = '[REPOSITORY_ID]';

    create_repository_sample($formattedParent, $repositoryRemoteUri, $repositoryId);
}

deleteConnection

Deletes a single connection.

Parameters
NameDescription
name string

Required. The name of the Connection to delete. Format: projects/*/locations/*/connections/*.

optionalArgs array

Optional.

↳ etag string

The current etag of the connection. If an etag is provided and does not match the current etag of the connection, deletion will be blocked and an ABORTED error will be returned.

↳ validateOnly bool

If set, validate the request, but do not actually post it.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V2\RepositoryManagerClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the Connection to delete.
 *                              Format: `projects/&#42;/locations/&#42;/connections/*`. Please see
 *                              {@see RepositoryManagerClient::connectionName()} for help formatting this field.
 */
function delete_connection_sample(string $formattedName): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $repositoryManagerClient->deleteConnection($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            printf('Operation completed successfully.' . PHP_EOL);
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = RepositoryManagerClient::connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]');

    delete_connection_sample($formattedName);
}

deleteRepository

Deletes a single repository.

Parameters
NameDescription
name string

Required. The name of the Repository to delete. Format: projects/*/locations/*/connections/*/repositories/*.

optionalArgs array

Optional.

↳ etag string

The current etag of the repository. If an etag is provided and does not match the current etag of the repository, deletion will be blocked and an ABORTED error will be returned.

↳ validateOnly bool

If set, validate the request, but do not actually post it.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V2\RepositoryManagerClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the Repository to delete.
 *                              Format: `projects/&#42;/locations/&#42;/connections/&#42;/repositories/*`. Please see
 *                              {@see RepositoryManagerClient::repositoryName()} for help formatting this field.
 */
function delete_repository_sample(string $formattedName): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $repositoryManagerClient->deleteRepository($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            printf('Operation completed successfully.' . PHP_EOL);
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = RepositoryManagerClient::repositoryName(
        '[PROJECT]',
        '[LOCATION]',
        '[CONNECTION]',
        '[REPOSITORY]'
    );

    delete_repository_sample($formattedName);
}

fetchLinkableRepositories

FetchLinkableRepositories get repositories from SCM that are accessible and could be added to the connection.

Parameters
NameDescription
connection string

Required. The name of the Connection. Format: projects/*/locations/*/connections/*.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Build\V2\Repository;
use Google\Cloud\Build\V2\RepositoryManagerClient;

/**
 * @param string $formattedConnection The name of the Connection.
 *                                    Format: `projects/&#42;/locations/&#42;/connections/*`. Please see
 *                                    {@see RepositoryManagerClient::connectionName()} for help formatting this field.
 */
function fetch_linkable_repositories_sample(string $formattedConnection): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $repositoryManagerClient->fetchLinkableRepositories($formattedConnection);

        /** @var Repository $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedConnection = RepositoryManagerClient::connectionName(
        '[PROJECT]',
        '[LOCATION]',
        '[CONNECTION]'
    );

    fetch_linkable_repositories_sample($formattedConnection);
}

fetchReadToken

Fetches read token of a given repository.

Parameters
NameDescription
repository string

Required. The resource name of the repository in the format projects/*/locations/*/connections/*/repositories/*.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V2\FetchReadTokenResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V2\FetchReadTokenResponse;
use Google\Cloud\Build\V2\RepositoryManagerClient;

/**
 * @param string $formattedRepository The resource name of the repository in the format
 *                                    `projects/&#42;/locations/&#42;/connections/&#42;/repositories/*`. Please see
 *                                    {@see RepositoryManagerClient::repositoryName()} for help formatting this field.
 */
function fetch_read_token_sample(string $formattedRepository): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var FetchReadTokenResponse $response */
        $response = $repositoryManagerClient->fetchReadToken($formattedRepository);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedRepository = RepositoryManagerClient::repositoryName(
        '[PROJECT]',
        '[LOCATION]',
        '[CONNECTION]',
        '[REPOSITORY]'
    );

    fetch_read_token_sample($formattedRepository);
}

fetchReadWriteToken

Fetches read/write token of a given repository.

Parameters
NameDescription
repository string

Required. The resource name of the repository in the format projects/*/locations/*/connections/*/repositories/*.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V2\FetchReadWriteTokenResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V2\FetchReadWriteTokenResponse;
use Google\Cloud\Build\V2\RepositoryManagerClient;

/**
 * @param string $formattedRepository The resource name of the repository in the format
 *                                    `projects/&#42;/locations/&#42;/connections/&#42;/repositories/*`. Please see
 *                                    {@see RepositoryManagerClient::repositoryName()} for help formatting this field.
 */
function fetch_read_write_token_sample(string $formattedRepository): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var FetchReadWriteTokenResponse $response */
        $response = $repositoryManagerClient->fetchReadWriteToken($formattedRepository);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedRepository = RepositoryManagerClient::repositoryName(
        '[PROJECT]',
        '[LOCATION]',
        '[CONNECTION]',
        '[REPOSITORY]'
    );

    fetch_read_write_token_sample($formattedRepository);
}

getConnection

Gets details of a single connection.

Parameters
NameDescription
name string

Required. The name of the Connection to retrieve. Format: projects/*/locations/*/connections/*.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V2\Connection
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V2\Connection;
use Google\Cloud\Build\V2\RepositoryManagerClient;

/**
 * @param string $formattedName The name of the Connection to retrieve.
 *                              Format: `projects/&#42;/locations/&#42;/connections/*`. Please see
 *                              {@see RepositoryManagerClient::connectionName()} for help formatting this field.
 */
function get_connection_sample(string $formattedName): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var Connection $response */
        $response = $repositoryManagerClient->getConnection($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = RepositoryManagerClient::connectionName('[PROJECT]', '[LOCATION]', '[CONNECTION]');

    get_connection_sample($formattedName);
}

getRepository

Gets details of a single repository.

Parameters
NameDescription
name string

Required. The name of the Repository to retrieve. Format: projects/*/locations/*/connections/*/repositories/*.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V2\Repository
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V2\Repository;
use Google\Cloud\Build\V2\RepositoryManagerClient;

/**
 * @param string $formattedName The name of the Repository to retrieve.
 *                              Format: `projects/&#42;/locations/&#42;/connections/&#42;/repositories/*`. Please see
 *                              {@see RepositoryManagerClient::repositoryName()} for help formatting this field.
 */
function get_repository_sample(string $formattedName): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var Repository $response */
        $response = $repositoryManagerClient->getRepository($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = RepositoryManagerClient::repositoryName(
        '[PROJECT]',
        '[LOCATION]',
        '[CONNECTION]',
        '[REPOSITORY]'
    );

    get_repository_sample($formattedName);
}

listConnections

Lists Connections in a given project and location.

Parameters
NameDescription
parent string

Required. The parent, which owns this collection of Connections. Format: projects/*/locations/*.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Build\V2\Connection;
use Google\Cloud\Build\V2\RepositoryManagerClient;

/**
 * @param string $formattedParent The parent, which owns this collection of Connections.
 *                                Format: `projects/&#42;/locations/*`. Please see
 *                                {@see RepositoryManagerClient::locationName()} for help formatting this field.
 */
function list_connections_sample(string $formattedParent): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $repositoryManagerClient->listConnections($formattedParent);

        /** @var Connection $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = RepositoryManagerClient::locationName('[PROJECT]', '[LOCATION]');

    list_connections_sample($formattedParent);
}

listRepositories

Lists Repositories in a given connection.

Parameters
NameDescription
parent string

Required. The parent, which owns this collection of Repositories. Format: projects/*/locations/*/connections/*.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ filter string

A filter expression that filters resources listed in the response. Expressions must follow API improvement proposal AIP-160. e.g. remote_uri:"https://github.com*".

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Build\V2\Repository;
use Google\Cloud\Build\V2\RepositoryManagerClient;

/**
 * @param string $formattedParent The parent, which owns this collection of Repositories.
 *                                Format: `projects/&#42;/locations/&#42;/connections/*`. Please see
 *                                {@see RepositoryManagerClient::connectionName()} for help formatting this field.
 */
function list_repositories_sample(string $formattedParent): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $repositoryManagerClient->listRepositories($formattedParent);

        /** @var Repository $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = RepositoryManagerClient::connectionName(
        '[PROJECT]',
        '[LOCATION]',
        '[CONNECTION]'
    );

    list_repositories_sample($formattedParent);
}

updateConnection

Updates a single connection.

Parameters
NameDescription
connection Google\Cloud\Build\V2\Connection

Required. The Connection to update.

optionalArgs array

Optional.

↳ updateMask FieldMask

The list of fields to be updated.

↳ allowMissing bool

If set to true, and the connection is not found a new connection will be created. In this situation update_mask is ignored. The creation will succeed only if the input connection has all the necessary information (e.g a github_config with both user_oauth_token and installation_id properties).

↳ etag string

The current etag of the connection. If an etag is provided and does not match the current etag of the connection, update will be blocked and an ABORTED error will be returned.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V2\Connection;
use Google\Cloud\Build\V2\RepositoryManagerClient;
use Google\Rpc\Status;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_connection_sample(): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $connection = new Connection();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $repositoryManagerClient->updateConnection($connection);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Connection $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

getIamPolicy

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

Parameters
NameDescription
resource string

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

optionalArgs array

Optional.

↳ options GetPolicyOptions

OPTIONAL: A GetPolicyOptions object for specifying options to GetIamPolicy.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\Policy
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V2\RepositoryManagerClient;
use Google\Cloud\Iam\V1\Policy;

/**
 * @param string $resource REQUIRED: The resource for which the policy is being requested.
 *                         See the operation documentation for the appropriate value for this field.
 */
function get_iam_policy_sample(string $resource): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Call the API and handle any network failures.
    try {
        /** @var Policy $response */
        $response = $repositoryManagerClient->getIamPolicy($resource);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $resource = '[RESOURCE]';

    get_iam_policy_sample($resource);
}

setIamPolicy

Sets the access control policy on the specified resource. Replaces any existing policy.

Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.

Parameters
NameDescription
resource string

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policy Google\Cloud\Iam\V1\Policy

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

optionalArgs array

Optional.

↳ updateMask FieldMask

OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only the fields in the mask will be modified. If no mask is provided, the following default mask is used: paths: "bindings, etag"

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\Policy
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V2\RepositoryManagerClient;
use Google\Cloud\Iam\V1\Policy;

/**
 * @param string $resource REQUIRED: The resource for which the policy is being specified.
 *                         See the operation documentation for the appropriate value for this field.
 */
function set_iam_policy_sample(string $resource): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $policy = new Policy();

    // Call the API and handle any network failures.
    try {
        /** @var Policy $response */
        $response = $repositoryManagerClient->setIamPolicy($resource, $policy);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $resource = '[RESOURCE]';

    set_iam_policy_sample($resource);
}

testIamPermissions

Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

Parameters
NameDescription
resource string

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissions string[]

The set of permissions to check for the resource. Permissions with wildcards (such as '' or 'storage.') are not allowed. For more information see IAM Overview.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\TestIamPermissionsResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V2\RepositoryManagerClient;
use Google\Cloud\Iam\V1\TestIamPermissionsResponse;

/**
 * @param string $resource           REQUIRED: The resource for which the policy detail is being requested.
 *                                   See the operation documentation for the appropriate value for this field.
 * @param string $permissionsElement The set of permissions to check for the `resource`. Permissions with
 *                                   wildcards (such as '*' or 'storage.*') are not allowed. For more
 *                                   information see
 *                                   [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
 */
function test_iam_permissions_sample(string $resource, string $permissionsElement): void
{
    // Create a client.
    $repositoryManagerClient = new RepositoryManagerClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $permissions = [$permissionsElement,];

    // Call the API and handle any network failures.
    try {
        /** @var TestIamPermissionsResponse $response */
        $response = $repositoryManagerClient->testIamPermissions($resource, $permissions);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $resource = '[RESOURCE]';
    $permissionsElement = '[PERMISSIONS]';

    test_iam_permissions_sample($resource, $permissionsElement);
}

Constants

SERVICE_NAME

Value: 'google.devtools.cloudbuild.v2.RepositoryManager'

The name of the service.

SERVICE_ADDRESS

Value: 'cloudbuild.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.