CodeCommit 使用示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

CodeCommit 使用示例 Amazon CLI

以下代码示例向您展示了如何使用with来执行操作和实现常见场景 CodeCommit。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 associate-approval-rule-template-with-repository

Amazon CLI

将批准规则模板与存储库关联

以下associate-approval-rule-template-with-repository示例将指定的批准规则模板与名为的存储库相关联MyDemoRepo

aws codecommit associate-approval-rule-template-with-repository \ --repository-name MyDemoRepo \ --approval-rule-template-name 2-approver-rule-for-main

此命令不生成任何输出。

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的将批准规则模板与存储库关联

以下代码示例演示如何使用 batch-associate-approval-rule-template-with-repositories

Amazon CLI

在单个操作中将批准规则模板与多个存储库关联

以下batch-associate-approval-rule-template-with-repositories示例将指定的批准规则模板与名为MyDemoRepo和的存储库相关联MyOtherDemoRepo

注意:批准规则模板特定于创建这些模板的 Amazon 区域。它们只能与该 Amazon 区域的存储库关联。

aws codecommit batch-associate-approval-rule-template-with-repositories \ --repository-names MyDemoRepo, MyOtherDemoRepo \ --approval-rule-template-name 2-approver-rule-for-main

输出:

{ "associatedRepositoryNames": [ "MyDemoRepo", "MyOtherDemoRepo" ], "errors": [] }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的将批准规则模板与存储库关联

以下代码示例演示如何使用 batch-describe-merge-conflicts

Amazon CLI

获取有关两个提交说明符之间合并时所有文件或文件子集中的合并冲突的信息

以下batch-describe-merge-conflicts示例确定了将名为的源分支feature-randomizationfeature与名为的存储库中main使用THREE_WAY_MERGE策略命名的目标分支合并时的合并冲突MyDemoRepo

aws codecommit batch-describe-merge-conflicts \ --source-commit-specifier feature-randomizationfeature \ --destination-commit-specifier main \ --merge-option THREE_WAY_MERGE \ --repository-name MyDemoRepo

输出:

{ "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" }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的解决拉取请求中的冲突

以下代码示例演示如何使用 batch-disassociate-approval-rule-template-from-repositories

Amazon CLI

在一次操作中取消批准规则模板与多个存储库的关联

以下batch-disassociate-approval-rule-template-from-repositories示例取消指定批准规则模板与名为MyDemoRepoMyOtherDemoRepo的存储库的关联。

aws codecommit batch-disassociate-approval-rule-template-from-repositories \ --repository-names MyDemoRepo, MyOtherDemoRepo \ --approval-rule-template-name 1-approval-rule-for-all pull requests

输出:

{ "disassociatedRepositoryNames": [ "MyDemoRepo", "MyOtherDemoRepo" ], "errors": [] }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的取消关联批准规则模板

以下代码示例演示如何使用 batch-get-commits

Amazon CLI

查看有关多次提交的信息

以下batch-get-commits示例显示有关指定提交的详细信息。

aws codecommit batch-get-commits \ --repository-name MyDemoRepo \ --commit-ids 317f8570EXAMPLE 4c925148EXAMPLE

输出:

{ "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" } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “查看提交详情”。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考BatchGetCommits中的。

以下代码示例演示如何使用 batch-get-repositories

Amazon CLI

查看有关多个存储库的详细信息

此示例显示有关多个 Amazon CodeCommit 存储库的详细信息。

aws codecommit batch-get-repositories \ --repository-names MyDemoRepo MyOtherDemoRepo

输出:

{ "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": [] }

以下代码示例演示如何使用 create-approval-rule-template

Amazon CLI

创建批准规则模板

以下create-approval-rule-template示例创建了一个名为的批准规则模板2-approver-rule-for-main ``. The template requires two users who assume the role of ``CodeCommitReview,用于批准任何拉取请求,然后才能将其合并到main分支。

aws codecommit create-approval-rule-template \ --approval-rule-template-name 2-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/*\"]}]}"

输出:

{ "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" } }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的创建批准规则模板

以下代码示例演示如何使用 create-branch

Amazon CLI

创建分支

此示例在 Amazon CodeCommit 存储库中创建分支。该命令只在出现错误时生成输出。

命令:

aws codecommit create-branch --repository-name MyDemoRepo --branch-name MyNewBranch --commit-id 317f8570EXAMPLE

输出:

None.
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateBranch中的。

以下代码示例演示如何使用 create-commit

Amazon CLI

创建提交

以下create-commit示例演示如何为存储库创建初始提交,该存储库将readme.md文件添加到main分支MyDemoRepo中名为的存储库中。

aws codecommit create-commit \ --repository-name MyDemoRepo \ --branch-name main \ --put-files "filePath=readme.md,fileContent='Welcome to our team repository.'"

输出:

{ "filesAdded": [ { "blobId": "5e1c309d-EXAMPLE", "absolutePath": "readme.md", "fileMode": "NORMAL" } ], "commitId": "4df8b524-EXAMPLE", "treeId": "55b57003-EXAMPLE", "filesDeleted": [], "filesUpdated": [] }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》 Amazon CodeCommit中的创建提交

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateCommit中的。

以下代码示例演示如何使用 create-pull-request-approval-rule

Amazon CLI

为拉取请求创建批准规则

以下create-pull-request-approval-rule示例为指定的拉取请求创建名Require two approved approvers为的批准规则。该规则规定,一个批准池需要两次批准。该池包括 CodeCommit 通过在123456789012 Amazon 账户CodeCommitReview中扮演角色进行访问的所有用户。它还包括Nikhil_Jayashankar来自同一 Amazon 账户的 IAM 用户或联合用户。

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/*\"]}]}"

输出:

{ "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" } }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的创建批准规则

以下代码示例演示如何使用 create-pull-request

Amazon CLI

创建拉取请求

以下create-pull-request示例创建了一个名为 “发音难度分析器” 的拉取请求,其描述为 “请在周二之前查看这些更改”,该请求的目标是 “jane-branch” 源分支,并将合并到名为 “” 的存储库中的默认分支 “main” 中。 Amazon CodeCommit MyDemoRepo

aws codecommit create-pull-request \ --title "My Pull Request" \ --description "Please review these changes by Tuesday" \ --client-request-token 123Example \ --targets repositoryName=MyDemoRepo,sourceReference=MyNewBranch

输出:

{ "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 } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreatePullRequest中的。

以下代码示例演示如何使用 create-repository

Amazon CLI

创建存储库

此示例创建了一个存储库并将其与用户的 Amazon 帐户关联。

命令:

aws codecommit create-repository --repository-name MyDemoRepo --repository-description "My demonstration repository"

输出:

{ "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" } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateRepository中的。

以下代码示例演示如何使用 create-unreferenced-merge-commit

Amazon CLI

创建表示合并两个提交说明符后结果的未引用提交

以下create-unreferenced-merge-commit示例创建了一个提交,该提交表示名为的源分支bugfix-1234与名为的存储库中main使用 THREE_WAY_MERGE 策略命名的目标分支之间的合并结果。MyDemoRepo

aws codecommit create-unreferenced-merge-commit \ --source-commit-specifier bugfix-1234 \ --destination-commit-specifier main \ --merge-option THREE_WAY_MERGE \ --repository-name MyDemoRepo \ --name "Maria Garcia" \ --email "maria_garcia@example.com" \ --commit-message "Testing the results of this merge."

输出:

{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的解决拉取请求中的冲突

以下代码示例演示如何使用 credential-helper

Amazon CLI

使用以下命令设置 C Amazon LI 中包含的凭证助手 Amazon CodeCommit

credential-helper实用程序不是为直接从 Amazon CLI 调用而设计的。相反,它旨在用作设置本地计算机的git config命令的参数。它允许 Git 在需要进行身份验证以与 CodeCommit 存储库交互时使用 HTTPS 和您的 IAM 用户证书或 Amazon EC2 实例角色的 Amazon 加密签名版本。

git config --global credential.helper '!aws codecommit credential-helper $@' git config --global credential.UseHttpPath true

输出:

[credential] helper = !aws codecommit credential-helper $@ UseHttpPath = true

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的设置 Amazon CodeCommit 使用其他方法。仔细阅读内容,然后按照以下主题之一中的步骤进行操作:《Amazon CodeCommit 用户指南》中的 “适用于 Linux、macOS 或 Unix 上的 HTTPS 连接” 或 “适用于 Windows 上的 HTTPS 连接”。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CredentialHelper中的。

以下代码示例演示如何使用 delete-approval-rule-template

Amazon CLI

删除批准规则模板

以下delete-approval-rule-template示例删除了指定的批准规则模板。

aws codecommit delete-approval-rule-template \ --approval-rule-template-name 1-approver-for-all-pull-requests

输出:

{ "approvalRuleTemplateId": "41de97b7-EXAMPLE" }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的删除批准规则模板

以下代码示例演示如何使用 delete-branch

Amazon CLI

删除分支

此示例说明如何删除 Amazon CodeCommit 存储库中的分支。

命令:

aws codecommit delete-branch --repository-name MyDemoRepo --branch-name MyNewBranch

输出:

{ "branch": { "commitId": "317f8570EXAMPLE", "branchName": "MyNewBranch" } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteBranch中的。

以下代码示例演示如何使用 delete-comment-content

Amazon CLI

删除评论的内容

如果您创建了评论,则只能删除评论的内容。此示例演示如何删除系统生成的 ID 为的评论的ff30b348EXAMPLEb9aa670f内容。

aws codecommit delete-comment-content \ --comment-id ff30b348EXAMPLEb9aa670f

输出:

{ "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 } } }

以下代码示例演示如何使用 delete-file

Amazon CLI

删除文件

以下delete-file示例演示如何README.md从名为的存储库中名为main、最新提交 ID 为的分支c5709475EXAMPLE中删除名为的文件MyDemoRepo

aws codecommit delete-file \ --repository-name MyDemoRepo \ --branch-name main \ --file-path README.md \ --parent-commit-id c5709475EXAMPLE

输出:

{ "blobId":"559b44fEXAMPLE", "commitId":"353cf655EXAMPLE", "filePath":"README.md", "treeId":"6bc824cEXAMPLE" }

有关更多信息,请参阅 Amazon CodeCommit API 参考指南Amazon CodeCommit中的编辑或删除文件

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteFile中的。

以下代码示例演示如何使用 delete-pull-request-approval-rule

Amazon CLI

删除拉取请求的批准规则

以下delete-pull-request-approval-rule示例删除了My Approval Rule为指定拉取请求命名的批准规则。

aws codecommit delete-pull-request-approval-rule \ --approval-rule-name "My Approval Rule" \ --pull-request-id 15

输出:

{ "approvalRuleId": "077d8e8a8-EXAMPLE" }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的编辑或删除批准规则

以下代码示例演示如何使用 delete-repository

Amazon CLI

删除存储库

此示例说明如何删除 Amazon CodeCommit 存储库。

命令:

aws codecommit delete-repository --repository-name MyDemoRepo

输出:

{ "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE" }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteRepository中的。

以下代码示例演示如何使用 describe-merge-conflicts

Amazon CLI

获取有关合并冲突的详细信息

以下describe-merge-conflicts示例使用 THREE_WAY_MERGE 策略确定readme.md在指定源分支和目标分支中命名的文件的合并冲突。

aws codecommit describe-merge-conflicts \ --source-commit-specifier feature-randomizationfeature \ --destination-commit-specifier main \ --merge-option THREE_WAY_MERGE \ --file-path readme.md \ --repository-name MyDemoRepo

输出:

{ "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" }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的解决拉取请求中的冲突

以下代码示例演示如何使用 describe-pull-request-events

Amazon CLI

查看拉取请求中的事件

以下describe-pull-request-events示例检索 ID 为 “8” 的拉取请求的事件。

aws codecommit describe-pull-request-events --pull-request-id 8

输出:

{ "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" } ] }

以下代码示例演示如何使用 disassociate-approval-rule-template-from-repository

Amazon CLI

取消批准规则模板与存储库的关联

以下disassociate-approval-rule-template-from-repository示例取消指定批准规则模板与名为MyDemoRepo的存储库的关联。

aws codecommit disassociate-approval-rule-template-from-repository \ --repository-name MyDemoRepo \ --approval-rule-template-name 1-approver-rule-for-all-pull-requests

此命令不生成任何输出。

有关更多信息,请参阅Amazon CodeCommit 用户指南中的取消关联批准规则模板

以下代码示例演示如何使用 evaluate-pull-request-approval-rules

Amazon CLI

评估拉取请求是否满足其所有批准规则

以下evaluate-pull-request-approval-rules示例评估了指定拉取请求的批准规则的状态。在此示例中,拉取请求的批准规则未得到满足,因此命令的输出显示approved值为false

aws codecommit evaluate-pull-request-approval-rules \ --pull-request-id 27 \ --revision-id 9f29d167EXAMPLE

输出:

{ "evaluation": { "approved": false, "approvalRulesNotSatisfied": [ "Require two approved approvers" ], "overridden": false, "approvalRulesSatisfied": [] } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的合并拉取请求

以下代码示例演示如何使用 get-approval-rule-template

Amazon CLI

获取批准规则模板的内容

以下get-approval-rule-template示例获取名为的批准规则模板的内容1-approver-rule-for-all-pull-requests

aws codecommit get-approval-rule-template \ --approval-rule-template-name 1-approver-rule-for-all-pull-requests

输出:

{ "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." } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “管理批准规则模板”。

以下代码示例演示如何使用 get-blob

Amazon CLI

查看有关 Git blob 对象的信息

以下get-blob示例在名为 “” 的存储库中检索有关 ID 为 “2eb4af3bexAmple” 的 Git blob 的信息。 Amazon CodeCommit MyDemoRepo

aws codecommit get-blob --repository-name MyDemoRepo --blob-id 2eb4af3bEXAMPLE

输出:

{ "content": "QSBCaW5hcnkgTGFyToEXAMPLE=" }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetBlob中的。

以下代码示例演示如何使用 get-branch

Amazon CLI

获取有关分支的信息

此示例获取有关 Amazon CodeCommit 存储库中分支的信息。

命令:

aws codecommit get-branch --repository-name MyDemoRepo --branch-name MyNewBranch

输出:

{ "BranchInfo": { "commitID": "317f8570EXAMPLE", "branchName": "MyNewBranch" } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetBranch中的。

以下代码示例演示如何使用 get-comment-reactions

Amazon CLI

查看表情符号对评论的反应

以下get-comment-reactions示例列出了对 ID 为的评论的所有表情符号反应abcd1234EXAMPLEb5678efgh。如果您的 shell 的字体支持显示表情符号版本 1.0,则会在emoji输出中显示表情符号。

aws codecommit get-comment-reactions \ --comment-id abcd1234EXAMPLEb5678efgh

输出:

{ "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" ] } ] } }

有关更多信息,请参阅Amazon CodeCommit 用户指南》 Amazon CodeCommit中的对提交进行评论

以下代码示例演示如何使用 get-comment

Amazon CLI

查看评论的详细信息

此示例演示如何查看系统生成的评论 ID 为的评论的ff30b348EXAMPLEb9aa670f详细信息。

aws codecommit get-comment \ --comment-id ff30b348EXAMPLEb9aa670f

输出:

{ "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 } } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetComment中的。

以下代码示例演示如何使用 get-comments-for-compared-commit

Amazon CLI

查看对提交的评论

此示例演示如何查看对名为的存储库中两个提交之间的比较所做的视图评论MyDemoRepo

aws codecommit get-comments-for-compared-commit \ --repository-name MyDemoRepo \ --before-commit-ID 6e147360EXAMPLE \ --after-commit-id 317f8570EXAMPLE

输出:

{ "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" }

以下代码示例演示如何使用 get-comments-for-pull-request

Amazon CLI

查看拉取请求的评论

此示例演示如何在名为的仓库中查看拉取请求的评论MyDemoRepo

aws codecommit get-comments-for-pull-request \ --repository-name MyDemoRepo \ --before-commit-ID 317f8570EXAMPLE \ --after-commit-id 5d036259EXAMPLE

输出:

{ "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" }

以下代码示例演示如何使用 get-commit

Amazon CLI

查看有关仓库中提交的信息

此示例显示了有关在名为 “” 的存储库中系统生成的 ID 为 “7e9fd3091thisanexamplethisanexample1” 的提交的详细信息。 Amazon CodeCommit MyDemoRepo

命令:

aws codecommit get-commit --repository-name MyDemoRepo --commit-id 7e9fd3091thisisanexamplethisisanexample1

输出:

{ "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" } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetCommit中的。

以下代码示例演示如何使用 get-differences

Amazon CLI

获取有关仓库中提交说明符差异的信息

此示例显示了在名为的 Amazon CodeCommit 存储库中重命名的 MyDemoRepo文件夹中有关两个提交说明符(分支、标记、HEAD 或其他完全限定引用,例如提交 ID)之间更改的视图元数据信息。该示例包括几个不需要的选项,包括--before-commit-specifier、--before-path 和--after-path,以便更全面地说明如何使用这些选项来限制结果。响应包括文件模式权限。

命令:

aws codecommit get-differences --repository-name MyDemoRepo --before-commit-specifier 955bba12thisisanexamplethisisanexample --after-commit-specifier 14a95463thisisanexamplethisisanexample --before-path tmp/example-folder --after-path tmp/renamed-folder

输出:

{ "differences": [ { "afterBlob": { "path": "blob.txt", "blobId": "2eb4af3b1thisisanexamplethisisanexample1", "mode": "100644" }, "changeType": "M", "beforeBlob": { "path": "blob.txt", "blobId": "bf7fcf281thisisanexamplethisisanexample1", "mode": "100644" } } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetDifferences中的。

以下代码示例演示如何使用 get-file

Amazon CLI

获取存储库中文件的 base-64 编码内容 Amazon CodeCommit

以下get-file示例演示如何README.md从名为的存储库中名为的分支main中获取名为 base-64 的编码内容。MyDemoRepo

aws codecommit get-file \ --repository-name MyDemoRepo \ --commit-specifier main \ --file-path README.md

输出:

{ "blobId":"559b44fEXAMPLE", "commitId":"c5709475EXAMPLE", "fileContent":"IyBQaHVzEXAMPLE", "filePath":"README.md", "fileMode":"NORMAL", "fileSize":1563 }

有关更多信息,请参阅 Amazon CodeCommit API 参考指南GetFile中的。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetFile中的。

以下代码示例演示如何使用 get-folder

Amazon CLI

获取 Amazon CodeCommit 存储库中文件夹的内容

以下get-folder示例演示如何从名为的存储库中获取顶级文件夹的内容MyDemoRepo

aws codecommit get-folder --repository-name MyDemoRepo --folder-path ""

输出:

{ "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" }

有关更多信息,请参阅 Amazon CodeCommit API 参考指南 GetFolder 中的。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetFolder中的。

以下代码示例演示如何使用 get-merge-commit

Amazon CLI

获取有关合并提交的详细信息

以下get-merge-commit示例显示了在名为的存储库中main使用 THREE_WAY_MERGE 策略命名的bugfix-bug1234源分支的合并提交的详细信息,目标分支名为 THREE_WAY_MERGE。MyDemoRepo

aws codecommit get-merge-commit \ --source-commit-specifier bugfix-bug1234 \ --destination-commit-specifier main \ --merge-option THREE_WAY_MERGE \ --repository-name MyDemoRepo

输出:

{ "sourceCommitId": "c5709475EXAMPLE", "destinationCommitId": "317f8570EXAMPLE", "baseCommitId": "fb12a539EXAMPLE", "mergeCommitId": "ffc4d608eEXAMPLE" }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “查看提交详情”。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetMergeCommit中的。

以下代码示例演示如何使用 get-merge-conflicts

Amazon CLI

查看拉取请求是否存在合并冲突

以下get-merge-conflicts示例显示名为 “main” 的源分支的尖端与名为 “main” 的存储库中名为 feature-randomizationfeature “main” 的目标分支之间是否存在任何合并冲突MyDemoRepo

aws codecommit get-merge-conflicts \ --repository-name MyDemoRepo \ --source-commit-specifier feature-randomizationfeature \ --destination-commit-specifier main \ --merge-option THREE_WAY_MERGE

输出:

{ "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" } } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetMergeConflicts中的。

以下代码示例演示如何使用 get-merge-options

Amazon CLI

获取有关可用于合并两个指定分支的合并选项的信息

以下get-merge-options示例确定了可用于合并名为的源分支和名为bugfix-bug1234的存储库main中名为的目标分支的合并选项MyDemoRepo

aws codecommit get-merge-options \ --source-commit-specifier bugfix-bug1234 \ --destination-commit-specifier main \ --repository-name MyDemoRepo

输出:

{ "mergeOptions": [ "FAST_FORWARD_MERGE", "SQUASH_MERGE", "THREE_WAY_MERGE" ], "sourceCommitId": "18059494EXAMPLE", "destinationCommitId": "ffd3311dEXAMPLE", "baseCommitId": "ffd3311dEXAMPLE" }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的解决拉取请求中的冲突

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetMergeOptions中的。

以下代码示例演示如何使用 get-pull-request-approval-states

Amazon CLI

查看拉取请求的批准情况

以下get-pull-request-approval-states示例返回对指定拉取请求的批准。

aws codecommit get-pull-request-approval-states \ --pull-request-id 8 \ --revision-id 9f29d167EXAMPLE

输出:

{ "approvals": [ { "userArn": "arn:aws:iam::123456789012:user/Mary_Major", "approvalState": "APPROVE" } ] }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “查看拉取请求”。

以下代码示例演示如何使用 get-pull-request-override-state

Amazon CLI

获取有关拉取请求的覆盖状态的信息

以下get-pull-request-override-state示例返回指定拉取请求的覆盖状态。在此示例中,名为 Mary Major 的用户覆盖了拉取请求的批准规则,因此输出返回的值为。true :

aws codecommit get-pull-request-override-state \ --pull-request-id 34 \ --revision-id 9f29d167EXAMPLE

输出:

{ "overridden": true, "overrider": "arn:aws:iam::123456789012:user/Mary_Major" }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的改写拉取请求的批准规则

以下代码示例演示如何使用 get-pull-request

Amazon CLI

查看拉取请求的详细信息

此示例演示如何查看 ID 为的拉取请求的相关信息27

aws codecommit get-pull-request \ --pull-request-id 27

输出:

{ "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" } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetPullRequest中的。

以下代码示例演示如何使用 get-repository-triggers

Amazon CLI

获取有关存储库中触发器的信息

此示例显示有关为名为的 Amazon CodeCommit 存储库配置的触发器的详细信息MyDemoRepo

aws codecommit get-repository-triggers \ --repository-name MyDemoRepo

输出:

{ "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" ] } ] }

以下代码示例演示如何使用 get-repository

Amazon CLI

获取有关存储库的信息

此示例显示有关 Amazon CodeCommit 存储库的详细信息。

aws codecommit get-repository \ --repository-name MyDemoRepo

输出:

{ "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" } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetRepository中的。

以下代码示例演示如何使用 list-approval-rule-templates

Amazon CLI

列出某个 Amazon 区域中的所有批准规则模板

以下list-approval-rule-templates示例列出了指定区域中的所有批准规则模板。如果未将 Amazon 区域指定为参数,则该命令将返回用于运行该命令的 Amazon CLI 配置文件中指定的区域的批准规则模板。

aws codecommit list-approval-rule-templates \ --region us-east-2

输出:

{ "approvalRuleTemplateNames": [ "2-approver-rule-for-main", "1-approver-rule-for-all-pull-requests" ] }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “管理批准规则模板”。

以下代码示例演示如何使用 list-associated-approval-rule-templates-for-repository

Amazon CLI

列出与存储库关联的所有模板

以下list-associated-approval-rule-templates-for-repository示例列出了与名为的存储库关联的所有批准规则模板MyDemoRepo

aws codecommit list-associated-approval-rule-templates-for-repository \ --repository-name MyDemoRepo

输出:

{ "approvalRuleTemplateNames": [ "2-approver-rule-for-main", "1-approver-rule-for-all-pull-requests" ] }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “管理批准规则模板”。

以下代码示例演示如何使用 list-branches

Amazon CLI

查看分支名称列表

此示例列出了 Amazon CodeCommit 存储库中的所有分支名称。

aws codecommit list-branches \ --repository-name MyDemoRepo

输出:

{ "branches": [ "MyNewBranch", "main" ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListBranches中的。

以下代码示例演示如何使用 list-pull-requests

Amazon CLI

查看仓库中的拉取请求列表

此示例演示如何在名为 “” 的仓库中列出 ARN 为 'arn: aws: iam:: 1111111111:user/li_juan '且状态为 “已关闭” 的 IAM 用户创建的拉取请求: Amazon CodeCommit MyDemoRepo

aws codecommit list-pull-requests --author-arn arn:aws:iam::111111111111:user/Li_Juan --pull-request-status CLOSED --repository-name MyDemoRepo

输出:

{ "nextToken": "", "pullRequestIds": ["2","12","16","22","23","35","30","39","47"] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListPullRequests中的。

以下代码示例演示如何使用 list-repositories-for-approval-rule-template

Amazon CLI

列出与模板关联的所有存储库

以下list-repositories-for-approval-rule-template示例列出了与指定批准规则模板关联的所有存储库。

aws codecommit list-repositories-for-approval-rule-template \ --approval-rule-template-name 2-approver-rule-for-main

输出:

{ "repositoryNames": [ "MyDemoRepo", "MyClonedRepo" ] }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “管理批准规则模板”。

以下代码示例演示如何使用 list-repositories

Amazon CLI

查看存储库列表

此示例列出了与用户 Amazon 账户关联的所有 Amazon CodeCommit 仓库。

命令:

aws codecommit list-repositories

输出:

{ "repositories": [ { "repositoryName": "MyDemoRepo" "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE", }, { "repositoryName": "MyOtherDemoRepo" "repositoryId": "cfc29ac4-b0cb-44dc-9990-f6f51EXAMPLE" } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListRepositories中的。

以下代码示例演示如何使用 list-tags-for-resource

Amazon CLI

查看存储库的 Amazon 标签

以下list-tags-for-resource示例列出了指定存储库的标签键和标签值。

aws codecommit list-tags-for-resource \ --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo

输出:

{ "tags": { "Status": "Secret", "Team": "Saanvi" } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “查看存储库的标签”。

以下代码示例演示如何使用 merge-branches-by-fast-forward

Amazon CLI

使用快进合并策略合并两个分支

以下merge-branches-by-fast-forward示例将指定的源分支与名MyDemoRepo为的存储库中的指定目标分支合并。

aws codecommit merge-branches-by-fast-forward \ --source-commit-specifier bugfix-bug1234 \ --destination-commit-specifier bugfix-bug1233 \ --repository-name MyDemoRepo

输出:

{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “比较和合并分支”。

以下代码示例演示如何使用 merge-branches-by-squash

Amazon CLI

使用 squash 合并策略合并两个分支

以下merge-branches-by-squash示例将指定的源分支与名MyDemoRepo为的存储库中的指定目标分支合并。

aws codecommit merge-branches-by-squash \ --source-commit-specifier bugfix-bug1234 \ --destination-commit-specifier bugfix-bug1233 \ --author-name "Maria Garcia" \ --email "maria_garcia@example.com" \ --commit-message "Merging two fix branches to prepare for a general patch." \ --repository-name MyDemoRepo

输出:

{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “比较和合并分支”。

以下代码示例演示如何使用 merge-branches-by-three-way

Amazon CLI

使用三向合并策略合并两个分支

以下merge-branches-by-three-way示例将指定的源分支与名MyDemoRepo为的存储库中的指定目标分支合并。

aws codecommit merge-branches-by-three-way \ --source-commit-specifier main \ --destination-commit-specifier bugfix-bug1234 \ --author-name "Jorge Souza" --email "jorge_souza@example.com" \ --commit-message "Merging changes from main to bugfix branch before additional testing." \ --repository-name MyDemoRepo

输出:

{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “比较和合并分支”。

以下代码示例演示如何使用 merge-pull-request-by-fast-forward

Amazon CLI

合并并关闭拉取请求

此示例演示如何在名为的存储库中合并和关闭 ID 为 '47'、源提交 ID 为 '99132ab0Example' 的拉取请求。MyDemoRepo

aws codecommit merge-pull-request-by-fast-forward \ --pull-request-id 47 \ --source-commit-id 99132ab0EXAMPLE \ --repository-name MyDemoRepo

输出:

{ "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" } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的合并拉取请求

以下代码示例演示如何使用 merge-pull-request-by-squash

Amazon CLI

使用 squash 合并策略合并拉取请求

以下merge-pull-request-by-squash示例在名为的存储库中使用 ACCEPT_SOURCE 的冲突解决策略合并并关闭指定的拉取请求。MyDemoRepo

aws codecommit merge-pull-request-by-squash \ --pull-request-id 47 \ --source-commit-id 99132ab0EXAMPLE \ --repository-name MyDemoRepo \ --conflict-detail-level LINE_LEVEL \ --conflict-resolution-strategy ACCEPT_SOURCE \ --name "Jorge Souza" --email "jorge_souza@example.com" \ --commit-message "Merging pull request 47 by squash and accepting source in merge conflicts"

输出:

{ "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" } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的合并拉取请求

以下代码示例演示如何使用 merge-pull-request-by-three-way

Amazon CLI

使用三向合并策略合并拉取请求

以下merge-pull-request-by-three-way示例使用名MyDemoRepo为的存储库中冲突详细信息和冲突解决策略的默认选项合并并关闭指定的拉取请求。

aws codecommit merge-pull-request-by-three-way \ --pull-request-id 47 \ --source-commit-id 99132ab0EXAMPLE \ --repository-name MyDemoRepo \ --name "Maria Garcia" \ --email "maria_garcia@example.com" \ --commit-message "Merging pull request 47 by three-way with default options"

输出:

{ "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" } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的合并拉取请求

以下代码示例演示如何使用 override-pull-request-approval-rules

Amazon CLI

改写拉取请求的批准规则要求

以下override-pull-request-approval-rules示例覆盖了指定拉取请求的批准规则。要改为撤消覆盖,请将--override-status参数值设置为。REVOKE

aws codecommit override-pull-request-approval-rules \ --pull-request-id 34 \ --revision-id 927df8d8EXAMPLE \ --override-status OVERRIDE

此命令不生成任何输出。

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的改写拉取请求的批准规则

以下代码示例演示如何使用 post-comment-for-compared-commit

Amazon CLI

对提交创建评论

此示例演示了如何在比较名为"Can you add a test case for this?"的存储库中的两个提交时向cl_sample.js文件添加对变更的注释MyDemoRepo

aws codecommit post-comment-for-compared-commit \ --repository-name MyDemoRepo \ --before-commit-id 317f8570EXAMPLE \ --after-commit-id 5d036259EXAMPLE \ --client-request-token 123Example \ --content "Can you add a test case for this?" \ --location filePath=cl_sample.js,filePosition=1232,relativeFileVersion=AFTER

输出:

{ "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" } }

以下代码示例演示如何使用 post-comment-for-pull-request

Amazon CLI

向拉取请求添加评论

以下post-comment-for-pull-request示例添加了注释 “这些似乎没有在任何地方使用。Can we remove them?"。关于在名为的存储库中 ID 为的拉取请求47中对ahs_count.py文件的更改MyDemoRepo

aws codecommit post-comment-for-pull-request \ --pull-request-id "47" \ --repository-name MyDemoRepo \ --before-commit-id 317f8570EXAMPLE \ --after-commit-id 5d036259EXAMPLE \ --client-request-token 123Example \ --content "These don't appear to be used anywhere. Can we remove them?" \ --location filePath=ahs_count.py,filePosition=367,relativeFileVersion=AFTER

输出:

{ "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" }

以下代码示例演示如何使用 post-comment-reply

Amazon CLI

回复提交或拉取请求中的评论

此示例演示如何将系统生成的 ID "Good catch. I'll remove them." 为的评论添加回复。abcd1234EXAMPLEb5678efgh

aws codecommit post-comment-reply \ --in-reply-to abcd1234EXAMPLEb5678efgh \ --content "Good catch. I'll remove them." \ --client-request-token 123Example

输出:

{ "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": [] } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考PostCommentReply中的。

以下代码示例演示如何使用 put-comment-reaction

Amazon CLI

使用表情符号回复对提交的评论

以下put-comment-reaction示例回复了标识为、表情符号反应值为的评论:thumbsup:abcd1234EXAMPLEb5678efgh

aws codecommit put-comment-reaction \ --comment-id abcd1234EXAMPLEb5678efgh \ --reaction-value :thumbsup:

此命令不生成任何输出。

有关更多信息,请参阅Amazon CodeCommit 用户指南》 Amazon CodeCommit中的对提交进行评论

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考PutCommentReaction中的。

以下代码示例演示如何使用 put-file

Amazon CLI

向存储库添加文件

以下put-file示例将名为 “ExampleSolution.py” 的文件添加到名为 “” 的存储库中,添加到名为 “feature-randomizationfeationfeationfeation” 的分支中,该分支的最新提交 ID 为 “4c925148Example”。MyDemoRepo

aws codecommit put-file \ --repository-name MyDemoRepo \ --branch-name feature-randomizationfeature \ --file-content file://MyDirectory/ExampleSolution.py \ --file-path /solutions/ExampleSolution.py \ --parent-commit-id 4c925148EXAMPLE \ --name "Maria Garcia" \ --email "maria_garcia@example.com" \ --commit-message "I added a third randomization routine."

输出:

{ "blobId": "2eb4af3bEXAMPLE", "commitId": "317f8570EXAMPLE", "treeId": "347a3408EXAMPLE" }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考PutFile中的。

以下代码示例演示如何使用 put-repository-triggers

Amazon CLI

在存储库中添加或更新触发器

此示例演示如何使用已创建的 JSON 文件(此处名为 MyTriggers .json)更新名为 MySecondTrigger “MyFirstTrigger” 和 “” 的触发器,该文件包含名为的存储库的所有触发器的结构。 MyDemoRepo要了解如何获取现有触发器的 JSON,请参阅 get-repository-triggers 命令。

aws codecommit put-repository-triggers \ --repository-name MyDemoRepo file://MyTriggers.json

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" ] } ] }

输出:

{ "configurationId": "6fa51cd8-35c1-EXAMPLE" }

以下代码示例演示如何使用 tag-resource

Amazon CLI

向现有存储库添加 Amazon 标签

以下tag-resource示例使用两个标签对指定的存储库进行标记。

aws codecommit tag-resource \ --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo \ --tags Status=Secret,Team=Saanvi

此命令不生成任何输出。

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的向存储库添加标签

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考TagResource中的。

以下代码示例演示如何使用 test-repository-triggers

Amazon CLI

测试存储库中的触发器

此示例演示如何在名为的 Amazon CodeCommit 存储库中测试名为 MyFirstTrigger “” 的触发器 MyDemoRepo。在此示例中,存储库中的事件会触发来自亚马逊简单通知服务 (Amazon SNS) 主题的通知。

命令:

aws codecommit test-repository-triggers --repository-name MyDemoRepo --triggers name=MyFirstTrigger,destinationArn=arn:aws:sns:us-east-1:111111111111:MyCodeCommitTopic,branches=mainline,preprod,events=all

输出:

{ "successfulExecutions": [ "MyFirstTrigger" ], "failedExecutions": [] }

以下代码示例演示如何使用 untag-resource

Amazon CLI

从存储库中移除 Amazon 标签

以下untag-resource示例从名为的存储库中删除带有指定密钥的标签MyDemoRepo

aws codecommit untag-resource \ --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo \ --tag-keys Status

此命令不生成任何输出。

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的从存储库中移除标签

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UntagResource中的。

以下代码示例演示如何使用 update-approval-rule-template-content

Amazon CLI

更新批准规则模板的内容

以下update-approval-rule-template-content示例更改了指定批准规则模板的内容,以便为担任角色的CodeCommitReview用户重新定义批准池。

aws codecommit update-approval-rule-template-content \ --approval-rule-template-name 1-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/*\"]}]}"

输出:

{ "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" } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “管理批准规则模板”。

以下代码示例演示如何使用 update-approval-rule-template-description

Amazon CLI

更新批准规则模板的描述

以下update-approval-rule-template-description示例将指定批准规则模板的描述更改为Requires 1 approval for all pull requests from the CodeCommitReview pool。 :

aws codecommit update-approval-rule-template-description \ --approval-rule-template-name 1-approver-rule-for-all-pull-requests \ --approval-rule-template-description "Requires 1 approval for all pull requests from the CodeCommitReview pool"

输出:

{ "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" } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “管理批准规则模板”。

以下代码示例演示如何使用 update-approval-rule-template-name

Amazon CLI

更新批准规则模板的名称

以下update-approval-rule-template-name示例将批准规则模板的名称从更改为 1-approver-rule-for-all pull-re 1-approver-rule quests`。

aws codecommit update-approval-rule-template-name \ --old-approval-rule-template-name 1-approver-rule \ --new-approval-rule-template-name 1-approver-rule-for-all-pull-requests

输出:

{ "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" } }

有关更多信息,请参阅《Amazon CodeCommit 用户指南》中的 “管理批准规则模板”。

以下代码示例演示如何使用 update-comment

Amazon CLI

更新对提交的评论

此示例演示如何将内容添加"Fixed as requested. I'll update the pull request."到 ID 为的评论中442b498bEXAMPLE5756813

aws codecommit update-comment \ --comment-id 442b498bEXAMPLE5756813 \ --content "Fixed as requested. I'll update the pull request."

输出:

{ "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 } } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateComment中的。

以下代码示例演示如何使用 update-default-branch

Amazon CLI

更改存储库的默认分支

此示例更改了 Amazon CodeCommit 存储库的默认分支。该命令只在出现错误时生成输出。

命令:

aws codecommit update-default-branch --repository-name MyDemoRepo --default-branch-name MyNewBranch

输出:

None.

以下代码示例演示如何使用 update-pull-request-approval-rule-content

Amazon CLI

编辑拉取请求的批准规则

以下update-pull-request-approval-rule-content示例更新了她指定的批准规则,要求一个用户从包含123456789012 Amazon 账户中任何 IAM 用户的批准池中获得批准。

aws codecommit update-pull-request-approval-rule-content \ --pull-request-id 27 \ --approval-rule-name "Require two approved approvers" \ --approval-rule-content "{Version: 2018-11-08, Statements: [{Type: \"Approvers\", NumberOfApprovalsNeeded: 1, ApprovalPoolMembers:[\"CodeCommitApprovers:123456789012:user/*\"]}]}}"

输出:

{ "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", } }

有关更多信息,请参阅Amazon CodeCommit 用户指南中的编辑或删除批准规则

以下代码示例演示如何使用 update-pull-request-approval-state

Amazon CLI

批准或撤销对拉取请求的批准

以下update-pull-request-approval-state示例批准了 ID 为、修订版 ID 为27的拉取请求9f29d167EXAMPLE。如果您想改为撤销批准,请将--approval-state参数值设置为。REVOKE

aws codecommit update-pull-request-approval-state \ --pull-request-id 27 \ --revision-id 9f29d167EXAMPLE \ --approval-state "APPROVE"

此命令不生成任何输出。

有关更多信息,请参阅Amazon CodeCommit 用户指南中的查看拉取请求

以下代码示例演示如何使用 update-pull-request-description

Amazon CLI

更改拉取请求的描述

此示例演示如何更改 ID 为的拉取请求的描述47

aws codecommit update-pull-request-description \ --pull-request-id 47 \ --description "Updated the pull request to remove unused global variable."

输出:

{ "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" } }

以下代码示例演示如何使用 update-pull-request-status

Amazon CLI

更改拉取请求的状态

此示例演示如何在名为的 Amazon CodeCommit 存储库CLOSED中将 ID 42 为的拉取请求的状态更改为的状态MyDemoRepo

aws codecommit update-pull-request-status \ --pull-request-id 42 \ --pull-request-status CLOSED

输出:

{ "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" } }

以下代码示例演示如何使用 update-pull-request-title

Amazon CLI

更改拉取请求的标题

此示例演示如何更改 ID 为的拉取请求的标题47

aws codecommit update-pull-request-title \ --pull-request-id 47 \ --title "Consolidation of global variables - updated review"

输出:

{ "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" } }

以下代码示例演示如何使用 update-repository-description

Amazon CLI

更改存储库的描述

此示例更改了 Amazon CodeCommit 存储库的描述。该命令只在出现错误时生成输出。

命令:

aws codecommit update-repository-description --repository-name MyDemoRepo --repository-description "This description was changed"

输出:

None.

以下代码示例演示如何使用 update-repository-name

Amazon CLI

更改存储库的名称

此示例更改了 Amazon CodeCommit 存储库的名称。该命令只在出现错误时生成输出。更改 Amazon CodeCommit 存储库的名称将更改用户连接到存储库所需的 SSH 和 HTTPS 网址。在更新连接设置之前,用户无法连接到此存储库。此外,由于存储库的 ARN 会发生更改,更改存储库名称会使依赖该存储库 ARN 的所有 IAM 用户策略失效。

命令:

aws codecommit update-repository-name --old-name MyDemoRepo --new-name MyRenamedDemoRepo

输出:

None.