What is @aws-sdk/client-codecommit?
@aws-sdk/client-codecommit is a part of the AWS SDK for JavaScript, which allows developers to interact with AWS CodeCommit, a fully managed source control service that makes it easy for teams to host secure and scalable Git repositories. This package provides methods to perform various operations on CodeCommit repositories, such as creating, updating, and deleting repositories, managing branches, and handling commits and pull requests.
What are @aws-sdk/client-codecommit's main functionalities?
Create Repository
This feature allows you to create a new repository in AWS CodeCommit. The code sample demonstrates how to initialize the CodeCommit client, create a command to create a repository, and send the command to AWS.
const { CodeCommitClient, CreateRepositoryCommand } = require('@aws-sdk/client-codecommit');
const client = new CodeCommitClient({ region: 'us-west-2' });
const command = new CreateRepositoryCommand({
repositoryName: 'MyNewRepo',
repositoryDescription: 'This is my new repository'
});
client.send(command).then(
(data) => console.log(data),
(error) => console.error(error)
);
List Repositories
This feature allows you to list all repositories in your AWS CodeCommit account. The code sample shows how to initialize the client, create a command to list repositories, and send the command to AWS.
const { CodeCommitClient, ListRepositoriesCommand } = require('@aws-sdk/client-codecommit');
const client = new CodeCommitClient({ region: 'us-west-2' });
const command = new ListRepositoriesCommand({});
client.send(command).then(
(data) => console.log(data.repositories),
(error) => console.error(error)
);
Get Repository
This feature allows you to retrieve information about a specific repository. The code sample demonstrates how to initialize the client, create a command to get repository details, and send the command to AWS.
const { CodeCommitClient, GetRepositoryCommand } = require('@aws-sdk/client-codecommit');
const client = new CodeCommitClient({ region: 'us-west-2' });
const command = new GetRepositoryCommand({
repositoryName: 'MyExistingRepo'
});
client.send(command).then(
(data) => console.log(data.repositoryMetadata),
(error) => console.error(error)
);
Create Branch
This feature allows you to create a new branch in a repository. The code sample shows how to initialize the client, create a command to create a branch, and send the command to AWS.
const { CodeCommitClient, CreateBranchCommand } = require('@aws-sdk/client-codecommit');
const client = new CodeCommitClient({ region: 'us-west-2' });
const command = new CreateBranchCommand({
repositoryName: 'MyRepo',
branchName: 'new-branch',
commitId: 'commit-id'
});
client.send(command).then(
(data) => console.log('Branch created successfully'),
(error) => console.error(error)
);
Create Pull Request
This feature allows you to create a pull request in a repository. The code sample demonstrates how to initialize the client, create a command to create a pull request, and send the command to AWS.
const { CodeCommitClient, CreatePullRequestCommand } = require('@aws-sdk/client-codecommit');
const client = new CodeCommitClient({ region: 'us-west-2' });
const command = new CreatePullRequestCommand({
title: 'My Pull Request',
description: 'This is a pull request',
targets: [
{
repositoryName: 'MyRepo',
sourceReference: 'source-branch',
destinationReference: 'destination-branch'
}
]
});
client.send(command).then(
(data) => console.log(data.pullRequest),
(error) => console.error(error)
);
Other packages similar to @aws-sdk/client-codecommit
nodegit
NodeGit is a native Node.js library that provides Git bindings. It allows you to perform Git operations such as cloning repositories, creating branches, and making commits. Unlike @aws-sdk/client-codecommit, which is specific to AWS CodeCommit, NodeGit can be used with any Git repository.
simple-git
Simple-git is a lightweight interface for running Git commands in any Node.js application. It provides a simple API to perform Git operations like cloning, committing, and pushing changes. Similar to NodeGit, it is not specific to AWS CodeCommit and can be used with any Git repository.
isomorphic-git
Isomorphic-git is a pure JavaScript implementation of Git that works in both Node.js and browser environments. It provides a wide range of Git functionalities, including cloning, committing, and pushing changes. Unlike @aws-sdk/client-codecommit, it is not tied to any specific Git hosting service.
@aws-sdk/client-codecommit
Description
AWS SDK for JavaScript CodeCommit Client for Node.js, Browser and React Native.
CodeCommit
This is the CodeCommit API Reference. This reference provides descriptions of the operations and data types for
CodeCommit API along with usage examples.
You can use the CodeCommit API to work with the following objects:
Repositories, by calling the following:
-
BatchGetRepositories, which returns information about one or more repositories associated with your Amazon Web Services account.
-
CreateRepository, which creates an CodeCommit repository.
-
DeleteRepository, which deletes an CodeCommit repository.
-
GetRepository, which returns information about a specified repository.
-
ListRepositories, which lists all CodeCommit repositories associated with your Amazon Web Services account.
-
UpdateRepositoryDescription, which sets or updates the description of the repository.
-
UpdateRepositoryEncryptionKey, which updates the Key Management Service encryption key used
to encrypt and decrypt a repository.
-
UpdateRepositoryName, which changes the name of the
repository. If you change the name of a repository, no other users of that
repository can access it until you send them the new HTTPS or SSH URL to
use.
Branches, by calling the following:
-
CreateBranch, which creates a branch in a specified
repository.
-
DeleteBranch, which deletes the specified branch in a repository unless it is the default branch.
-
GetBranch, which returns information about a specified branch.
-
ListBranches, which lists all branches for a specified repository.
-
UpdateDefaultBranch, which changes the default branch for a repository.
Files, by calling the following:
-
DeleteFile, which deletes the content of a specified file from a specified branch.
-
GetBlob, which returns the base-64 encoded content of an
individual Git blob object in a repository.
-
GetFile, which returns the base-64 encoded content of a specified file.
-
GetFolder, which returns the contents of a specified folder or directory.
-
ListFileCommitHistory, which retrieves a list of commits and changes to a specified file.
-
PutFile, which adds or modifies a single file in a specified repository and branch.
Commits, by calling the following:
-
BatchGetCommits, which returns information about one or more commits in a repository.
-
CreateCommit, which creates a commit for changes to a repository.
-
GetCommit, which returns information about a commit, including commit
messages and author and committer information.
-
GetDifferences, which returns information about the
differences in a valid commit specifier (such as a branch, tag, HEAD, commit ID,
or other fully qualified reference).
Merges, by calling the following:
-
BatchDescribeMergeConflicts, which returns information about conflicts in a merge between commits in a repository.
-
CreateUnreferencedMergeCommit, which creates an unreferenced commit between two branches or commits for the
purpose of comparing them and identifying any potential conflicts.
-
DescribeMergeConflicts, which returns information about merge conflicts between the base, source, and destination versions
of a file in a potential merge.
-
GetMergeCommit, which returns information about the merge between a source and destination commit.
-
GetMergeConflicts, which returns information about merge conflicts
between the source and destination branch in a pull request.
-
GetMergeOptions, which returns information about the available merge options between two branches or commit specifiers.
-
MergeBranchesByFastForward, which merges two branches using the fast-forward merge option.
-
MergeBranchesBySquash, which merges two branches using the squash merge option.
-
MergeBranchesByThreeWay, which merges two branches using the three-way merge option.
Pull requests, by calling the following:
-
CreatePullRequest, which creates a pull request in a specified repository.
-
CreatePullRequestApprovalRule, which creates an approval rule for a specified pull request.
-
DeletePullRequestApprovalRule, which deletes an approval rule for a specified pull request.
-
DescribePullRequestEvents, which returns information about one or more pull request events.
-
EvaluatePullRequestApprovalRules, which evaluates whether a pull request has met all the conditions specified in its associated approval rules.
-
GetCommentsForPullRequest, which returns information about comments on a specified pull request.
-
GetPullRequest, which returns information about a specified pull request.
-
GetPullRequestApprovalStates, which returns information about the approval states for a specified pull request.
-
GetPullRequestOverrideState, which returns information about whether approval rules have been set aside (overriden) for a
pull request, and if so, the Amazon Resource Name (ARN) of the user or identity that overrode the rules and their requirements for the pull request.
-
ListPullRequests, which lists all pull requests for a repository.
-
MergePullRequestByFastForward, which merges the source destination branch of a pull request into the specified destination
branch for that pull request using the fast-forward merge option.
-
MergePullRequestBySquash, which merges the source destination branch of a pull request into the specified destination
branch for that pull request using the squash merge option.
-
MergePullRequestByThreeWay, which merges the source destination branch of a pull request into the specified destination
branch for that pull request using the three-way merge option.
-
OverridePullRequestApprovalRules, which sets aside all approval rule requirements for a pull request.
-
PostCommentForPullRequest, which posts a comment to a pull request at the specified line, file, or request.
-
UpdatePullRequestApprovalRuleContent, which updates the structure of an approval rule for a pull request.
-
UpdatePullRequestApprovalState, which updates the state of an approval on a pull request.
-
UpdatePullRequestDescription, which updates the description of a pull request.
-
UpdatePullRequestStatus, which updates the status of a pull request.
-
UpdatePullRequestTitle, which updates the title of a pull request.
Approval rule templates, by calling the following:
-
AssociateApprovalRuleTemplateWithRepository, which associates a template
with a specified repository. After the template is associated with a repository,
CodeCommit creates approval rules that match the template conditions on
every pull request created in the specified repository.
-
BatchAssociateApprovalRuleTemplateWithRepositories, which associates a
template with one or more specified repositories. After the template is
associated with a repository, CodeCommit creates approval rules that match
the template conditions on every pull request created in the specified
repositories.
-
BatchDisassociateApprovalRuleTemplateFromRepositories, which removes the
association between a template and specified repositories so that approval rules
based on the template are not automatically created when pull requests are
created in those repositories.
-
CreateApprovalRuleTemplate, which creates a template for approval rules that can then be associated with one or more repositories
in your Amazon Web Services account.
-
DeleteApprovalRuleTemplate, which deletes the specified template. It does not remove approval rules on pull requests already created with the template.
-
DisassociateApprovalRuleTemplateFromRepository, which removes the
association between a template and a repository so that approval rules based on
the template are not automatically created when pull requests are created in the
specified repository.
-
GetApprovalRuleTemplate, which returns information about an approval rule template.
-
ListApprovalRuleTemplates, which lists all approval rule templates in the Amazon Web Services Region in your Amazon Web Services account.
-
ListAssociatedApprovalRuleTemplatesForRepository, which lists all approval rule templates that are associated with a specified repository.
-
ListRepositoriesForApprovalRuleTemplate, which lists all repositories associated with the specified approval rule template.
-
UpdateApprovalRuleTemplateDescription, which updates the description of an
approval rule template.
-
UpdateApprovalRuleTemplateName, which updates the name of an approval rule template.
-
UpdateApprovalRuleTemplateContent, which updates the content of an approval rule template.
Comments in a repository, by calling the following:
Tags used to tag resources in CodeCommit (not Git tags), by calling the following:
-
ListTagsForResource, which gets information about Amazon Web Servicestags for a specified Amazon Resource Name (ARN) in CodeCommit.
-
TagResource, which adds or updates tags for a resource in CodeCommit.
-
UntagResource, which removes tags for a resource in CodeCommit.
Triggers, by calling the following:
-
GetRepositoryTriggers, which returns information about triggers configured
for a repository.
-
PutRepositoryTriggers, which replaces all triggers for a repository and can
be used to create or delete triggers.
-
TestRepositoryTriggers, which tests the functionality of a repository trigger
by sending data to the trigger target.
For information about how to use CodeCommit, see the CodeCommit User Guide.
Installing
To install the this package, simply type add or install @aws-sdk/client-codecommit
using your favorite package manager:
npm install @aws-sdk/client-codecommit
yarn add @aws-sdk/client-codecommit
pnpm add @aws-sdk/client-codecommit
Getting Started
Import
The AWS SDK is modulized by clients and commands.
To send a request, you only need to import the CodeCommitClient
and
the commands you need, for example ListRepositoriesCommand
:
const { CodeCommitClient, ListRepositoriesCommand } = require("@aws-sdk/client-codecommit");
import { CodeCommitClient, ListRepositoriesCommand } from "@aws-sdk/client-codecommit";
Usage
To send a request, you:
- Initiate client with configuration (e.g. credentials, region).
- Initiate command with input parameters.
- Call
send
operation on client with command object as input. - If you are using a custom http handler, you may call
destroy()
to close open connections.
const client = new CodeCommitClient({ region: "REGION" });
const params = {
};
const command = new ListRepositoriesCommand(params);
Async/await
We recommend using await
operator to wait for the promise returned by send operation as follows:
try {
const data = await client.send(command);
} catch (error) {
} finally {
}
Async-await is clean, concise, intuitive, easy to debug and has better error handling
as compared to using Promise chains or callbacks.
Promises
You can also use Promise chaining
to execute send operation.
client.send(command).then(
(data) => {
},
(error) => {
}
);
Promises can also be called using .catch()
and .finally()
as follows:
client
.send(command)
.then((data) => {
})
.catch((error) => {
})
.finally(() => {
});
Callbacks
We do not recommend using callbacks because of callback hell,
but they are supported by the send operation.
client.send(command, (err, data) => {
});
v2 compatible style
The client can also send requests using v2 compatible style.
However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post
on modular packages in AWS SDK for JavaScript
import * as AWS from "@aws-sdk/client-codecommit";
const client = new AWS.CodeCommit({ region: "REGION" });
try {
const data = await client.listRepositories(params);
} catch (error) {
}
client
.listRepositories(params)
.then((data) => {
})
.catch((error) => {
});
client.listRepositories(params, (err, data) => {
});
Troubleshooting
When the service returns an exception, the error will include the exception information,
as well as response metadata (e.g. request id).
try {
const data = await client.send(command);
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
console.log({ requestId, cfId, extendedRequestId });
}
Getting Help
Please use these community resources for getting help.
We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.
To test your universal JavaScript code in Node.js, browser and react-native environments,
visit our code samples repo.
Contributing
This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-codecommit
package is updated.
To contribute to client you can check our generate clients scripts.
License
This SDK is distributed under the
Apache License, Version 2.0,
see LICENSE for more information.
Client Commands (Operations List)
AssociateApprovalRuleTemplateWithRepository
Command API Reference / Input / Output
BatchAssociateApprovalRuleTemplateWithRepositories
Command API Reference / Input / Output
BatchDescribeMergeConflicts
Command API Reference / Input / Output
BatchDisassociateApprovalRuleTemplateFromRepositories
Command API Reference / Input / Output
BatchGetCommits
Command API Reference / Input / Output
BatchGetRepositories
Command API Reference / Input / Output
CreateApprovalRuleTemplate
Command API Reference / Input / Output
CreateBranch
Command API Reference / Input / Output
CreateCommit
Command API Reference / Input / Output
CreatePullRequest
Command API Reference / Input / Output
CreatePullRequestApprovalRule
Command API Reference / Input / Output
CreateRepository
Command API Reference / Input / Output
CreateUnreferencedMergeCommit
Command API Reference / Input / Output
DeleteApprovalRuleTemplate
Command API Reference / Input / Output
DeleteBranch
Command API Reference / Input / Output
DeleteCommentContent
Command API Reference / Input / Output
DeleteFile
Command API Reference / Input / Output
DeletePullRequestApprovalRule
Command API Reference / Input / Output
DeleteRepository
Command API Reference / Input / Output
DescribeMergeConflicts
Command API Reference / Input / Output
DescribePullRequestEvents
Command API Reference / Input / Output
DisassociateApprovalRuleTemplateFromRepository
Command API Reference / Input / Output
EvaluatePullRequestApprovalRules
Command API Reference / Input / Output
GetApprovalRuleTemplate
Command API Reference / Input / Output
GetBlob
Command API Reference / Input / Output
GetBranch
Command API Reference / Input / Output
GetComment
Command API Reference / Input / Output
GetCommentReactions
Command API Reference / Input / Output
GetCommentsForComparedCommit
Command API Reference / Input / Output
GetCommentsForPullRequest
Command API Reference / Input / Output
GetCommit
Command API Reference / Input / Output
GetDifferences
Command API Reference / Input / Output
GetFile
Command API Reference / Input / Output
GetFolder
Command API Reference / Input / Output
GetMergeCommit
Command API Reference / Input / Output
GetMergeConflicts
Command API Reference / Input / Output
GetMergeOptions
Command API Reference / Input / Output
GetPullRequest
Command API Reference / Input / Output
GetPullRequestApprovalStates
Command API Reference / Input / Output
GetPullRequestOverrideState
Command API Reference / Input / Output
GetRepository
Command API Reference / Input / Output
GetRepositoryTriggers
Command API Reference / Input / Output
ListApprovalRuleTemplates
Command API Reference / Input / Output
ListAssociatedApprovalRuleTemplatesForRepository
Command API Reference / Input / Output
ListBranches
Command API Reference / Input / Output
ListFileCommitHistory
Command API Reference / Input / Output
ListPullRequests
Command API Reference / Input / Output
ListRepositories
Command API Reference / Input / Output
ListRepositoriesForApprovalRuleTemplate
Command API Reference / Input / Output
ListTagsForResource
Command API Reference / Input / Output
MergeBranchesByFastForward
Command API Reference / Input / Output
MergeBranchesBySquash
Command API Reference / Input / Output
MergeBranchesByThreeWay
Command API Reference / Input / Output
MergePullRequestByFastForward
Command API Reference / Input / Output
MergePullRequestBySquash
Command API Reference / Input / Output
MergePullRequestByThreeWay
Command API Reference / Input / Output
OverridePullRequestApprovalRules
Command API Reference / Input / Output
PostCommentForComparedCommit
Command API Reference / Input / Output
PostCommentForPullRequest
Command API Reference / Input / Output
PostCommentReply
Command API Reference / Input / Output
PutCommentReaction
Command API Reference / Input / Output
PutFile
Command API Reference / Input / Output
PutRepositoryTriggers
Command API Reference / Input / Output
TagResource
Command API Reference / Input / Output
TestRepositoryTriggers
Command API Reference / Input / Output
UntagResource
Command API Reference / Input / Output
UpdateApprovalRuleTemplateContent
Command API Reference / Input / Output
UpdateApprovalRuleTemplateDescription
Command API Reference / Input / Output
UpdateApprovalRuleTemplateName
Command API Reference / Input / Output
UpdateComment
Command API Reference / Input / Output
UpdateDefaultBranch
Command API Reference / Input / Output
UpdatePullRequestApprovalRuleContent
Command API Reference / Input / Output
UpdatePullRequestApprovalState
Command API Reference / Input / Output
UpdatePullRequestDescription
Command API Reference / Input / Output
UpdatePullRequestStatus
Command API Reference / Input / Output
UpdatePullRequestTitle
Command API Reference / Input / Output
UpdateRepositoryDescription
Command API Reference / Input / Output
UpdateRepositoryEncryptionKey
Command API Reference / Input / Output
UpdateRepositoryName
Command API Reference / Input / Output