使用 AWS CLI 的 CodeCommit 範例 - AWS Command Line Interface

使用 AWS CLI 的 CodeCommit 範例

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 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 範例會將指定的核准規則範本,與名為 MyDemoRepoMyOtherDemoRepo 的儲存庫建立關聯。

注意:核准規則範本專屬於建立這些範本的所在 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 範例判斷出在名為 MyDemoRepo 的儲存庫中,使用 THREE_WAY_MERGE 策略合併名為 feature-randomizationfeature 的來源分支,與名為 main 的目的地分支的合併衝突。

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 範例會將指定的核准規則範本,與名為 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": [] }

如需詳細資訊,請參閱《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

建立分支

此範例在 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 使用者指南》中的在 AWS CodeCommit 中建立遞交

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

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

AWS CLI

建立提取請求的核准規則

下列 create-pull-request-approval-rule 範例針對指定的提取請求,建立名為 Require two approved approvers 的核准規則。此規則指定需要有來自核准集區的兩個核准。集區包括藉由擔任 123456789012 AWS 帳戶中 CodeCommitReview 角色,存取 CodeCommit 的所有使用者。還包括相同 AWS 帳戶中,名為 Nikhil_Jayashankar 的 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 儲存庫中的預設分支“main”。

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 範例建立一個遞交,其代表在名為 MyDemoRepo 的儲存庫中,使用 THREE_WAY_MERGE 策略對名為 bugfix-1234 的來源分支,與名為 main 的目標分支進行合併的結果。

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 CodeCommit 設定 CLI AWS 中包含的憑證助手

credential-helper 公用程式的設計,並非直接從 AWS CLI 呼叫。反之,該公用程式旨在搭配 git config 命令當作參數使用,以設定您的本機電腦。每當 Git 需要透過 AWS 進行身分驗證,以與 CodeCommit 儲存庫互動時,您就可以允許 Git 使用 HTTPS,以及 IAM 使用者憑證或 Amazon EC2 執行個體角色的加密簽章版本。

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 CodeCommit」。仔細檢閱內容,然後遵循下列其中一個主題中的程序:適用於 Linux、macOS 或 Unix 上的 HTTPS 連線,或《AWS CodeCommit 使用者指南》中適用於 Windows 的 HTTPS 連線。

  • 如需 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

刪除分支

此範例示範如何刪除 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 範例展示如何從名為 main 的分支中,刪除名為 README.md 的檔案,而該分支在名為 MyDemoRepo 的儲存庫中具有 c5709475EXAMPLE 的最新遞交 ID。

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

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

  • 如需 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

刪除儲存庫

此範例示範如何刪除 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' 的 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

取得分支的相關資訊

此範例會取得 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" ] } ] } }

如需詳細資訊,請參閱《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

取得儲存庫中遞交指標差異的相關資訊

此範例顯示檢視名為 MyDemoRepo 的 AWS CodeCommit 儲存庫中重新命名的資料夾中,兩個遞交指標 (分支、標籤、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 詳細資訊,請參閱《AWS CLI 命令參考》中的 GetDifferences

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

AWS CLI

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

下列 get-file 範例展示如何從名為 MyDemoRepo 的儲存庫中,名為 main 的分支取得名為 README.md 之檔案的 base-64 編碼內容。

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 }

如需詳細資訊,請參閱《AWS CodeCommit API 參考》指南中的 GetFile

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

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

AWS CLI

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

如需詳細資訊,請參閱《AWS CodeCommit API 參考》指南中的 GetFolder。

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

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

AWS CLI

取得合併遞交的詳細資訊

下列 get-merge-commit 範例顯示,在名為 MyDemoRepo 儲存庫中名為 bugfix-bug1234 的來源分支,與名為 main 的目的地分支之合併遞交的詳細資訊。

aws codecommit get-merge-commit \ --source-commit-specifier bugfix-bug1234 \ --destination-commit-specifier main \ --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 範例顯示,在名為 MyDemoRepo 儲存庫中名為 feature-randomizationfeature 的來源分支尖端,與名為 'main' 的目的地分支之間,是否有任何合併衝突。

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 範例判定可用於合併名為 MyDemoRepo 的儲存庫中,名為 bugfix-bug1234 的來源分支與名為 main 的目的地分支的合併選項。

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

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

此範例顯示針對名為 MyDemoRepo 的 AWS CodeCommit 儲存庫而設定之觸發的詳細資訊。

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

取得儲存庫的相關資訊

此範例顯示 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 區域指定為參數,則命令會傳回用於執行命令之 CLI AWS 設定檔中,用於指定區域的核准規則範本。

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

檢視分支名稱的清單

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

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

輸出:

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

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

AWS CLI

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

此範例展示如何在名為 'MyDemoRepo' 的 AWS CodeCommit 儲存庫中列出 ARN 'arn:aws:iam::111111111111:user/Li_Juan',且狀態為 'CLOSED' 的 IAM 使用者所建立的提取請求:

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 帳戶相關聯的所有 AWS CodeCommit 儲存庫。

命令:

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

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

如需詳細資訊,請參閱《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

合併與關閉提取請求

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

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

使用 squash 合併策略合併提取請求

下列 merge-pull-request-by-squash 範例使用名為 MyDemoRepo 的儲存庫中 ACCEPT_SOURCE 的衝突解決策略,合併和關閉指定的提取請求。

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

建立對遞交的評論

此範例展示如何在名為 MyDemoRepo 的儲存庫中兩個遞交之間的比較中,將對於變更的評論 "Can you add a test case for this?" 新增至 cl_sample.js 檔案。

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 範例將對於變更的評論 "These don't appear to be used anywhere. Can we remove them?"(這些似乎沒有在任何地方使用過。是否可以移除?) 新增至名為 MyDemoRepo 之儲存庫中 ID 為 47 的提取請求中的 ahs_count.py 檔案。

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 abcd1234EXAMPLEb5678efgh 將回覆 "Good catch. I'll remove them." 新增至評論。

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:

此命令不會產生輸出。

如需詳細資訊,請參閱《AWS CodeCommit 使用者指南》中的在 AWS CodeCommit 評論遞交

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

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

AWS CLI

將檔案新增到儲存庫

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

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

在儲存庫中測試觸發

此範例展示如何在名為 MyDemoRepo 的 AWS CodeCommit 儲存庫中測試名為 'MyFirstTrigger' 的觸發。在此範例中,儲存庫中的事件會從 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

更新對遞交的評論

此範例展示如何將內容 "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 詳細資訊,請參閱《AWS CLI 命令參考》中的 UpdateComment

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

AWS CLI

變更儲存庫的預設分支

此範例會變更 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

變更提取請求的狀態

此範例展示如何將 ID 為 42 的提取請求狀態,變更為在名為 MyDemoRepo 的 AWS CodeCommit 儲存庫中的 CLOSED 狀態。

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

變更儲存庫的描述

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

命令:

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

輸出:

None.

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

AWS CLI

變更儲存庫的名稱

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

命令:

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

輸出:

None.