使用 的 CodeCommit 範例 AWS CLI - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 的 CodeCommit 範例 AWS CLI

下列程式碼範例示範如何使用 AWS Command Line Interface with CodeCommit 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然 動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例示範如何使用 associate-approval-rule-template-with-repository

AWS 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

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的將核准規則範本與儲存庫建立關聯

下列程式碼範例示範如何使用 batch-associate-approval-rule-template-with-repositories

AWS CLI

在單一操作中將核准規則範本與多個儲存庫建立關聯

下列batch-associate-approval-rule-template-with-repositories範例會將指定的核准規則範本與名為 MyDemoRepo和 的儲存庫建立關聯MyOtherDemoRepo

注意:核准規則範本是建立規則的 AWS 區域特有的。它們只能與該 AWS 區域中的儲存庫相關聯。

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的將核准規則範本與儲存庫建立關聯

下列程式碼範例示範如何使用 batch-describe-merge-conflicts

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的解決提取請求中的衝突

下列程式碼範例示範如何使用 batch-disassociate-approval-rule-template-from-repositories

AWS CLI

在單一操作中取消核准規則範本與多個儲存庫的關聯

下列batch-disassociate-approval-rule-template-from-repositories範例會將指定的核准規則範本與名為 MyDemoRepo和 的儲存庫取消關聯MyOtherDemoRepo

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的取消與核准規則範本的關聯

下列程式碼範例示範如何使用 batch-get-commits

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的檢視承諾詳細資訊

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 BatchGetCommits

下列程式碼範例示範如何使用 batch-get-repositories

AWS CLI

檢視多個儲存庫的詳細資訊

此範例顯示多個 AWS 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

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的建立核准規則範本

下列程式碼範例示範如何使用 create-branch

AWS CLI

建立分支

此範例會在 a AWS CodeCommit 儲存庫中建立分支。只有在發生錯誤時,此命令才會產生輸出。

命令:

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

輸出:

None.
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateBranch

下列程式碼範例示範如何使用 create-commit

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的建立 Commit inWordAWS CodeCommit

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateCommit

下列程式碼範例示範如何使用 create-pull-request-approval-rule

AWS CLI

為提取請求建立核准規則

下列create-pull-request-approval-rule範例會建立名為 的核准規則,Require two approved approvers用於指定的提取請求。規則指定需要兩個核准集區中的核准。集區包含透過CodeCommitReview123456789012 AWS 帳戶中擔任 角色來存取 CodeCommit 的所有使用者。它還包括Nikhil_Jayashankar來自相同 AWS 帳戶的 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" } }

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的建立核准規則

下列程式碼範例示範如何使用 create-pull-request

AWS CLI

建立提取請求

下列create-pull-request範例會建立名為「發音困難分析器」的提取請求,其中包含「請檢閱週二」的這些變更,其目標為「jane-branch」來源分支,並將合併到名為「MyDemoRepo」的 AWS CodeCommit 儲存庫中的預設分支「主要」。

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 詳細資訊,請參閱 AWS CLI 命令參考中的 CreatePullRequest

下列程式碼範例示範如何使用 create-repository

AWS CLI

建立儲存庫

此範例會建立儲存庫,並將其與使用者帳戶建立關聯 AWS 。

命令:

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 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateRepository

下列程式碼範例示範如何使用 create-unreferenced-merge-commit

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的解決提取請求中的衝突

下列程式碼範例示範如何使用 credential-helper

AWS CLI

若要設定包含在 AWS CLI with AWS CodeCommit 中的憑證協助程式

credential-helper 公用程式的設計並非直接從 AWS CLI 呼叫。反之,它旨在與 git config命令搭配使用作為參數,以設定本機電腦。它可讓 Git 使用 HTTPS 和密碼編譯簽署的 IAM 使用者憑證或 Amazon EC2 執行個體角色版本,只要 Git 需要與 進行身分驗證 AWS 才能與 CodeCommit 儲存庫互動。

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

輸出:

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

如需詳細資訊,請參閱 AWS CodeCommit AWS 使用者指南中的使用其他方法設定 forCodeCommit 。仔細檢閱內容,然後遵循下列其中一個主題中的程序:適用於 Linux 上的 HTTPS 連線、macOS 或 Unix,或適用於 HTTPS AWS 使用者指南中的 Windows 上的 CodeCommit 連線。

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CredentialHelper

下列程式碼範例示範如何使用 delete-approval-rule-template

AWS CLI

若要刪除核准規則範本

下列delete-approval-rule-template範例會刪除指定的核准規則範本。

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

輸出:

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的刪除核准規則範本

下列程式碼範例示範如何使用 delete-branch

AWS CLI

若要刪除分支

此範例說明如何刪除 an AWS CodeCommit 儲存庫中的分支。

命令:

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

輸出:

{ "branch": { "commitId": "317f8570EXAMPLE", "branchName": "MyNewBranch" } }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteBranch

下列程式碼範例示範如何使用 delete-comment-content

AWS 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

AWS CLI

若要刪除檔案

下列delete-file範例示範如何README.md從名為 的分支中刪除名為 的檔案,main該分支在名為 的儲存庫c5709475EXAMPLE中具有 的最新遞交 IDMyDemoRepo

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

如需詳細資訊,請參閱 Word AWS CodeCommit 參考指南中的編輯或刪除檔案 inWordAWS CodeCommit API

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteFile

下列程式碼範例示範如何使用 delete-pull-request-approval-rule

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的編輯或刪除核准規則

下列程式碼範例示範如何使用 delete-repository

AWS CLI

若要刪除儲存庫

此範例示範如何刪除 a AWS CodeCommit 儲存庫。

命令:

aws codecommit delete-repository --repository-name MyDemoRepo

輸出:

{ "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE" }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteRepository

下列程式碼範例示範如何使用 describe-merge-conflicts

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的解決提取請求中的衝突

下列程式碼範例示範如何使用 describe-pull-request-events

AWS 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

AWS 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

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的取消與核准規則範本的關聯

下列程式碼範例示範如何使用 evaluate-pull-request-approval-rules

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的合併提取請求

下列程式碼範例示範如何使用 get-approval-rule-template

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本

下列程式碼範例示範如何使用 get-blob

AWS CLI

檢視 Git blob 物件的相關資訊

下列get-blob範例會擷取名為 'MyDemoRepo' 的 an AWS CodeCommit 儲存庫中 ID 為 '2eb4af3bEXAMPLE' 的 Git blob 相關資訊。

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

輸出:

{ "content": "QSBCaW5hcnkgTGFyToEXAMPLE=" }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetBlob

下列程式碼範例示範如何使用 get-branch

AWS CLI

取得分支的相關資訊

此範例會取得有關 a AWS CodeCommit 儲存庫中分支的資訊。

命令:

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

輸出:

{ "BranchInfo": { "commitID": "317f8570EXAMPLE", "branchName": "MyNewBranch" } }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetBranch

下列程式碼範例示範如何使用 get-comment-reactions

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

如需詳細資訊,請參閱 Word 使用者指南中的對遞交 in AWS CodeCommit 的註解AWS CodeCommit

下列程式碼範例示範如何使用 get-comment

AWS 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 詳細資訊,請參閱 AWS CLI 命令參考中的 GetComment

下列程式碼範例示範如何使用 get-comments-for-compared-commit

AWS 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

AWS 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

AWS CLI

檢視儲存庫中遞交的相關資訊

此範例顯示在名為 'MyDemoRepo' 的 AWS CodeCommit 儲存庫中,系統產生的 ID 為 '7e9fd3091thisisanexamplethisisanexample1' 的遞交詳細資訊。

命令:

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 詳細資訊,請參閱 AWS CLI 命令參考中的 GetCommit

下列程式碼範例示範如何使用 get-differences

AWS CLI

取得儲存庫中遞交規範器差異的相關資訊

此範例顯示在名為 AWS CodeCommit MyDemoRepo 的重新命名資料夾中,檢視兩個遞交規格符 (分支、標籤、HEAD 或其他完全合格的參考,例如遞交 IDs) 之間變更的中繼資料資訊。此範例包含幾個不需要的選項,包括 --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 詳細資訊,請參閱 AWS CLI 命令參考中的 GetDifferences

下列程式碼範例示範如何使用 get-file

AWS CLI

若要取得 a AWS CodeCommit 儲存庫中檔案的 base-64 編碼內容

下列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 }

如需詳細資訊,請參閱 GetFile 參考指南中的 AWS APICodeCommit

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetFile

下列程式碼範例示範如何使用 get-folder

AWS CLI

若要取得 a AWS 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" }

如需詳細資訊,請參閱 GetFolder AWS 參考指南中的APICodeCommit

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetFolder

下列程式碼範例示範如何使用 get-merge-commit

AWS CLI

若要取得合併遞交的詳細資訊

下列get-merge-commit範例顯示名為 之來源分支的合併遞交詳細資訊,該來源分支bugfix-bug1234使用名為 main的 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" }

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的檢視承諾詳細資訊

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetMergeCommit

下列程式碼範例示範如何使用 get-merge-conflicts

AWS CLI

檢視提取請求是否有任何合併衝突

下列get-merge-conflicts範例顯示名為 的來源分支和名為 'main' 的feature-randomizationfeature目的地分支的儲存庫中,是否有任何合併衝突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 詳細資訊,請參閱 AWS CLI 命令參考中的 GetMergeConflicts

下列程式碼範例示範如何使用 get-merge-options

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的解決提取請求中的衝突

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetMergeOptions

下列程式碼範例示範如何使用 get-pull-request-approval-states

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的檢視提取請求

下列程式碼範例示範如何使用 get-pull-request-override-state

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的覆寫提取請求上的核准規則

下列程式碼範例示範如何使用 get-pull-request

AWS 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 詳細資訊,請參閱 AWS CLI 命令參考中的 GetPullRequest

下列程式碼範例示範如何使用 get-repository-triggers

AWS CLI

取得儲存庫中觸發程序的相關資訊

此範例顯示針對名為 的 AWS 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

AWS CLI

取得儲存庫的相關資訊

此範例顯示有關 a AWS 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 詳細資訊,請參閱 AWS CLI 命令參考中的 GetRepository

下列程式碼範例示範如何使用 list-approval-rule-templates

AWS CLI

列出 AWS 區域中的所有核准規則範本

下列list-approval-rule-templates範例列出指定區域中的所有核准規則範本。如果未將 AWS 區域指定為 參數,則命令會傳回用於執行命令的 AWS CLI 設定檔中指定區域的核准規則範本。

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

輸出:

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本

下列程式碼範例示範如何使用 list-associated-approval-rule-templates-for-repository

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本

下列程式碼範例示範如何使用 list-branches

AWS CLI

檢視分支名稱清單

此範例會列出 an AWS CodeCommit 儲存庫中的所有分支名稱。

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

輸出:

{ "branches": [ "MyNewBranch", "main" ] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListBranches

下列程式碼範例示範如何使用 list-pull-requests

AWS CLI

檢視儲存庫中的提取請求清單

此範例示範如何列出 IAM 使用者使用 ARN 'arn:aws:iam::111111111111:user/Li_Juan' 建立的提取請求,以及名為 'CLOSED' 的 an AWS 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 詳細資訊,請參閱 AWS CLI 命令參考中的 ListPullRequests

下列程式碼範例示範如何使用 list-repositories-for-approval-rule-template

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本

下列程式碼範例示範如何使用 list-repositories

AWS CLI

檢視儲存庫清單

此範例會列出與使用者帳戶相關聯的所有 AWS CodeCommit 儲存庫 AWS 。

命令:

aws codecommit list-repositories

輸出:

{ "repositories": [ { "repositoryName": "MyDemoRepo" "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE", }, { "repositoryName": "MyOtherDemoRepo" "repositoryId": "cfc29ac4-b0cb-44dc-9990-f6f51EXAMPLE" } ] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListRepositories

下列程式碼範例示範如何使用 list-tags-for-resource

AWS CLI

檢視儲存庫的 AWS 標籤

下列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" } }

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的檢視儲存庫的標籤

下列程式碼範例示範如何使用 merge-branches-by-fast-forward

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的比較和合併分支

下列程式碼範例示範如何使用 merge-branches-by-squash

AWS CLI

使用方形合併策略合併兩個分支

下列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" }

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的比較和合併分支

下列程式碼範例示範如何使用 merge-branches-by-three-way

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的比較和合併分支

下列程式碼範例示範如何使用 merge-pull-request-by-fast-forward

AWS CLI

若要合併和關閉提取請求

此範例示範如何在名為 的儲存庫中合併和關閉 ID 為 '47' 的提取請求,以及 ID 為 '99132ab0EXAMPLE' 的來源遞交 IDMyDemoRepo

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的合併提取請求

下列程式碼範例示範如何使用 merge-pull-request-by-squash

AWS CLI

使用壁式合併策略合併提取請求

下列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" } }

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的合併提取請求

下列程式碼範例示範如何使用 merge-pull-request-by-three-way

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的合併提取請求

下列程式碼範例示範如何使用 override-pull-request-approval-rules

AWS 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

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的覆寫提取請求上的核准規則

下列程式碼範例示範如何使用 post-comment-for-compared-commit

AWS 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

AWS CLI

將註解新增至提取請求

下列post-comment-for-pull-request範例新增了「這些「似乎沒有在任何地方使用」的註解。我們可以移除它們嗎?" 在名為 的儲存庫中使用 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

AWS 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 詳細資訊,請參閱 AWS CLI 命令參考中的 PostCommentReply

下列程式碼範例示範如何使用 put-comment-reaction

AWS CLI

使用表情符號回覆遞交的評論

下列put-comment-reaction範例會回應 ID 為 且表情符號反應值abcd1234EXAMPLEb5678efgh為 的註解:thumbsup:

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

此命令不會產生輸出。

如需詳細資訊,請參閱 Word 使用者指南中的對遞交 in AWS CodeCommit 的註解AWS CodeCommit

下列程式碼範例示範如何使用 put-file

AWS CLI

將檔案新增至儲存庫

下列put-file範例會將名為 'ExampleSolution.py' 的檔案新增至名為 'MyDemoRepo' 的儲存庫,其最近遞交的 ID 為 '4c925148EXAMPLE' 的名為 'feature-randomizationfeature' 的分支。

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 詳細資訊,請參閱 AWS CLI 命令參考中的 PutFile

下列程式碼範例示範如何使用 put-repository-triggers

AWS CLI

在儲存庫中新增或更新觸發程序

此範例示範如何使用已建立的 JSON 檔案 (此處名為 MyTriggers.json) 更新名為 'MyFirstTrigger' 和 'MySecondTrigger' 的觸發條件,其中包含名為 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

AWS CLI

將 AWS 標籤新增至現有儲存庫

下列tag-resource範例使用兩個標籤標記指定的儲存庫。

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

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的將標籤新增至儲存庫

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 TagResource

下列程式碼範例示範如何使用 test-repository-triggers

AWS CLI

在儲存庫中測試觸發條件

此範例示範如何在名為 MyFirstTrigger 的 AWS CodeCommit 儲存庫中測試名為 ' MyDemoRepo' 的觸發程序。在此範例中,儲存庫中的事件觸發來自 Amazon Simple Notification Service (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

AWS CLI

從儲存庫移除 AWS 標籤

下列untag-resource範例會從名為 的儲存庫中移除具有指定金鑰的標籤MyDemoRepo

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

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的從儲存庫移除標籤

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 UntagResource

下列程式碼範例示範如何使用 update-approval-rule-template-content

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本

下列程式碼範例示範如何使用 update-approval-rule-template-description

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本

下列程式碼範例示範如何使用 update-approval-rule-template-name

AWS CLI

更新核准規則範本的名稱

下列update-approval-rule-template-name範例會將核准規則範本的名稱從 1-approver-rule 變更為 1-approver-rule-for-all-pull-requests`。

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

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本

下列程式碼範例示範如何使用 update-comment

AWS CLI

更新遞交的評論

此範例示範如何將內容新增至 ID 為 的"Fixed as requested. I'll update the pull request."評論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 詳細資訊,請參閱 AWS CLI 命令參考中的 UpdateComment

下列程式碼範例示範如何使用 update-default-branch

AWS CLI

若要變更儲存庫的預設分支

此範例會變更 a AWS CodeCommit 儲存庫的預設分支。只有在發生錯誤時,此命令才會產生輸出。

命令:

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

輸出:

None.

下列程式碼範例示範如何使用 update-pull-request-approval-rule-content

AWS CLI

編輯提取請求的核准規則

下列update-pull-request-approval-rule-content範例會更新她指定的核准規則,要求從包含123456789012 AWS 帳戶中任何 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", } }

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的編輯或刪除核准規則

下列程式碼範例示範如何使用 update-pull-request-approval-state

AWS CLI

若要核准或撤銷提取請求的核准

下列update-pull-request-approval-state範例會核准 ID 為 27且修訂 ID 為 的提取請求9f29d167EXAMPLE。如果您想要改為撤銷核准,請將 --approval-state 參數值設定為 REVOKE

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

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的檢閱提取請求

下列程式碼範例示範如何使用 update-pull-request-description

AWS 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

AWS CLI

若要變更提取請求的狀態

此範例示範如何在名為 的 AWS 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

AWS 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

AWS CLI

若要變更儲存庫的描述

此範例會變更 a AWS CodeCommit 儲存庫的描述。只有在發生錯誤時,此命令才會產生輸出。

命令:

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

輸出:

None.

下列程式碼範例示範如何使用 update-repository-name

AWS CLI

若要變更儲存庫的名稱

此範例會變更 a AWS CodeCommit 儲存庫的名稱。只有在發生錯誤時,此命令才會產生輸出。變更 AWS CodeCommit 儲存庫的名稱會變更使用者連線到儲存庫所需的 SSH 和 HTTPS URLs。使用者將無法連接到此儲存庫,直到他們更新連線設定為止。此外,由於儲存庫的 ARN 會變更,因此變更儲存庫名稱會使任何依賴此儲存庫的 IAM 的 ARN 使用者政策失效。

命令:

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

輸出:

None.