CodeCommit client

This page contains examples with the CodeCommit client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.

The CodeCommit package could be installed with Composer.

composer require async-aws/code-commit

A new client object may be instantiated by:

use AsyncAws\CodeCommit\CodeCommitClient; $codeCommit = new CodeCommitClient();

The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:

use AsyncAws\CodeCommit\CodeCommitClient; $codeCommit = new CodeCommitClient([ 'accessKeyId' => 'my_access_key', 'accessKeySecret' => 'my_access_secret', 'region' => 'eu-central-1', ]);

For all available options, see the configuration reference.

Usage

Get a branch

use AsyncAws\CodeCommit\CodeCommitClient; use AsyncAws\CodeCommit\Input\GetBranchInput; $codeCommit = new CodeCommitClient(); $branch = $codeCommit->getBranch(new GetBranchInput([ 'repositoryName' => $repoName, 'branchName' => 'main' ])); $latestCommitId = $branch->getBranch()->getCommitId();

Get list of different blobs between two commits

use AsyncAws\CodeCommit\CodeCommitClient; use AsyncAws\CodeCommit\Input\GetDifferencesInput; $codeCommit = new CodeCommitClient(); $differences = $codeCommit->getDifferences(new GetDifferencesInput([ 'repositoryName' => $repoName, 'afterCommitSpecifier' => $latestCommitId, 'beforeCommitSpecifier' => $baseCommitId ])); foreach($differences->getDifferences() as $diff) { echo $diff->getAfterBlob()?->getPath(); // eg 'composer.json' echo $diff->getAfterBlob()?->getBlobId(); echo $diff->getChangeType(); // eg 'A', 'M', 'D' for 'Added', 'Modified', 'Deleted' }

Get information about a blob

use AsyncAws\CodeCommit\CodeCommitClient; use AsyncAws\CodeCommit\Input\GetBlobInput; $codeCommit = new CodeCommitClient(); $blob = $codeCommit->getBlob(new GetBlobInput([ 'repositoryName' => $repoName, 'blobId' => $blobId ])); echo $blob->getContent(); // Lorem ipsum dolor sit amet...

The source code to this page is found on GitHub.