There are more AWS SDK examples available in the AWS Doc SDK Examples
CodeCommit examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS 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.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see AssociateApprovalRuleTemplateWithRepository
in AWS CLI Command Reference.
-
The following code example shows how to use batch-associate-approval-rule-template-with-repositories.
- AWS 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 AWS Region where they are created. They can only be associated with repositories in that AWS 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 AWS CodeCommit User Guide.
-
For API details, see BatchAssociateApprovalRuleTemplateWithRepositories
in AWS CLI Command Reference.
-
The following code example shows how to use batch-describe-merge-conflicts.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see BatchDescribeMergeConflicts
in AWS CLI Command Reference.
-
The following code example shows how to use batch-disassociate-approval-rule-template-from-repositories.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see BatchDisassociateApprovalRuleTemplateFromRepositories
in AWS CLI Command Reference.
-
The following code example shows how to use batch-get-commits.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see BatchGetCommits
in AWS CLI Command Reference.
-
The following code example shows how to use batch-get-repositories.
- AWS CLI
-
To view details about multiple repositories
This example shows details about multiple AWS 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 AWS CLI Command Reference.
-
The following code example shows how to use create-approval-rule-template.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see CreateApprovalRuleTemplate
in AWS CLI Command Reference.
-
The following code example shows how to use create-branch.
- AWS CLI
-
To create a branch
This example creates a branch in an AWS 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 AWS CLI Command Reference.
-
The following code example shows how to use create-commit.
- AWS 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 AWS CodeCommit in the AWS CodeCommit User Guide.
-
For API details, see CreateCommit
in AWS CLI Command Reference.
-
The following code example shows how to use create-pull-request-approval-rule.
- AWS 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 the123456789012AWS account. It also includes either an IAM user or federated user namedNikhil_Jayashankarfrom the same AWS account.aws codecommit create-pull-request-approval-rule \ --pull-request-id42--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 AWS CodeCommit User Guide.
-
For API details, see CreatePullRequestApprovalRule
in AWS CLI Command Reference.
-
The following code example shows how to use create-pull-request.
- AWS 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 AWS 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 AWS CLI Command Reference.
-
The following code example shows how to use create-repository.
- AWS CLI
-
To create a repository
This example creates a repository and associates it with the user's AWS 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 AWS CLI Command Reference.
-
The following code example shows how to use create-unreferenced-merge-commit.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see CreateUnreferencedMergeCommit
in AWS CLI Command Reference.
-
The following code example shows how to use credential-helper.
- AWS CLI
-
To set up the credential helper included in the AWS CLI with AWS CodeCommit
The
credential-helperutility is not designed to be called directly from the AWS 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 AWS 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 AWS CodeCommit Using Other Methods in the AWS 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 AWS CodeCommit User Guide.
-
For API details, see CredentialHelper
in AWS CLI Command Reference.
-
The following code example shows how to use delete-approval-rule-template.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see DeleteApprovalRuleTemplate
in AWS CLI Command Reference.
-
The following code example shows how to use delete-branch.
- AWS CLI
-
To delete a branch
This example shows how to delete a branch in an AWS CodeCommit repository.
Command:
aws codecommit delete-branch --repository-nameMyDemoRepo--branch-nameMyNewBranchOutput:
{ "branch": { "commitId": "317f8570EXAMPLE", "branchName": "MyNewBranch" } }-
For API details, see DeleteBranch
in AWS CLI Command Reference.
-
The following code example shows how to use delete-comment-content.
- AWS 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 AWS CLI Command Reference.
-
The following code example shows how to use delete-file.
- AWS 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 AWS CodeCommit in the AWS CodeCommit API Reference guide.
-
For API details, see DeleteFile
in AWS CLI Command Reference.
-
The following code example shows how to use delete-pull-request-approval-rule.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see DeletePullRequestApprovalRule
in AWS CLI Command Reference.
-
The following code example shows how to use delete-repository.
- AWS CLI
-
To delete a repository
This example shows how to delete an AWS CodeCommit repository.
Command:
aws codecommit delete-repository --repository-nameMyDemoRepoOutput:
{ "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE" }-
For API details, see DeleteRepository
in AWS CLI Command Reference.
-
The following code example shows how to use describe-merge-conflicts.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see DescribeMergeConflicts
in AWS CLI Command Reference.
-
The following code example shows how to use describe-pull-request-events.
- AWS 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 AWS CLI Command Reference.
-
The following code example shows how to use disassociate-approval-rule-template-from-repository.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see DisassociateApprovalRuleTemplateFromRepository
in AWS CLI Command Reference.
-
The following code example shows how to use evaluate-pull-request-approval-rules.
- AWS 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 AWS CodeCommit User Guide.
-
For API details, see EvaluatePullRequestApprovalRules
in AWS CLI Command Reference.
-
The following code example shows how to use get-approval-rule-template.
- AWS 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