CodeCommit examples using Amazon CLI
The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with CodeCommit.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use associate-approval-rule-template-with-repository.
- Amazon CLI
-
To associate an approval rule template with a repository
The following
associate-approval-rule-template-with-repositoryexample associates the specified approval rule template with a repository namedMyDemoRepo.aws codecommit associate-approval-rule-template-with-repository \ --repository-nameMyDemoRepo\ --approval-rule-template-name2-approver-rule-for-mainThis command produces no output.
For more information, see Associate an Approval Rule Template with a Repository
in the Amazon CodeCommit User Guide. -
For API details, see AssociateApprovalRuleTemplateWithRepository
in Amazon CLI Command Reference.
-
The following code example shows how to use batch-associate-approval-rule-template-with-repositories.
- Amazon CLI
-
To associate an approval rule template with multiple repositories in a single operation
The following
batch-associate-approval-rule-template-with-repositoriesexample associates the specified approval rule template with repositories namedMyDemoRepoandMyOtherDemoRepo.Note: Approval rule templates are specific to the Amazon Region where they are created. They can only be associated with repositories in that Amazon Region.
aws codecommit batch-associate-approval-rule-template-with-repositories \ --repository-namesMyDemoRepo,MyOtherDemoRepo\ --approval-rule-template-name2-approver-rule-for-mainOutput:
{ "associatedRepositoryNames": [ "MyDemoRepo", "MyOtherDemoRepo" ], "errors": [] }For more information, see Associate an Approval Rule Template with a Repository
in the Amazon CodeCommit User Guide. -
For API details, see BatchAssociateApprovalRuleTemplateWithRepositories
in Amazon CLI Command Reference.
-
The following code example shows how to use batch-describe-merge-conflicts.
- Amazon CLI
-
To get information about merge conflicts in all files or a subset of files in a merge between two commit specifiers
The following
batch-describe-merge-conflictsexample determines the merge conflicts for merging a source branch namedfeature-randomizationfeaturewith a destination branch namedmainusing theTHREE_WAY_MERGEstrategy in a repository namedMyDemoRepo.aws codecommit batch-describe-merge-conflicts \ --source-commit-specifierfeature-randomizationfeature\ --destination-commit-specifiermain\ --merge-optionTHREE_WAY_MERGE\ --repository-nameMyDemoRepoOutput:
{ "conflicts": [ { "conflictMetadata": { "filePath": "readme.md", "fileSizes": { "source": 139, "destination": 230, "base": 85 }, "fileModes": { "source": "NORMAL", "destination": "NORMAL", "base": "NORMAL" }, "objectTypes": { "source": "FILE", "destination": "FILE", "base": "FILE" }, "numberOfConflicts": 1, "isBinaryFile": { "source": false, "destination": false, "base": false }, "contentConflict": true, "fileModeConflict": false, "objectTypeConflict": false, "mergeOperations": { "source": "M", "destination": "M" } }, "mergeHunks": [ { "isConflict": true, "source": { "startLine": 0, "endLine": 3, "hunkContent": "VGhpcyBpEXAMPLE==" }, "destination": { "startLine": 0, "endLine": 1, "hunkContent": "VXNlIHRoEXAMPLE=" } } ] } ], "errors": [], "destinationCommitId": "86958e0aEXAMPLE", "sourceCommitId": "6ccd57fdEXAMPLE", "baseCommitId": "767b6958EXAMPLE" }For more information, see Resolve Conflicts in a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see BatchDescribeMergeConflicts
in Amazon CLI Command Reference.
-
The following code example shows how to use batch-disassociate-approval-rule-template-from-repositories.
- Amazon CLI
-
To disassociate an approval rule template from multiple repositories in a single operation
The following
batch-disassociate-approval-rule-template-from-repositoriesexample disassociates the specified approval rule template from repositories namedMyDemoRepoandMyOtherDemoRepo.aws codecommit batch-disassociate-approval-rule-template-from-repositories \ --repository-namesMyDemoRepo,MyOtherDemoRepo\ --approval-rule-template-name1-approval-rule-for-allpullrequestsOutput:
{ "disassociatedRepositoryNames": [ "MyDemoRepo", "MyOtherDemoRepo" ], "errors": [] }For more information, see Disassociate an Approval Rule Template
in the Amazon CodeCommit User Guide. -
For API details, see BatchDisassociateApprovalRuleTemplateFromRepositories
in Amazon CLI Command Reference.
-
The following code example shows how to use batch-get-commits.
- Amazon CLI
-
To view information about multiple commits
The following
batch-get-commitsexample displays details about the specified commits.aws codecommit batch-get-commits \ --repository-nameMyDemoRepo\ --commit-ids317f8570EXAMPLE4c925148EXAMPLEOutput:
{ "commits": [ { "additionalData": "", "committer": { "date": "1508280564 -0800", "name": "Mary Major", "email": "mary_major@example.com" }, "author": { "date": "1508280564 -0800", "name": "Mary Major", "email": "mary_major@example.com" }, "commitId": "317f8570EXAMPLE", "treeId": "1f330709EXAMPLE", "parents": [ "6e147360EXAMPLE" ], "message": "Change variable name and add new response element" }, { "additionalData": "", "committer": { "date": "1508280542 -0800", "name": "Li Juan", "email": "li_juan@example.com" }, "author": { "date": "1508280542 -0800", "name": "Li Juan", "email": "li_juan@example.com" }, "commitId": "4c925148EXAMPLE", "treeId": "1f330709EXAMPLE", "parents": [ "317f8570EXAMPLE" ], "message": "Added new class" } }For more information, see View Commit Details
in the Amazon CodeCommit User Guide. -
For API details, see BatchGetCommits
in Amazon CLI Command Reference.
-
The following code example shows how to use batch-get-repositories.
- Amazon CLI
-
To view details about multiple repositories
This example shows details about multiple Amazon CodeCommit repositories.
aws codecommit batch-get-repositories \ --repository-namesMyDemoRepoMyOtherDemoRepoOutput:
{ "repositoriesNotFound": [], "repositories": [ { "creationDate": 1429203623.625, "defaultBranch": "main", "repositoryName": "MyDemoRepo", "cloneUrlSsh": "ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo", "lastModifiedDate": 1430783812.0869999, "repositoryDescription": "My demonstration repository", "cloneUrlHttp": "https://codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo", "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE", "Arn": "arn:aws:codecommit:us-east-2:111111111111:MyDemoRepo" "accountId": "111111111111" }, { "creationDate": 1429203623.627, "defaultBranch": "main", "repositoryName": "MyOtherDemoRepo", "cloneUrlSsh": "ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyOtherDemoRepo", "lastModifiedDate": 1430783812.0889999, "repositoryDescription": "My other demonstration repository", "cloneUrlHttp": "https://codecommit.us-east-2.amazonaws.com/v1/repos/MyOtherDemoRepo", "repositoryId": "cfc29ac4-b0cb-44dc-9990-f6f51EXAMPLE", "Arn": "arn:aws:codecommit:us-east-2:111111111111:MyOtherDemoRepo" "accountId": "111111111111" } ], "repositoriesNotFound": [] }-
For API details, see BatchGetRepositories
in Amazon CLI Command Reference.
-
The following code example shows how to use create-approval-rule-template.
- Amazon CLI
-
To create an approval rule template
The following
create-approval-rule-templateexample creates an approval rule template named2-approver-rule-for-main ``. The template requires two users who assume the role of ``CodeCommitReviewto approve any pull request before it can be merged to themainbranch.aws codecommit create-approval-rule-template \ --approval-rule-template-name2-approver-rule-for-main\ --approval-rule-template-description"Requires two developers from the team to approve the pull request if the destination branch is main"\ --approval-rule-template-content "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}"Output:
{ "approvalRuleTemplate": { "approvalRuleTemplateName": "2-approver-rule-for-main", "creationDate": 1571356106.936, "approvalRuleTemplateId": "dd8b17fe-EXAMPLE", "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "approvalRuleTemplateDescription": "Requires two developers from the team to approve the pull request if the destination branch is main", "lastModifiedDate": 1571356106.936, "ruleContentSha256": "4711b576EXAMPLE" } }For more information, see Create an Approval Rule Template
in the Amazon CodeCommit User Guide. -
For API details, see CreateApprovalRuleTemplate
in Amazon CLI Command Reference.
-
The following code example shows how to use create-branch.
- Amazon CLI
-
To create a branch
This example creates a branch in an Amazon CodeCommit repository. This command produces output only if there are errors.
Command:
aws codecommit create-branch --repository-nameMyDemoRepo--branch-nameMyNewBranch--commit-id317f8570EXAMPLEOutput:
None.-
For API details, see CreateBranch
in Amazon CLI Command Reference.
-
The following code example shows how to use create-commit.
- Amazon CLI
-
To create a commit
The following
create-commitexample demonstrates how to create an initial commit for a repository that adds areadme.mdfile to a repository namedMyDemoRepoin themainbranch.aws codecommit create-commit \ --repository-nameMyDemoRepo\ --branch-namemain\ --put-files"filePath=readme.md,fileContent='Welcome to our team repository.'"Output:
{ "filesAdded": [ { "blobId": "5e1c309d-EXAMPLE", "absolutePath": "readme.md", "fileMode": "NORMAL" } ], "commitId": "4df8b524-EXAMPLE", "treeId": "55b57003-EXAMPLE", "filesDeleted": [], "filesUpdated": [] }For more information, see Create a Commit in Amazon CodeCommit
in the Amazon CodeCommit User Guide. -
For API details, see CreateCommit
in Amazon CLI Command Reference.
-
The following code example shows how to use create-pull-request-approval-rule.
- Amazon CLI
-
To create an approval rule for a pull request
The following
create-pull-request-approval-ruleexample creates an approval rule namedRequire two approved approversfor the specified pull request. The rule specifies that two approvals are required from an approval pool. The pool includes all users who access CodeCommit by assuming the role ofCodeCommitReviewin the123456789012Amazon account. It also includes either an IAM user or federated user namedNikhil_Jayashankarfrom the same Amazon account.aws codecommit create-pull-request-approval-rule \ --approval-rule-name"Require two approved approvers"\ --approval-rule-content "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"CodeCommitApprovers:123456789012:Nikhil_Jayashankar\", \"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}"Output:
{ "approvalRule": { "approvalRuleName": "Require two approved approvers", "lastModifiedDate": 1570752871.932, "ruleContentSha256": "7c44e6ebEXAMPLE", "creationDate": 1570752871.932, "approvalRuleId": "aac33506-EXAMPLE", "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"CodeCommitApprovers:123456789012:Nikhil_Jayashankar\", \"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major" } }For more information, see Create an Approval Rule
in the Amazon CodeCommit User Guide. -
For API details, see CreatePullRequestApprovalRule
in Amazon CLI Command Reference.
-
The following code example shows how to use create-pull-request.
- Amazon CLI
-
To create a pull request
The following
create-pull-requestexample creates a pull request named 'Pronunciation difficulty analyzer' with a description of 'Please review these changes by Tuesday' that targets the 'jane-branch' source branch and is to be merged to the default branch 'main' in an Amazon CodeCommit repository named 'MyDemoRepo'.aws codecommit create-pull-request \ --title"My Pull Request"\ --description"Please review these changes by Tuesday"\ --client-request-token123Example\ --targetsrepositoryName=MyDemoRepo,sourceReference=MyNewBranchOutput:
{ "pullRequest": { "approvalRules": [ { "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "approvalRuleId": "dd8b17fe-EXAMPLE", "approvalRuleName": "2-approver-rule-for-main", "creationDate": 1571356106.936, "lastModifiedDate": 571356106.936, "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "originApprovalRuleTemplate": { "approvalRuleTemplateId": "dd3d22fe-EXAMPLE", "approvalRuleTemplateName": "2-approver-rule-for-main" }, "ruleContentSha256": "4711b576EXAMPLE" } ], "authorArn": "arn:aws:iam::111111111111:user/Jane_Doe", "description": "Please review these changes by Tuesday", "title": "Pronunciation difficulty analyzer", "pullRequestTargets": [ { "destinationCommit": "5d036259EXAMPLE", "destinationReference": "refs/heads/main", "repositoryName": "MyDemoRepo", "sourceCommit": "317f8570EXAMPLE", "sourceReference": "refs/heads/jane-branch", "mergeMetadata": { "isMerged": false } } ], "lastActivityDate": 1508962823.285, "pullRequestId": "42", "clientRequestToken": "123Example", "pullRequestStatus": "OPEN", "creationDate": 1508962823.285 } }-
For API details, see CreatePullRequest
in Amazon CLI Command Reference.
-
The following code example shows how to use create-repository.
- Amazon CLI
-
To create a repository
This example creates a repository and associates it with the user's Amazon account.
Command:
aws codecommit create-repository --repository-nameMyDemoRepo--repository-description"My demonstration repository"Output:
{ "repositoryMetadata": { "repositoryName": "MyDemoRepo", "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo", "lastModifiedDate": 1444766838.027, "repositoryDescription": "My demonstration repository", "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo", "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE", "Arn": "arn:aws:codecommit:us-east-1:111111111111EXAMPLE:MyDemoRepo", "accountId": "111111111111" } }-
For API details, see CreateRepository
in Amazon CLI Command Reference.
-
The following code example shows how to use create-unreferenced-merge-commit.
- Amazon CLI
-
To create an unreferenced commit that represents the result of merging two commit specifiers
The following
create-unreferenced-merge-commitexample creates a commit that represents the results of a merge between a source branch namedbugfix-1234with a destination branch namedmainusing the THREE_WAY_MERGE strategy in a repository namedMyDemoRepo.aws codecommit create-unreferenced-merge-commit \ --source-commit-specifierbugfix-1234\ --destination-commit-specifiermain\ --merge-optionTHREE_WAY_MERGE\ --repository-nameMyDemoRepo\ --name"Maria Garcia"\ --email"maria_garcia@example.com"\ --commit-message"Testing the results of this merge."Output:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }For more information, see Resolve Conflicts in a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see CreateUnreferencedMergeCommit
in Amazon CLI Command Reference.
-
The following code example shows how to use credential-helper.
- Amazon CLI
-
To set up the credential helper included in the Amazon CLI with Amazon CodeCommit
The
credential-helperutility is not designed to be called directly from the Amazon CLI. Instead it is intended to be used as a parameter with thegit configcommand to set up your local computer. It enables Git to use HTTPS and a cryptographically signed version of your IAM user credentials or Amazon EC2 instance role whenever Git needs to authenticate with Amazon to interact with CodeCommit repositories.git config --global credential.helper '!aws codecommit credential-helper $@' git config --global credential.UseHttpPath trueOutput:
[credential] helper = !aws codecommit credential-helper $@ UseHttpPath = trueFor more information, see Setting up for Amazon CodeCommit Using Other Methods in the Amazon CodeCommit User Guide. Review the content carefully, and then follow the procedures in one of the following topics: For HTTPS Connections on Linux, macOS, or Unix or For HTTPS Connections on Windows in the Amazon CodeCommit User Guide.
-
For API details, see CredentialHelper
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-approval-rule-template.
- Amazon CLI
-
To delete an approval rule template
The following
delete-approval-rule-templateexample deletes the specified approval rule template.aws codecommit delete-approval-rule-template \ --approval-rule-template-name1-approver-for-all-pull-requestsOutput:
{ "approvalRuleTemplateId": "41de97b7-EXAMPLE" }For more information, see Delete an Approval Rule Template
in the Amazon CodeCommit User Guide. -
For API details, see DeleteApprovalRuleTemplate
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-branch.
- Amazon CLI
-
To delete a branch
This example shows how to delete a branch in an Amazon CodeCommit repository.
Command:
aws codecommit delete-branch --repository-nameMyDemoRepo--branch-nameMyNewBranchOutput:
{ "branch": { "commitId": "317f8570EXAMPLE", "branchName": "MyNewBranch" } }-
For API details, see DeleteBranch
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-comment-content.
- Amazon CLI
-
To delete the content of a comment
You can only delete the content of a comment if you created the comment. This example demonstrates how to delete the content of a comment with the system-generated ID of
ff30b348EXAMPLEb9aa670f.aws codecommit delete-comment-content \ --comment-idff30b348EXAMPLEb9aa670fOutput:
{ "comment": { "creationDate": 1508369768.142, "deleted": true, "lastModifiedDate": 1508369842.278, "clientRequestToken": "123Example", "commentId": "ff30b348EXAMPLEb9aa670f", "authorArn": "arn:aws:iam::111111111111:user/Li_Juan", "callerReactions": [], "reactionCounts": { "CLAP" : 1 } } }-
For API details, see DeleteCommentContent
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-file.
- Amazon CLI
-
To delete a file
The following
delete-fileexample demonstrates how to delete a file namedREADME.mdfrom a branch namedmainwith a most recent commit ID ofc5709475EXAMPLEin a repository namedMyDemoRepo.aws codecommit delete-file \ --repository-nameMyDemoRepo\ --branch-namemain\ --file-pathREADME.md\ --parent-commit-idc5709475EXAMPLEOutput:
{ "blobId":"559b44fEXAMPLE", "commitId":"353cf655EXAMPLE", "filePath":"README.md", "treeId":"6bc824cEXAMPLE" }For more information, see Edit or Delete a File in Amazon CodeCommit
in the Amazon CodeCommit API Reference guide. -
For API details, see DeleteFile
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-pull-request-approval-rule.
- Amazon CLI
-
To delete an approval rule for a pull request
The following
delete-pull-request-approval-ruleexample deletes the approval rule namedMy Approval Rulefor the specified pull request.aws codecommit delete-pull-request-approval-rule \ --approval-rule-name"My Approval Rule"\ --pull-request-id15Output:
{ "approvalRuleId": "077d8e8a8-EXAMPLE" }For more information, see Edit or Delete an Approval Rule
in the Amazon CodeCommit User Guide. -
For API details, see DeletePullRequestApprovalRule
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-repository.
- Amazon CLI
-
To delete a repository
This example shows how to delete an Amazon CodeCommit repository.
Command:
aws codecommit delete-repository --repository-nameMyDemoRepoOutput:
{ "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE" }-
For API details, see DeleteRepository
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-merge-conflicts.
- Amazon CLI
-
To get detailed information about merge conflicts
The following
describe-merge-conflictsexample determines the merge conflicts for a file namedreadme.mdin the specified source branch and destination branch using the THREE_WAY_MERGE strategy.aws codecommit describe-merge-conflicts \ --source-commit-specifierfeature-randomizationfeature\ --destination-commit-specifiermain\ --merge-optionTHREE_WAY_MERGE\ --file-pathreadme.md\ --repository-nameMyDemoRepoOutput:
{ "conflictMetadata": { "filePath": "readme.md", "fileSizes": { "source": 139, "destination": 230, "base": 85 }, "fileModes": { "source": "NORMAL", "destination": "NORMAL", "base": "NORMAL" }, "objectTypes": { "source": "FILE", "destination": "FILE", "base": "FILE" }, "numberOfConflicts": 1, "isBinaryFile": { "source": false, "destination": false, "base": false }, "contentConflict": true, "fileModeConflict": false, "objectTypeConflict": false, "mergeOperations": { "source": "M", "destination": "M" } }, "mergeHunks": [ { "isConflict": true, "source": { "startLine": 0, "endLine": 3, "hunkContent": "VGhpcyBpEXAMPLE=" }, "destination": { "startLine": 0, "endLine": 1, "hunkContent": "VXNlIHRoEXAMPLE=" } } ], "destinationCommitId": "86958e0aEXAMPLE", "sourceCommitId": "6ccd57fdEXAMPLE", "baseCommitId": "767b69580EXAMPLE" }For more information, see Resolve Conflicts in a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see DescribeMergeConflicts
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-pull-request-events.
- Amazon CLI
-
To view events in a pull request
The following
describe-pull-request-eventsexample retrieves the events for a pull request with the ID of '8'.aws codecommit describe-pull-request-events --pull-request-id8Output:
{ "pullRequestEvents": [ { "pullRequestId": "8", "pullRequestEventType": "PULL_REQUEST_CREATED", "eventDate": 1510341779.53, "actor": "arn:aws:iam::111111111111:user/Zhang_Wei" }, { "pullRequestStatusChangedEventMetadata": { "pullRequestStatus": "CLOSED" }, "pullRequestId": "8", "pullRequestEventType": "PULL_REQUEST_STATUS_CHANGED", "eventDate": 1510341930.72, "actor": "arn:aws:iam::111111111111:user/Jane_Doe" } ] }-
For API details, see DescribePullRequestEvents
in Amazon CLI Command Reference.
-
The following code example shows how to use disassociate-approval-rule-template-from-repository.
- Amazon CLI
-
To disassociate an approval rule template from a repository
The following
disassociate-approval-rule-template-from-repositoryexample disassociates the specified approval rule template from a repository namedMyDemoRepo.aws codecommit disassociate-approval-rule-template-from-repository \ --repository-nameMyDemoRepo\ --approval-rule-template-name1-approver-rule-for-all-pull-requestsThis command produces no output.
For more information, see Disassociate an Approval Rule Template
in the Amazon CodeCommit User Guide. -
For API details, see DisassociateApprovalRuleTemplateFromRepository
in Amazon CLI Command Reference.
-
The following code example shows how to use evaluate-pull-request-approval-rules.
- Amazon CLI
-
To evaluate whether a pull request has all of its approval rules satisfied
The following
evaluate-pull-request-approval-rulesexample evaluates the state of approval rules on the specified pull request. In this example, an approval rule has not been satisfied for the pull request, so the output of the command shows anapprovedvalue offalse.aws codecommit evaluate-pull-request-approval-rules \ --pull-request-id27\ --revision-id9f29d167EXAMPLEOutput:
{ "evaluation": { "approved": false, "approvalRulesNotSatisfied": [ "Require two approved approvers" ], "overridden": false, "approvalRulesSatisfied": [] } }For more information, see Merge a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see EvaluatePullRequestApprovalRules
in Amazon CLI Command Reference.
-
The following code example shows how to use get-approval-rule-template.
- Amazon CLI
-
To get the content of an approval rule template
The following
get-approval-rule-templateexample gets the content of an approval rule template named1-approver-rule-for-all-pull-requests.aws codecommit get-approval-rule-template \ --approval-rule-template-name1-approver-rule-for-all-pull-requestsOutput:
{ "approvalRuleTemplate": { "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "ruleContentSha256": "621181bbEXAMPLE", "lastModifiedDate": 1571356106.936, "creationDate": 1571356106.936, "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests", "lastModifiedUser": "arn:aws:iam::123456789012:user/Li_Juan", "approvalRuleTemplateId": "a29abb15-EXAMPLE", "approvalRuleTemplateDescription": "All pull requests must be approved by one developer on the team." } }For more information, see Manage Approval Rule Templates
in the Amazon CodeCommit User Guide. -
For API details, see GetApprovalRuleTemplate
in Amazon CLI Command Reference.
-
The following code example shows how to use get-blob.
- Amazon CLI
-
To view information about a Git blob object
The following
get-blobexample retrieves information about a Git blob with the ID of '2eb4af3bEXAMPLE' in an Amazon CodeCommit repository named 'MyDemoRepo'.aws codecommit get-blob --repository-nameMyDemoRepo--blob-id2eb4af3bEXAMPLEOutput:
{ "content": "QSBCaW5hcnkgTGFyToEXAMPLE=" }-
For API details, see GetBlob
in Amazon CLI Command Reference.
-
The following code example shows how to use get-branch.
- Amazon CLI
-
To get information about a branch
This example gets information about a branch in an Amazon CodeCommit repository.
Command:
aws codecommit get-branch --repository-nameMyDemoRepo--branch-nameMyNewBranchOutput:
{ "BranchInfo": { "commitID": "317f8570EXAMPLE", "branchName": "MyNewBranch" } }-
For API details, see GetBranch
in Amazon CLI Command Reference.
-
The following code example shows how to use get-comment-reactions.
- Amazon CLI
-
To view emoji reactions to a comment
The following
get-comment-reactionsexample lists all emoji reactions to a comment with the ID ofabcd1234EXAMPLEb5678efgh. If the font for your shell supports displaying Emoji Version 1.0, then in the output foremojithe emoji is displayed.aws codecommit get-comment-reactions \ --comment-idabcd1234EXAMPLEb5678efghOutput:
{ "reactionsForComment": { [ { "reaction": { "emoji:"??", "shortCode": "thumbsup", "unicode": "U+1F44D" }, "users": [ "arn:aws:iam::123456789012:user/Li_Juan", "arn:aws:iam::123456789012:user/Mary_Major", "arn:aws:iam::123456789012:user/Jorge_Souza" ] }, { "reaction": { "emoji": "??", "shortCode": "thumbsdown", "unicode": "U+1F44E" }, "users": [ "arn:aws:iam::123456789012:user/Nikhil_Jayashankar" ] }, { "reaction": { "emoji": "??", "shortCode": "confused", "unicode": "U+1F615" }, "users": [ "arn:aws:iam::123456789012:user/Saanvi_Sarkar" ] } ] } }For more information, see Comment on a commit in Amazon CodeCommit
in the Amazon CodeCommit User Guide. -
For API details, see GetCommentReactions
in Amazon CLI Command Reference.
-
The following code example shows how to use get-comment.
- Amazon CLI
-
To view details of a comment
This example demonstrates how to view details of a comment with the system-generated comment ID of
ff30b348EXAMPLEb9aa670f.aws codecommit get-comment \ --comment-idff30b348EXAMPLEb9aa670fOutput:
{ "comment": { "authorArn": "arn:aws:iam::111111111111:user/Li_Juan", "clientRequestToken": "123Example", "commentId": "ff30b348EXAMPLEb9aa670f", "content": "Whoops - I meant to add this comment to the line, but I don't see how to delete it.", "creationDate": 1508369768.142, "deleted": false, "commentId": "", "lastModifiedDate": 1508369842.278, "callerReactions": [], "reactionCounts": { "SMILE" : 6, "THUMBSUP" : 1 } } }-
For API details, see GetComment
in Amazon CLI Command Reference.
-
The following code example shows how to use get-comments-for-compared-commit.
- Amazon CLI
-
To view comments on a commit
This example demonstrates how to view view comments made on the comparison between two commits in a repository named
MyDemoRepo.aws codecommit get-comments-for-compared-commit \ --repository-nameMyDemoRepo\ --before-commit-ID6e147360EXAMPLE\ --after-commit-id317f8570EXAMPLEOutput:
{ "commentsForComparedCommitData": [ { "afterBlobId": "1f330709EXAMPLE", "afterCommitId": "317f8570EXAMPLE", "beforeBlobId": "80906a4cEXAMPLE", "beforeCommitId": "6e147360EXAMPLE", "comments": [ { "authorArn": "arn:aws:iam::111111111111:user/Li_Juan", "clientRequestToken": "123Example", "commentId": "ff30b348EXAMPLEb9aa670f", "content": "Whoops - I meant to add this comment to the line, not the file, but I don't see how to delete it.", "creationDate": 1508369768.142, "deleted": false, "CommentId": "123abc-EXAMPLE", "lastModifiedDate": 1508369842.278, "callerReactions": [], "reactionCounts": { "SMILE" : 6, "THUMBSUP" : 1 } }, { "authorArn": "arn:aws:iam::111111111111:user/Li_Juan", "clientRequestToken": "123Example", "commentId": "553b509bEXAMPLE56198325", "content": "Can you add a test case for this?", "creationDate": 1508369612.240, "deleted": false, "commentId": "456def-EXAMPLE", "lastModifiedDate": 1508369612.240, "callerReactions": [], "reactionCounts": { "THUMBSUP" : 2 } } ], "location": { "filePath": "cl_sample.js", "filePosition": 1232, "relativeFileVersion": "after" }, "repositoryName": "MyDemoRepo" } ], "nextToken": "exampleToken" }-
For API details, see GetCommentsForComparedCommit
in Amazon CLI Command Reference.
-
The following code example shows how to use get-comments-for-pull-request.
- Amazon CLI
-
To view comments for a pull request
This example demonstrates how to view comments for a pull request in a repository named
MyDemoRepo.aws codecommit get-comments-for-pull-request \ --repository-nameMyDemoRepo\ --before-commit-ID317f8570EXAMPLE\ --after-commit-id5d036259EXAMPLEOutput:
{ "commentsForPullRequestData": [ { "afterBlobId": "1f330709EXAMPLE", "afterCommitId": "5d036259EXAMPLE", "beforeBlobId": "80906a4cEXAMPLE", "beforeCommitId": "317f8570EXAMPLE", "comments": [ { "authorArn": "arn:aws:iam::111111111111:user/Saanvi_Sarkar", "clientRequestToken": "", "commentId": "abcd1234EXAMPLEb5678efgh", "content": "These don't appear to be used anywhere. Can we remove them?", "creationDate": 1508369622.123, "deleted": false, "lastModifiedDate": 1508369622.123, "callerReactions": [], "reactionCounts": { "THUMBSUP" : 6, "CONFUSED" : 1 } }, { "authorArn": "arn:aws:iam::111111111111:user/Li_Juan", "clientRequestToken": "", "commentId": "442b498bEXAMPLE5756813", "content": "Good catch. I'll remove them.", "creationDate": 1508369829.104, "deleted": false, "lastModifiedDate": 150836912.273, "callerReactions": ["THUMBSUP"] "reactionCounts": { "THUMBSUP" : 14 } } ], "location": { "filePath": "ahs_count.py", "filePosition": 367, "relativeFileVersion": "AFTER" }, "repositoryName": "MyDemoRepo", "pullRequestId": "42" } ], "nextToken": "exampleToken" }-
For API details, see GetCommentsForPullRequest
in Amazon CLI Command Reference.
-
The following code example shows how to use get-commit.
- Amazon CLI
-
To view information about a commit in a repository
This example shows details about a commit with the system-generated ID of '7e9fd3091thisisanexamplethisisanexample1' in an Amazon CodeCommit repository named 'MyDemoRepo'.
Command:
aws codecommit get-commit --repository-nameMyDemoRepo--commit-id7e9fd3091thisisanexamplethisisanexample1Output:
{ "commit": { "additionalData": "", "committer": { "date": "1484167798 -0800", "name": "Mary Major", "email": "mary_major@example.com" }, "author": { "date": "1484167798 -0800", "name": "Mary Major", "email": "mary_major@example.com" }, "treeId": "347a3408thisisanexampletreeidexample", "parents": [ "7aa87a031thisisanexamplethisisanexample1" ], "message": "Fix incorrect variable name" } }-
For API details, see GetCommit
in Amazon CLI Command Reference.
-
The following code example shows how to use get-differences.
- Amazon CLI
-
To get information about differences for a commit specifier in a repository
This example shows view metadata information about changes between two commit specifiers (branch, tag, HEAD, or other fully qualified references, such as commit IDs) in a renamed folder in Amazon CodeCommit repository named MyDemoRepo. The example includes several options that are not required, including --before-commit-specifier, --before-path, and --after-path, in order to more fully illustrate how you can use these options to limit the results. The response includes file mode permissions.
Command:
aws codecommit get-differences --repository-nameMyDemoRepo--before-commit-specifier955bba12thisisanexamplethisisanexample--after-commit-specifier14a95463thisisanexamplethisisanexample--before-pathtmp/example-folder--after-pathtmp/renamed-folderOutput:
{ "differences": [ { "afterBlob": { "path": "blob.txt", "blobId": "2eb4af3b1thisisanexamplethisisanexample1", "mode": "100644" }, "changeType": "M", "beforeBlob": { "path": "blob.txt", "blobId": "bf7fcf281thisisanexamplethisisanexample1", "mode": "100644" } } ] }-
For API details, see GetDifferences
in Amazon CLI Command Reference.
-
The following code example shows how to use get-file.
- Amazon CLI
-
To get the base-64 encoded contents of a file in an Amazon CodeCommit repository
The following
get-fileexample demonstrates how to get the base-64 encoded contents of a file namedREADME.mdfrom a branch namedmainin a repository namedMyDemoRepo.aws codecommit get-file \ --repository-nameMyDemoRepo\ --commit-specifiermain\ --file-pathREADME.mdOutput:
{ "blobId":"559b44fEXAMPLE", "commitId":"c5709475EXAMPLE", "fileContent":"IyBQaHVzEXAMPLE", "filePath":"README.md", "fileMode":"NORMAL", "fileSize":1563 }For more information, see GetFile
in the Amazon CodeCommit API Reference guide. -
For API details, see GetFile
in Amazon CLI Command Reference.
-
The following code example shows how to use get-folder.
- Amazon CLI
-
To get the contents of a folder in an Amazon CodeCommit repository
The following
get-folderexample demonstrates how to get the contents of a top-level folder from a repository namedMyDemoRepo.aws codecommit get-folder --repository-nameMyDemoRepo--folder-path ""Output:
{ "commitId":"c5709475EXAMPLE", "files":[ { "absolutePath":".gitignore", "blobId":"74094e8bEXAMPLE", "fileMode":"NORMAL", "relativePath":".gitignore" }, { "absolutePath":"Gemfile", "blobId":"9ceb72f6EXAMPLE", "fileMode":"NORMAL", "relativePath":"Gemfile" }, { "absolutePath":"Gemfile.lock", "blobId":"795c4a2aEXAMPLE", "fileMode":"NORMAL", "relativePath":"Gemfile.lock" }, { "absolutePath":"LICENSE.txt", "blobId":"0c7932c8EXAMPLE", "fileMode":"NORMAL", "relativePath":"LICENSE.txt" }, { "absolutePath":"README.md", "blobId":"559b44feEXAMPLE", "fileMode":"NORMAL", "relativePath":"README.md" } ], "folderPath":"", "subFolders":[ { "absolutePath":"public", "relativePath":"public", "treeId":"d5e92ae3aEXAMPLE" }, { "absolutePath":"tmp", "relativePath":"tmp", "treeId":"d564d0bcEXAMPLE" } ], "subModules":[], "symbolicLinks":[], "treeId":"7b3c4dadEXAMPLE" }For more information, see GetFolder in the Amazon CodeCommit API Reference guide.
-
For API details, see GetFolder
in Amazon CLI Command Reference.
-
The following code example shows how to use get-merge-commit.
- Amazon CLI
-
To get detailed information about a merge commit
The following
get-merge-commitexample displays details about a merge commit for the source branch namedbugfix-bug1234with a destination branch namedmainin a repository namedMyDemoRepo.aws codecommit get-merge-commit \ --source-commit-specifierbugfix-bug1234\ --destination-commit-specifiermain\ --repository-nameMyDemoRepoOutput:
{ "sourceCommitId": "c5709475EXAMPLE", "destinationCommitId": "317f8570EXAMPLE", "baseCommitId": "fb12a539EXAMPLE", "mergeCommitId": "ffc4d608eEXAMPLE" }For more information, see View Commit Details
in the Amazon CodeCommit User Guide. -
For API details, see GetMergeCommit
in Amazon CLI Command Reference.
-
The following code example shows how to use get-merge-conflicts.
- Amazon CLI
-
To view whether there are any merge conflicts for a pull request
The following
get-merge-conflictsexample displays whether there are any merge conflicts between the tip of a source branch namedfeature-randomizationfeatureand a destination branch named 'main' in a repository namedMyDemoRepo.aws codecommit get-merge-conflicts \ --repository-nameMyDemoRepo\ --source-commit-specifierfeature-randomizationfeature\ --destination-commit-specifiermain\ --merge-optionTHREE_WAY_MERGEOutput:
{ "mergeable": false, "destinationCommitId": "86958e0aEXAMPLE", "sourceCommitId": "6ccd57fdEXAMPLE", "baseCommitId": "767b6958EXAMPLE", "conflictMetadataList": [ { "filePath": "readme.md", "fileSizes": { "source": 139, "destination": 230, "base": 85 }, "fileModes": { "source": "NORMAL", "destination": "NORMAL", "base": "NORMAL" }, "objectTypes": { "source": "FILE", "destination": "FILE", "base": "FILE" }, "numberOfConflicts": 1, "isBinaryFile": { "source": false, "destination": false, "base": false }, "contentConflict": true, "fileModeConflict": false, "objectTypeConflict": false, "mergeOperations": { "source": "M", "destination": "M" } } ] }-
For API details, see GetMergeConflicts
in Amazon CLI Command Reference.
-
The following code example shows how to use get-merge-options.
- Amazon CLI
-
To get information about the merge options available for merging two specified branches
The following
get-merge-optionsexample determines the merge options available for merging a source branch namedbugfix-bug1234with a destination branch namedmainin a repository namedMyDemoRepo.aws codecommit get-merge-options \ --source-commit-specifierbugfix-bug1234\ --destination-commit-specifiermain\ --repository-nameMyDemoRepoOutput:
{ "mergeOptions": [ "FAST_FORWARD_MERGE", "SQUASH_MERGE", "THREE_WAY_MERGE" ], "sourceCommitId": "18059494EXAMPLE", "destinationCommitId": "ffd3311dEXAMPLE", "baseCommitId": "ffd3311dEXAMPLE" }For more information, see Resolve Conflicts in a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see GetMergeOptions
in Amazon CLI Command Reference.
-
The following code example shows how to use get-pull-request-approval-states.
- Amazon CLI
-
To view approvals on a pull request
The following
get-pull-request-approval-statesexample returns approvals for the specified pull request.aws codecommit get-pull-request-approval-states \ --pull-request-id8\ --revision-id9f29d167EXAMPLEOutput:
{ "approvals": [ { "userArn": "arn:aws:iam::123456789012:user/Mary_Major", "approvalState": "APPROVE" } ] }For more information, see View Pull Requests
in the Amazon CodeCommit User Guide. -
For API details, see GetPullRequestApprovalStates
in Amazon CLI Command Reference.
-
The following code example shows how to use get-pull-request-override-state.
- Amazon CLI
-
To get information about the override status of a pull request
The following
get-pull-request-override-stateexample returns the override state for the specified pull request. In this example, the approval rules for the pull request were overridden by a user named Mary Major, so the output returns a value oftrue.:aws codecommit get-pull-request-override-state \ --pull-request-id34\ --revision-id9f29d167EXAMPLEOutput:
{ "overridden": true, "overrider": "arn:aws:iam::123456789012:user/Mary_Major" }For more information, see Override Approval Rules on a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see GetPullRequestOverrideState
in Amazon CLI Command Reference.
-
The following code example shows how to use get-pull-request.
- Amazon CLI
-
To view details of a pull request
This example demonstrates how to view information about a pull request with the ID of
27.aws codecommit get-pull-request \ --pull-request-id27Output:
{ "pullRequest": { "approvalRules": [ { "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "approvalRuleId": "dd8b17fe-EXAMPLE", "approvalRuleName": "2-approver-rule-for-main", "creationDate": 1571356106.936, "lastModifiedDate": 571356106.936, "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "ruleContentSha256": "4711b576EXAMPLE" } ], "lastActivityDate": 1562619583.565, "pullRequestTargets": [ { "sourceCommit": "ca45e279EXAMPLE", "sourceReference": "refs/heads/bugfix-1234", "mergeBase": "a99f5ddbEXAMPLE", "destinationReference": "refs/heads/main", "mergeMetadata": { "isMerged": false }, "destinationCommit": "2abfc6beEXAMPLE", "repositoryName": "MyDemoRepo" } ], "revisionId": "e47def21EXAMPLE", "title": "Quick fix for bug 1234", "authorArn": "arn:aws:iam::123456789012:user/Nikhil_Jayashankar", "clientRequestToken": "d8d7612e-EXAMPLE", "creationDate": 1562619583.565, "pullRequestId": "27", "pullRequestStatus": "OPEN" } }-
For API details, see GetPullRequest
in Amazon CLI Command Reference.
-
The following code example shows how to use get-repository-triggers.
- Amazon CLI
-
To get information about triggers in a repository
This example shows details about triggers configured for an Amazon CodeCommit repository named
MyDemoRepo.aws codecommit get-repository-triggers \ --repository-nameMyDemoRepoOutput:
{ "configurationId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE", "triggers": [ { "destinationArn": "arn:aws:sns:us-east-1:111111111111:MyCodeCommitTopic", "branches": [ "main", "preprod" ], "name": "MyFirstTrigger", "customData": "", "events": [ "all" ] }, { "destinationArn": "arn:aws:lambda:us-east-1:111111111111:function:MyCodeCommitPythonFunction", "branches": [], "name": "MySecondTrigger", "customData": "EXAMPLE", "events": [ "all" ] } ] }-
For API details, see GetRepositoryTriggers
in Amazon CLI Command Reference.
-
The following code example shows how to use get-repository.
- Amazon CLI
-
To get information about a repository
This example shows details about an Amazon CodeCommit repository.
aws codecommit get-repository \ --repository-nameMyDemoRepoOutput:
{ "repositoryMetadata": { "creationDate": 1429203623.625, "defaultBranch": "main", "repositoryName": "MyDemoRepo", "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/v1/repos/MyDemoRepo", "lastModifiedDate": 1430783812.0869999, "repositoryDescription": "My demonstration repository", "cloneUrlHttp": "https://codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo", "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE", "Arn": "arn:aws:codecommit:us-east-1:80398EXAMPLE:MyDemoRepo "accountId": "111111111111" } }-
For API details, see GetRepository
in Amazon CLI Command Reference.
-
The following code example shows how to use list-approval-rule-templates.
- Amazon CLI
-
To list all approval rule templates in an Amazon Region
The following
list-approval-rule-templatesexample lists all approval rule templates in the specified Region. If no Amazon Region is specified as a parameter, the command returns approval rule templates for the region specified in the Amazon CLI profile used to run the command.aws codecommit list-approval-rule-templates \ --regionus-east-2Output:
{ "approvalRuleTemplateNames": [ "2-approver-rule-for-main", "1-approver-rule-for-all-pull-requests" ] }For more information, see Manage Approval Rule Templates
in the Amazon CodeCommit User Guide. -
For API details, see ListApprovalRuleTemplates
in Amazon CLI Command Reference.
-
The following code example shows how to use list-associated-approval-rule-templates-for-repository.
- Amazon CLI
-
To list all templates associated with a repository
The following
list-associated-approval-rule-templates-for-repositoryexample lists all approval rule templates associated with a repository namedMyDemoRepo.aws codecommit list-associated-approval-rule-templates-for-repository \ --repository-nameMyDemoRepoOutput:
{ "approvalRuleTemplateNames": [ "2-approver-rule-for-main", "1-approver-rule-for-all-pull-requests" ] }For more information, see Manage Approval Rule Templates
in the Amazon CodeCommit User Guide. -
For API details, see ListAssociatedApprovalRuleTemplatesForRepository
in Amazon CLI Command Reference.
-
The following code example shows how to use list-branches.
- Amazon CLI
-
To view a list of branch names
This example lists all branch names in an Amazon CodeCommit repository.
aws codecommit list-branches \ --repository-nameMyDemoRepoOutput:
{ "branches": [ "MyNewBranch", "main" ] }-
For API details, see ListBranches
in Amazon CLI Command Reference.
-
The following code example shows how to use list-pull-requests.
- Amazon CLI
-
To view a list of pull requests in a repository
This example demonstrates how to list pull requests created by an IAM user with the ARN 'arn:aws:iam::111111111111:user/Li_Juan' and the status of 'CLOSED' in an Amazon CodeCommit repository named 'MyDemoRepo':
aws codecommit list-pull-requests --author-arnarn:aws:iam::111111111111:user/Li_Juan--pull-request-statusCLOSED--repository-nameMyDemoRepoOutput:
{ "nextToken": "", "pullRequestIds": ["2","12","16","22","23","35","30","39","47"] }-
For API details, see ListPullRequests
in Amazon CLI Command Reference.
-
The following code example shows how to use list-repositories-for-approval-rule-template.
- Amazon CLI
-
To list all repositories associated with a template
The following
list-repositories-for-approval-rule-templateexample lists all repositories associated with the specified approval rule template.aws codecommit list-repositories-for-approval-rule-template \ --approval-rule-template-name2-approver-rule-for-mainOutput:
{ "repositoryNames": [ "MyDemoRepo", "MyClonedRepo" ] }For more information, see Manage Approval Rule Templates
in the Amazon CodeCommit User Guide. -
For API details, see ListRepositoriesForApprovalRuleTemplate
in Amazon CLI Command Reference.
-
The following code example shows how to use list-repositories.
- Amazon CLI
-
To view a list of repositories
This example lists all Amazon CodeCommit repositories associated with the user's Amazon account.
Command:
aws codecommit list-repositoriesOutput:
{ "repositories": [ { "repositoryName": "MyDemoRepo" "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE", }, { "repositoryName": "MyOtherDemoRepo" "repositoryId": "cfc29ac4-b0cb-44dc-9990-f6f51EXAMPLE" } ] }-
For API details, see ListRepositories
in Amazon CLI Command Reference.
-
The following code example shows how to use list-tags-for-resource.
- Amazon CLI
-
To view the Amazon tags for a repository
The following
list-tags-for-resourceexample lists tag keys and tag values for the specified repository.aws codecommit list-tags-for-resource \ --resource-arnarn:aws:codecommit:us-west-2:111111111111:MyDemoRepoOutput:
{ "tags": { "Status": "Secret", "Team": "Saanvi" } }For more information, see View Tags for a Repository
in the Amazon CodeCommit User Guide. -
For API details, see ListTagsForResource
in Amazon CLI Command Reference.
-
The following code example shows how to use merge-branches-by-fast-forward.
- Amazon CLI
-
To merge two branches using the fast-forward merge strategy
The following
merge-branches-by-fast-forwardexample merges the specified source branch with the specified destination branch in a repository namedMyDemoRepo.aws codecommit merge-branches-by-fast-forward \ --source-commit-specifierbugfix-bug1234\ --destination-commit-specifierbugfix-bug1233\ --repository-nameMyDemoRepoOutput:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }For more information, see Compare and Merge Branches
in the Amazon CodeCommit User Guide. -
For API details, see MergeBranchesByFastForward
in Amazon CLI Command Reference.
-
The following code example shows how to use merge-branches-by-squash.
- Amazon CLI
-
To merge two branches using the squash merge strategy
The following
merge-branches-by-squashexample merges the specified source branch with the specified destination branch in a repository namedMyDemoRepo.aws codecommit merge-branches-by-squash \ --source-commit-specifierbugfix-bug1234\ --destination-commit-specifierbugfix-bug1233\ --author-name"Maria Garcia"\ --email"maria_garcia@example.com"\ --commit-message"Merging two fix branches to prepare for a general patch."\ --repository-nameMyDemoRepoOutput:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }For more information, see Compare and Merge Branches
in the Amazon CodeCommit User Guide. -
For API details, see MergeBranchesBySquash
in Amazon CLI Command Reference.
-
The following code example shows how to use merge-branches-by-three-way.
- Amazon CLI
-
To merge two branches using the three-way merge strategy
The following
merge-branches-by-three-wayexample merges the specified source branch with the specified destination branch in a repository namedMyDemoRepo.aws codecommit merge-branches-by-three-way \ --source-commit-specifiermain\ --destination-commit-specifierbugfix-bug1234\ --author-name"Jorge Souza"--email"jorge_souza@example.com"\ --commit-message"Merging changes from main to bugfix branch before additional testing."\ --repository-nameMyDemoRepoOutput:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }For more information, see Compare and Merge Branches
in the Amazon CodeCommit User Guide. -
For API details, see MergeBranchesByThreeWay
in Amazon CLI Command Reference.
-
The following code example shows how to use merge-pull-request-by-fast-forward.
- Amazon CLI
-
To merge and close a pull request
This example demonstrates how to merge and close a pull request with the ID of '47' and a source commit ID of '99132ab0EXAMPLE' in a repository named
MyDemoRepo.aws codecommit merge-pull-request-by-fast-forward \ --pull-request-id47\ --source-commit-id99132ab0EXAMPLE\ --repository-nameMyDemoRepoOutput:
{ "pullRequest": { "approvalRules": [ { "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "approvalRuleId": "dd8b17fe-EXAMPLE", "approvalRuleName": "I want one approver for this pull request", "creationDate": 1571356106.936, "lastModifiedDate": 571356106.936, "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "ruleContentSha256": "4711b576EXAMPLE" } ], "authorArn": "arn:aws:iam::123456789012:user/Li_Juan", "clientRequestToken": "", "creationDate": 1508530823.142, "description": "Review the latest changes and updates to the global variables", "lastActivityDate": 1508887223.155, "pullRequestId": "47", "pullRequestStatus": "CLOSED", "pullRequestTargets": [ { "destinationCommit": "9f31c968EXAMPLE", "destinationReference": "refs/heads/main", "mergeMetadata": { "isMerged": true, "mergedBy": "arn:aws:iam::123456789012:user/Mary_Major" }, "repositoryName": "MyDemoRepo", "sourceCommit": "99132ab0EXAMPLE", "sourceReference": "refs/heads/variables-branch" } ], "title": "Consolidation of global variables" } }For more information, see Merge a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see MergePullRequestByFastForward
in Amazon CLI Command Reference.
-
The following code example shows how to use merge-pull-request-by-squash.
- Amazon CLI
-
To merge a pull request using the squash merge strategy
The following
merge-pull-request-by-squashexample merges and closes the specified pull request using the conflict resolution strategy of ACCEPT_SOURCE in a repository namedMyDemoRepo.aws codecommit merge-pull-request-by-squash \ --pull-request-id47\ --source-commit-id99132ab0EXAMPLE\ --repository-nameMyDemoRepo\ --conflict-detail-levelLINE_LEVEL\ --conflict-resolution-strategyACCEPT_SOURCE\ --name"Jorge Souza"--email"jorge_souza@example.com"\ --commit-message"Merging pull request 47 by squash and accepting source in merge conflicts"Output:
{ "pullRequest": { "approvalRules": [ { "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "approvalRuleId": "dd8b17fe-EXAMPLE", "approvalRuleName": "2-approver-rule-for-main", "creationDate": 1571356106.936, "lastModifiedDate": 571356106.936, "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "originApprovalRuleTemplate": { "approvalRuleTemplateId": "dd8b17fe-EXAMPLE", "approvalRuleTemplateName": "2-approver-rule-for-main" }, "ruleContentSha256": "4711b576EXAMPLE" } ], "authorArn": "arn:aws:iam::123456789012:user/Li_Juan", "clientRequestToken": "", "creationDate": 1508530823.142, "description": "Review the latest changes and updates to the global variables", "lastActivityDate": 1508887223.155, "pullRequestId": "47", "pullRequestStatus": "CLOSED", "pullRequestTargets": [ { "destinationCommit": "9f31c968EXAMPLE", "destinationReference": "refs/heads/main", "mergeMetadata": { "isMerged": true, "mergedBy": "arn:aws:iam::123456789012:user/Mary_Major" }, "repositoryName": "MyDemoRepo", "sourceCommit": "99132ab0EXAMPLE", "sourceReference": "refs/heads/variables-branch" } ], "title": "Consolidation of global variables" } }For more information, see Merge a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see MergePullRequestBySquash
in Amazon CLI Command Reference.
-
The following code example shows how to use merge-pull-request-by-three-way.
- Amazon CLI
-
To merge a pull request using the three-way merge strategy
The following
merge-pull-request-by-three-wayexample merges and closes the specified pull request using the default options for conflict detail and conflict resolution strategy in a repository namedMyDemoRepo.aws codecommit merge-pull-request-by-three-way \ --pull-request-id47\ --source-commit-id99132ab0EXAMPLE\ --repository-nameMyDemoRepo\ --name"Maria Garcia"\ --email"maria_garcia@example.com"\ --commit-message"Merging pull request 47 by three-way with default options"Output:
{ "pullRequest": { "approvalRules": [ { "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "approvalRuleId": "dd8b17fe-EXAMPLE", "approvalRuleName": "2-approver-rule-for-main", "creationDate": 1571356106.936, "lastModifiedDate": 571356106.936, "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "originApprovalRuleTemplate": { "approvalRuleTemplateId": "dd8b17fe-EXAMPLE", "approvalRuleTemplateName": "2-approver-rule-for-main" }, "ruleContentSha256": "4711b576EXAMPLE" } ], "authorArn": "arn:aws:iam::123456789012:user/Li_Juan", "clientRequestToken": "", "creationDate": 1508530823.142, "description": "Review the latest changes and updates to the global variables", "lastActivityDate": 1508887223.155, "pullRequestId": "47", "pullRequestStatus": "CLOSED", "pullRequestTargets": [ { "destinationCommit": "9f31c968EXAMPLE", "destinationReference": "refs/heads/main", "mergeMetadata": { "isMerged": true, "mergedBy": "arn:aws:iam::123456789012:user/Mary_Major" }, "repositoryName": "MyDemoRepo", "sourceCommit": "99132ab0EXAMPLE", "sourceReference": "refs/heads/variables-branch" } ], "title": "Consolidation of global variables" } }For more information, see Merge a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see MergePullRequestByThreeWay
in Amazon CLI Command Reference.
-
The following code example shows how to use override-pull-request-approval-rules.
- Amazon CLI
-
To override approval rule requirements on a pull request
The following
override-pull-request-approval-rulesexample overrides approval rules on the specified pull request. To revoke an override instead, set the--override-statusparameter value toREVOKE.aws codecommit override-pull-request-approval-rules \ --pull-request-id34\ --revision-id927df8d8EXAMPLE\ --override-statusOVERRIDEThis command produces no output.
For more information, see Override Approval Rules on a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see OverridePullRequestApprovalRules
in Amazon CLI Command Reference.
-
The following code example shows how to use post-comment-for-compared-commit.
- Amazon CLI
-
To create a comment on a commit
This example demonstrates how to add the comment
"Can you add a test case for this?"on the change to thecl_sample.jsfile in the comparison between two commits in a repository namedMyDemoRepo.aws codecommit post-comment-for-compared-commit \ --repository-nameMyDemoRepo\ --before-commit-id317f8570EXAMPLE\ --after-commit-id5d036259EXAMPLE\ --client-request-token123Example\ --content"Can you add a test case for this?"\ --locationfilePath=cl_sample.js,filePosition=1232,relativeFileVersion=AFTEROutput:
{ "afterBlobId": "1f330709EXAMPLE", "afterCommitId": "317f8570EXAMPLE", "beforeBlobId": "80906a4cEXAMPLE", "beforeCommitId": "6e147360EXAMPLE", "comment": { "authorArn": "arn:aws:iam::111111111111:user/Li_Juan", "clientRequestToken": "", "commentId": "553b509bEXAMPLE56198325", "content": "Can you add a test case for this?", "creationDate": 1508369612.203, "deleted": false, "commentId": "abc123-EXAMPLE", "lastModifiedDate": 1508369612.203, "callerReactions": [], "reactionCounts": [] }, "location": { "filePath": "cl_sample.js", "filePosition": 1232, "relativeFileVersion": "AFTER" , "repositoryName": "MyDemoRepo" } }-
For API details, see PostCommentForComparedCommit
in Amazon CLI Command Reference.
-
The following code example shows how to use post-comment-for-pull-request.
- Amazon CLI
-
To add a comment to a pull request
The following
post-comment-for-pull-requestexample adds the comment "These don't appear to be used anywhere. Can we remove them?" on the change to theahs_count.pyfile in a pull request with the ID of47in a repository namedMyDemoRepo.aws codecommit post-comment-for-pull-request \ --pull-request-id"47"\ --repository-nameMyDemoRepo\ --before-commit-id317f8570EXAMPLE\ --after-commit-id5d036259EXAMPLE\ --client-request-token123Example\ --content"These don't appear to be used anywhere. Can we remove them?"\ --locationfilePath=ahs_count.py,filePosition=367,relativeFileVersion=AFTEROutput:
{ "afterBlobId": "1f330709EXAMPLE", "afterCommitId": "5d036259EXAMPLE", "beforeBlobId": "80906a4cEXAMPLE", "beforeCommitId": "317f8570EXAMPLE", "comment": { "authorArn": "arn:aws:iam::111111111111:user/Saanvi_Sarkar", "clientRequestToken": "123Example", "commentId": "abcd1234EXAMPLEb5678efgh", "content": "These don't appear to be used anywhere. Can we remove them?", "creationDate": 1508369622.123, "deleted": false, "CommentId": "", "lastModifiedDate": 1508369622.123, "callerReactions": [], "reactionCounts": [] }, "location": { "filePath": "ahs_count.py", "filePosition": 367, "relativeFileVersion": "AFTER" }, "repositoryName": "MyDemoRepo", "pullRequestId": "47" }-
For API details, see PostCommentForPullRequest
in Amazon CLI Command Reference.
-
The following code example shows how to use post-comment-reply.
- Amazon CLI
-
To reply to a comment on a commit or in a pull request
This example demonstrates how to add the reply
"Good catch. I'll remove them."to the comment with the system-generated ID ofabcd1234EXAMPLEb5678efgh.aws codecommit post-comment-reply \ --in-reply-toabcd1234EXAMPLEb5678efgh\ --content"Good catch. I'll remove them."\ --client-request-token123ExampleOutput:
{ "comment": { "authorArn": "arn:aws:iam::111111111111:user/Li_Juan", "clientRequestToken": "123Example", "commentId": "442b498bEXAMPLE5756813", "content": "Good catch. I'll remove them.", "creationDate": 1508369829.136, "deleted": false, "CommentId": "abcd1234EXAMPLEb5678efgh", "lastModifiedDate": 150836912.221, "callerReactions": [], "reactionCounts": [] } }-
For API details, see PostCommentReply
in Amazon CLI Command Reference.
-
The following code example shows how to use put-comment-reaction.
- Amazon CLI
-
To reply to a comment on a commit with an emoji
The following
put-comment-reactionexample replies to a comment with the ID ofabcd1234EXAMPLEb5678efghwith an emoji reaction value of:thumbsup:.aws codecommit put-comment-reaction \ --comment-idabcd1234EXAMPLEb5678efgh\ --reaction-value:thumbsup:This command produces no output.
For more information, see Comment on a commit in Amazon CodeCommit
in the Amazon CodeCommit User Guide. -
For API details, see PutCommentReaction
in Amazon CLI Command Reference.
-
The following code example shows how to use put-file.
- Amazon CLI
-
To add a file to a repository
The following
put-fileexample adds a file named 'ExampleSolution.py' to a repository named 'MyDemoRepo' to a branch named 'feature-randomizationfeature' whose most recent commit has an ID of '4c925148EXAMPLE'.aws codecommit put-file \ --repository-nameMyDemoRepo\ --branch-namefeature-randomizationfeature\ --file-contentfile://MyDirectory/ExampleSolution.py\ --file-path/solutions/ExampleSolution.py\ --parent-commit-id4c925148EXAMPLE\ --name"Maria Garcia"\ --email"maria_garcia@example.com"\ --commit-message"I added a third randomization routine."Output:
{ "blobId": "2eb4af3bEXAMPLE", "commitId": "317f8570EXAMPLE", "treeId": "347a3408EXAMPLE" }-
For API details, see PutFile
in Amazon CLI Command Reference.
-
The following code example shows how to use put-repository-triggers.
- Amazon CLI
-
To add or update a trigger in a repository
This example demonstrates how to update triggers named 'MyFirstTrigger' and 'MySecondTrigger' using an already-created JSON file (here named MyTriggers.json) that contains the structure of all the triggers for a repository named MyDemoRepo. To learn how to get the JSON for existing triggers, see the get-repository-triggers command.
aws codecommit put-repository-triggers \ --repository-nameMyDemoRepofile://MyTriggers.jsonContents of
MyTriggers.json:{ "repositoryName": "MyDemoRepo", "triggers": [ { "destinationArn": "arn:aws:sns:us-east-1:80398EXAMPLE:MyCodeCommitTopic", "branches": [ "main", "preprod" ], "name": "MyFirstTrigger", "customData": "", "events": [ "all" ] }, { "destinationArn": "arn:aws:lambda:us-east-1:111111111111:function:MyCodeCommitPythonFunction", "branches": [], "name": "MySecondTrigger", "customData": "EXAMPLE", "events": [ "all" ] } ] }Output:
{ "configurationId": "6fa51cd8-35c1-EXAMPLE" }-
For API details, see PutRepositoryTriggers
in Amazon CLI Command Reference.
-
The following code example shows how to use tag-resource.
- Amazon CLI
-
To add Amazon tags to an existing repository
The following
tag-resourceexample tags the specified repository with two tags.aws codecommit tag-resource \ --resource-arnarn:aws:codecommit:us-west-2:111111111111:MyDemoRepo\ --tagsStatus=Secret,Team=SaanviThis command produces no output.
For more information, see Add a Tag to a Repository
in the Amazon CodeCommit User Guide. -
For API details, see TagResource
in Amazon CLI Command Reference.
-
The following code example shows how to use test-repository-triggers.
- Amazon CLI
-
To test triggers in a repository
This example demonstrates how to test a trigger named 'MyFirstTrigger' in an Amazon CodeCommit repository named MyDemoRepo. In this example, events in the repository trigger notifications from an Amazon Simple Notification Service (Amazon SNS) topic.
Command:
aws codecommit test-repository-triggers --repository-nameMyDemoRepo--triggersname=MyFirstTrigger,destinationArn=arn:aws:sns:us-east-1:111111111111:MyCodeCommitTopic,branches=mainline,preprod,events=allOutput:
{ "successfulExecutions": [ "MyFirstTrigger" ], "failedExecutions": [] }-
For API details, see TestRepositoryTriggers
in Amazon CLI Command Reference.
-
The following code example shows how to use untag-resource.
- Amazon CLI
-
To remove Amazon tags from a repository
The following
untag-resourceexample removes the tag with the specified key from the repository namedMyDemoRepo.aws codecommit untag-resource \ --resource-arnarn:aws:codecommit:us-west-2:111111111111:MyDemoRepo\ --tag-keysStatusThis command produces no output.
For more information, see Remove a Tag from a Repository
in the Amazon CodeCommit User Guide. -
For API details, see UntagResource
in Amazon CLI Command Reference.
-
The following code example shows how to use update-approval-rule-template-content.
- Amazon CLI
-
To update the content of an approval rule template
The following
update-approval-rule-template-contentexample changes the content of the specified approval rule template to redefine the approval pool to users who assume the role ofCodeCommitReview.aws codecommit update-approval-rule-template-content \ --approval-rule-template-name1-approver-rule\ --new-rule-content "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}"Output:
{ "approvalRuleTemplate": { "creationDate": 1571352720.773, "approvalRuleTemplateDescription": "Requires 1 approval for all pull requests from the CodeCommitReview pool", "lastModifiedDate": 1571358728.41, "approvalRuleTemplateId": "41de97b7-EXAMPLE", "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests", "ruleContentSha256": "2f6c21a5EXAMPLE", "lastModifiedUser": "arn:aws:iam::123456789012:user/Li_Juan" } }For more information, see Manage Approval Rule Templates
in the Amazon CodeCommit User Guide. -
For API details, see UpdateApprovalRuleTemplateContent
in Amazon CLI Command Reference.
-
The following code example shows how to use update-approval-rule-template-description.
- Amazon CLI
-
To update the description of an approval rule template
The following
update-approval-rule-template-descriptionexample changes the description of the specified approval rule template toRequires 1 approval for all pull requests from the CodeCommitReview pool.:aws codecommit update-approval-rule-template-description \ --approval-rule-template-name1-approver-rule-for-all-pull-requests\ --approval-rule-template-description"Requires 1 approval for all pull requests from the CodeCommitReview pool"Output:
{ "approvalRuleTemplate": { "creationDate": 1571352720.773, "approvalRuleTemplateDescription": "Requires 1 approval for all pull requests from the CodeCommitReview pool", "lastModifiedDate": 1571358728.41, "approvalRuleTemplateId": "41de97b7-EXAMPLE", "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests", "ruleContentSha256": "2f6c21a5EXAMPLE", "lastModifiedUser": "arn:aws:iam::123456789012:user/Li_Juan" } }For more information, see Manage Approval Rule Templates
in the Amazon CodeCommit User Guide. -
For API details, see UpdateApprovalRuleTemplateDescription
in Amazon CLI Command Reference.
-
The following code example shows how to use update-approval-rule-template-name.
- Amazon CLI
-
To update the name of an approval rule template
The following
update-approval-rule-template-nameexample changes the name of an approval rule template from1-approver-ruleto 1-approver-rule-for-all-pull-requests`.aws codecommit update-approval-rule-template-name \ --old-approval-rule-template-name1-approver-rule\ --new-approval-rule-template-name1-approver-rule-for-all-pull-requestsOutput:
{ "approvalRuleTemplate": { "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests", "lastModifiedDate": 1571358241.619, "approvalRuleTemplateId": "41de97b7-EXAMPLE", "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "creationDate": 1571352720.773, "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "approvalRuleTemplateDescription": "All pull requests must be approved by one developer on the team.", "ruleContentSha256": "2f6c21a5cEXAMPLE" } }For more information, see Manage Approval Rule Templates
in the Amazon CodeCommit User Guide. -
For API details, see UpdateApprovalRuleTemplateName
in Amazon CLI Command Reference.
-
The following code example shows how to use update-comment.
- Amazon CLI
-
To update a comment on a commit
This example demonstrates how to add the content
"Fixed as requested. I'll update the pull request."to a comment with an ID of442b498bEXAMPLE5756813.aws codecommit update-comment \ --comment-id442b498bEXAMPLE5756813\ --content"Fixed as requested. I'll update the pull request."Output:
{ "comment": { "authorArn": "arn:aws:iam::111111111111:user/Li_Juan", "clientRequestToken": "", "commentId": "442b498bEXAMPLE5756813", "content": "Fixed as requested. I'll update the pull request.", "creationDate": 1508369929.783, "deleted": false, "lastModifiedDate": 1508369929.287, "callerReactions": [], "reactionCounts": { "THUMBSUP" : 2 } } }-
For API details, see UpdateComment
in Amazon CLI Command Reference.
-
The following code example shows how to use update-default-branch.
- Amazon CLI
-
To change the default branch for a repository
This example changes the default branch for an Amazon CodeCommit repository. This command produces output only if there are errors.
Command:
aws codecommit update-default-branch --repository-nameMyDemoRepo--default-branch-nameMyNewBranchOutput:
None.-
For API details, see UpdateDefaultBranch
in Amazon CLI Command Reference.
-
The following code example shows how to use update-pull-request-approval-rule-content.
- Amazon CLI
-
To edit an approval rule for a pull request
The following
update-pull-request-approval-rule-contentexample updates she specified approval rule to require one user approval from an approval pool that includes any IAM user in the123456789012Amazon account.aws codecommit update-pull-request-approval-rule-content \ --pull-request-id27\ --approval-rule-name"Require two approved approvers"\ --approval-rule-content "{Version: 2018-11-08, Statements: [{Type: \"Approvers\", NumberOfApprovalsNeeded: 1, ApprovalPoolMembers:[\"CodeCommitApprovers:123456789012:user/*\"]}]}}"Output:
{ "approvalRule": { "approvalRuleContent": "{Version: 2018-11-08, Statements: [{Type: \"Approvers\", NumberOfApprovalsNeeded: 1, ApprovalPoolMembers:[\"CodeCommitApprovers:123456789012:user/*\"]}]}}", "approvalRuleId": "aac33506-EXAMPLE", "originApprovalRuleTemplate": {}, "creationDate": 1570752871.932, "lastModifiedDate": 1570754058.333, "approvalRuleName": Require two approved approvers", "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "ruleContentSha256": "cd93921cEXAMPLE", } }For more information, see Edit or Delete an Approval Rule
in the Amazon CodeCommit User Guide. -
For API details, see UpdatePullRequestApprovalRuleContent
in Amazon CLI Command Reference.
-
The following code example shows how to use update-pull-request-approval-state.
- Amazon CLI
-
To approve or revoke approval for a pull request
The following
update-pull-request-approval-stateexample approves a pull request with the ID of27and a revision ID of9f29d167EXAMPLE. If you wanted to revoke approval instead, then set the--approval-stateparameter value toREVOKE.aws codecommit update-pull-request-approval-state \ --pull-request-id27\ --revision-id9f29d167EXAMPLE\ --approval-state"APPROVE"This command produces no output.
For more information, see Review a Pull Request
in the Amazon CodeCommit User Guide. -
For API details, see UpdatePullRequestApprovalState
in Amazon CLI Command Reference.
-
The following code example shows how to use update-pull-request-description.
- Amazon CLI
-
To change the description of a pull request
This example demonstrates how to change the description of a pull request with the ID of
47.aws codecommit update-pull-request-description \ --pull-request-id47\ --description"Updated the pull request to remove unused global variable."Output:
{ "pullRequest": { "authorArn": "arn:aws:iam::111111111111:user/Li_Juan", "clientRequestToken": "", "creationDate": 1508530823.155, "description": "Updated the pull request to remove unused global variable.", "lastActivityDate": 1508372423.204, "pullRequestId": "47", "pullRequestStatus": "OPEN", "pullRequestTargets": [ { "destinationCommit": "9f31c968EXAMPLE", "destinationReference": "refs/heads/main", "mergeMetadata": { "isMerged": false, }, "repositoryName": "MyDemoRepo", "sourceCommit": "99132ab0EXAMPLE", "sourceReference": "refs/heads/variables-branch" } ], "title": "Consolidation of global variables" } }-
For API details, see UpdatePullRequestDescription
in Amazon CLI Command Reference.
-
The following code example shows how to use update-pull-request-status.
- Amazon CLI
-
To change the status of a pull request
This example demonstrates how to to change the status of a pull request with the ID of
42to a status ofCLOSEDin an Amazon CodeCommit repository namedMyDemoRepo.aws codecommit update-pull-request-status \ --pull-request-id42\ --pull-request-statusCLOSEDOutput:
{ "pullRequest": { "approvalRules": [ { "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "approvalRuleId": "dd8b17fe-EXAMPLE", "approvalRuleName": "2-approvers-needed-for-this-change", "creationDate": 1571356106.936, "lastModifiedDate": 571356106.936, "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "ruleContentSha256": "4711b576EXAMPLE" } ], "authorArn": "arn:aws:iam::123456789012:user/Li_Juan", "clientRequestToken": "", "creationDate": 1508530823.165, "description": "Updated the pull request to remove unused global variable.", "lastActivityDate": 1508372423.12, "pullRequestId": "47", "pullRequestStatus": "CLOSED", "pullRequestTargets": [ { "destinationCommit": "9f31c968EXAMPLE", "destinationReference": "refs/heads/main", "mergeMetadata": { "isMerged": false, }, "repositoryName": "MyDemoRepo", "sourceCommit": "99132ab0EXAMPLE", "sourceReference": "refs/heads/variables-branch" } ], "title": "Consolidation of global variables" } }-
For API details, see UpdatePullRequestStatus
in Amazon CLI Command Reference.
-
The following code example shows how to use update-pull-request-title.
- Amazon CLI
-
To change the title of a pull request
This example demonstrates how to change the title of a pull request with the ID of
47.aws codecommit update-pull-request-title \ --pull-request-id47\ --title"Consolidation of global variables - updated review"Output:
{ "pullRequest": { "approvalRules": [ { "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}", "approvalRuleId": "dd8b17fe-EXAMPLE", "approvalRuleName": "2-approver-rule-for-main", "creationDate": 1571356106.936, "lastModifiedDate": 571356106.936, "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major", "originApprovalRuleTemplate": { "approvalRuleTemplateId": "dd8b26gr-EXAMPLE", "approvalRuleTemplateName": "2-approver-rule-for-main" }, "ruleContentSha256": "4711b576EXAMPLE" } ], "authorArn": "arn:aws:iam::123456789012:user/Li_Juan", "clientRequestToken": "", "creationDate": 1508530823.12, "description": "Review the latest changes and updates to the global variables. I have updated this request with some changes, including removing some unused variables.", "lastActivityDate": 1508372657.188, "pullRequestId": "47", "pullRequestStatus": "OPEN", "pullRequestTargets": [ { "destinationCommit": "9f31c968EXAMPLE", "destinationReference": "refs/heads/main", "mergeMetadata": { "isMerged": false, }, "repositoryName": "MyDemoRepo", "sourceCommit": "99132ab0EXAMPLE", "sourceReference": "refs/heads/variables-branch" } ], "title": "Consolidation of global variables - updated review" } }-
For API details, see UpdatePullRequestTitle
in Amazon CLI Command Reference.
-
The following code example shows how to use update-repository-description.
- Amazon CLI
-
To change the description for a repository
This example changes the description for an Amazon CodeCommit repository. This command produces output only if there are errors.
Command:
aws codecommit update-repository-description --repository-nameMyDemoRepo--repository-description"This description was changed"Output:
None.-
For API details, see UpdateRepositoryDescription
in Amazon CLI Command Reference.
-
The following code example shows how to use update-repository-name.
- Amazon CLI
-
To change the name of a repository
This example changes the name of an Amazon CodeCommit repository. This command produces output only if there are errors. Changing the name of the Amazon CodeCommit repository will change the SSH and HTTPS URLs that users need to connect to the repository. Users will not be able to connect to this repository until they update their connection settings. Also, because the repository's ARN will change, changing the repository name will invalidate any IAM user policies that rely on this repository's ARN.
Command:
aws codecommit update-repository-name --old-nameMyDemoRepo--new-nameMyRenamedDemoRepoOutput:
None.-
For API details, see UpdateRepositoryName
in Amazon CLI Command Reference.
-