本文件 AWS CLI 僅適用於 第 1 版。如需 第 2 版的相關文件 AWS CLI,請參閱 第 2 版使用者指南。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 的 CodeCommit 範例 AWS CLI
下列程式碼範例示範如何使用 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-nameMyDemoRepo\ --approval-rule-template-name2-approver-rule-for-main此命令不會產生輸出。
如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的將核准規則範本與儲存庫建立關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 AssociateApprovalRuleTemplateWithRepository
。
-
以下程式碼範例顯示如何使用 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-namesMyDemoRepo,MyOtherDemoRepo\ --approval-rule-template-name2-approver-rule-for-main輸出:
{ "associatedRepositoryNames": [ "MyDemoRepo", "MyOtherDemoRepo" ], "errors": [] }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的將核准規則範本與儲存庫建立關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 BatchAssociateApprovalRuleTemplateWithRepositories
。
-
以下程式碼範例顯示如何使用 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-specifierfeature-randomizationfeature\ --destination-commit-specifiermain\ --merge-optionTHREE_WAY_MERGE\ --repository-nameMyDemoRepo輸出:
{ "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 使用者指南中的解決提取請求中的衝突。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 BatchDescribeMergeConflicts
。
-
以下程式碼範例顯示如何使用 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-namesMyDemoRepo,MyOtherDemoRepo\ --approval-rule-template-name1-approval-rule-for-allpullrequests輸出:
{ "disassociatedRepositoryNames": [ "MyDemoRepo", "MyOtherDemoRepo" ], "errors": [] }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的取消與核准規則範本的關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 BatchDisassociateApprovalRuleTemplateFromRepositories
。
-
以下程式碼範例顯示如何使用 batch-get-commits。
- AWS CLI
-
檢視多個遞交的相關資訊
下列
batch-get-commits範例顯示指定遞交的詳細資訊。aws codecommit batch-get-commits \ --repository-nameMyDemoRepo\ --commit-ids317f8570EXAMPLE4c925148EXAMPLE輸出:
{ "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-namesMyDemoRepoMyOtherDemoRepo輸出:
{ "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": [] }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 BatchGetRepositories
。
-
以下程式碼範例顯示如何使用 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-name2-approver-rule-for-main\ --approval-rule-template-description"Requires two developers from the team to approve the pull request if the destination branch is main"\ --approval-rule-template-content "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}"輸出:
{ "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 使用者指南中的建立核准規則範本。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateApprovalRuleTemplate
。
-
以下程式碼範例顯示如何使用 create-branch。
- AWS CLI
-
建立分支
此範例會在 AWS CodeCommit 儲存庫中建立分支。只有在發生錯誤時,此命令才會產生輸出。
命令:
aws codecommit create-branch --repository-nameMyDemoRepo--branch-nameMyNewBranch--commit-id317f8570EXAMPLE輸出:
None.-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateBranch
。
-
以下程式碼範例顯示如何使用 create-commit。
- AWS CLI
-
建立遞交
下列
create-commit範例示範如何為將readme.md檔案新增至main分支MyDemoRepo中名為 的儲存庫的儲存庫建立初始遞交。aws codecommit create-commit \ --repository-nameMyDemoRepo\ --branch-namemain\ --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": [] }如需詳細資訊,請參閱 CodeCommit 使用者指南中的在 AWS CodeCommit 中建立遞交。 AWS CodeCommit
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateCommit
。
-
以下程式碼範例顯示如何使用 create-pull-request-approval-rule。
- AWS CLI
-
為提取請求建立核准規則
下列
create-pull-request-approval-rule範例Require two approved approvers會為指定的提取請求建立名為 的核准規則。規則指定需要兩個核准集區中的核准。集區包含透過CodeCommitReview在123456789012AWS 帳戶中擔任 角色來存取 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 使用者指南中的建立核准規則。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreatePullRequestApprovalRule
。
-
以下程式碼範例顯示如何使用 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-token123Example\ --targetsrepositoryName=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-nameMyDemoRepo--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-specifierbugfix-1234\ --destination-commit-specifiermain\ --merge-optionTHREE_WAY_MERGE\ --repository-nameMyDemoRepo\ --name"Maria Garcia"\ --email"maria_garcia@example.com"\ --commit-message"Testing the results of this merge."輸出:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的解決提取請求中的衝突。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateUnreferencedMergeCommit
。
-
以下程式碼範例顯示如何使用 credential-helper。
- AWS CLI
-
使用 AWS CodeCommit 設定 CLI AWS 中包含的登入資料協助程式
credential-helper公用程式的設計並非直接從 CLI AWS 呼叫。反之,它旨在搭配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-name1-approver-for-all-pull-requests輸出:
{ "approvalRuleTemplateId": "41de97b7-EXAMPLE" }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的刪除核准規則範本。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteApprovalRuleTemplate
。
-
以下程式碼範例顯示如何使用 delete-branch。
- AWS CLI
-
刪除分支
此範例說明如何刪除 AWS CodeCommit 儲存庫中的分支。
命令:
aws codecommit delete-branch --repository-nameMyDemoRepo--branch-nameMyNewBranch輸出:
{ "branch": { "commitId": "317f8570EXAMPLE", "branchName": "MyNewBranch" } }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteBranch
。
-
以下程式碼範例顯示如何使用 delete-comment-content。
- AWS CLI
-
刪除評論的內容
您只能刪除您所建立評論的評論內容。此範例示範如何使用系統產生的 ID 刪除評論的內容
ff30b348EXAMPLEb9aa670f。aws codecommit delete-comment-content \ --comment-idff30b348EXAMPLEb9aa670f輸出:
{ "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 } } }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteCommentContent
。
-
以下程式碼範例顯示如何使用 delete-file。
- AWS CLI
-
刪除檔案
下列
delete-file範例示範如何README.md從名為 的分支中刪除名為 的檔案,main該分支在名為 的儲存庫c5709475EXAMPLE中具有 的最新遞交 IDMyDemoRepo。aws codecommit delete-file \ --repository-nameMyDemoRepo\ --branch-namemain\ --file-pathREADME.md\ --parent-commit-idc5709475EXAMPLE輸出:
{ "blobId":"559b44fEXAMPLE", "commitId":"353cf655EXAMPLE", "filePath":"README.md", "treeId":"6bc824cEXAMPLE" }如需詳細資訊,請參閱 AWS CodeCommit API 參考指南中的編輯或刪除檔案 inCodeCommitAWS 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-id15輸出:
{ "approvalRuleId": "077d8e8a8-EXAMPLE" }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的編輯或刪除核准規則。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeletePullRequestApprovalRule
。
-
以下程式碼範例顯示如何使用 delete-repository。
- AWS CLI
-
刪除儲存庫
此範例示範如何刪除 AWS CodeCommit 儲存庫。
命令:
aws codecommit delete-repository --repository-nameMyDemoRepo輸出:
{ "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-specifierfeature-randomizationfeature\ --destination-commit-specifiermain\ --merge-optionTHREE_WAY_MERGE\ --file-pathreadme.md\ --repository-nameMyDemoRepo輸出:
{ "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 使用者指南中的解決提取請求中的衝突。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DescribeMergeConflicts
。
-
以下程式碼範例顯示如何使用 describe-pull-request-events。
- AWS CLI
-
檢視提取請求中的事件
下列
describe-pull-request-events範例會擷取 ID 為 '8' 之提取請求的事件。aws codecommit describe-pull-request-events --pull-request-id8輸出:
{ "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" } ] }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DescribePullRequestEvents
。
-
以下程式碼範例顯示如何使用 disassociate-approval-rule-template-from-repository。
- AWS CLI
-
取消核准規則範本與儲存庫的關聯
下列
disassociate-approval-rule-template-from-repository範例會將指定的核准規則範本與名為 的儲存庫取消關聯MyDemoRepo。aws codecommit disassociate-approval-rule-template-from-repository \ --repository-nameMyDemoRepo\ --approval-rule-template-name1-approver-rule-for-all-pull-requests此命令不會產生輸出。
如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的取消與核准規則範本的關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DisassociateApprovalRuleTemplateFromRepository
。
-
以下程式碼範例顯示如何使用 evaluate-pull-request-approval-rules。
- AWS CLI
-
評估提取請求是否滿足其所有核准規則
下列
evaluate-pull-request-approval-rules範例會評估指定提取請求的核准規則狀態。在此範例中,提取請求尚未滿足核准規則,因此命令的輸出會顯示approved的值false。aws codecommit evaluate-pull-request-approval-rules \ --pull-request-id27\ --revision-id9f29d167EXAMPLE輸出:
{ "evaluation": { "approved": false, "approvalRulesNotSatisfied": [ "Require two approved approvers" ], "overridden": false, "approvalRulesSatisfied": [] } }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的合併提取請求。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 EvaluatePullRequestApprovalRules
。
-
以下程式碼範例顯示如何使用 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-name1-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 使用者指南中的管理核准規則範本。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetApprovalRuleTemplate
。
-
以下程式碼範例顯示如何使用 get-blob。
- AWS CLI
-
檢視 Git Blob 物件的相關資訊
下列
get-blob範例會在名為 'MyDemoRepo' 的CodeCommit 儲存庫中,擷取 ID 為 '2eb4af3bEXAMPLE' 的 Git Blob 相關資訊。 AWS CodeCommitaws codecommit get-blob --repository-nameMyDemoRepo--blob-id2eb4af3bEXAMPLE輸出:
{ "content": "QSBCaW5hcnkgTGFyToEXAMPLE=" }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetBlob
。
-
以下程式碼範例顯示如何使用 get-branch。
- AWS CLI
-
取得分支的相關資訊
此範例會取得 AWS CodeCommit 儲存庫中分支的相關資訊。
命令:
aws codecommit get-branch --repository-nameMyDemoRepo--branch-nameMyNewBranch輸出:
{ "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-idabcd1234EXAMPLEb5678efgh輸出:
{ "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 使用者指南中的對 inCodeCommit 遞交的註解。 AWS CodeCommit
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetCommentReactions
。
-
以下程式碼範例顯示如何使用 get-comment。
- AWS CLI
-
檢視註解的詳細資訊
此範例示範如何使用系統產生的註解 ID 來檢視註解的詳細資訊
ff30b348EXAMPLEb9aa670f。aws codecommit get-comment \ --comment-idff30b348EXAMPLEb9aa670f輸出:
{ "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-nameMyDemoRepo\ --before-commit-ID6e147360EXAMPLE\ --after-commit-id317f8570EXAMPLE輸出:
{ "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" }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetCommentsForComparedCommit
。
-
以下程式碼範例顯示如何使用 get-comments-for-pull-request。
- AWS CLI
-
檢視提取請求的註解
此範例示範如何在名為 的儲存庫中檢視提取請求的註解
MyDemoRepo。aws codecommit get-comments-for-pull-request \ --repository-nameMyDemoRepo\ --before-commit-ID317f8570EXAMPLE\ --after-commit-id5d036259EXAMPLE輸出:
{ "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" }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetCommentsForPullRequest
。
-
以下程式碼範例顯示如何使用 get-commit。
- AWS CLI
-
檢視儲存庫中遞交的相關資訊
此範例顯示在名為 'MyDemoRepo' 的 AWS CodeCommit 儲存庫中,系統產生 ID 為 '7e9fd3091thisisanexamplethisisanexample1' 的遞交詳細資訊。
命令:
aws codecommit get-commit --repository-nameMyDemoRepo--commit-id7e9fd3091thisisanexamplethisisanexample1輸出:
{ "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-nameMyDemoRepo--before-commit-specifier955bba12thisisanexamplethisisanexample--after-commit-specifier14a95463thisisanexamplethisisanexample--before-pathtmp/example-folder--after-pathtmp/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範例示範如何README.md從名為 的儲存庫main中名為 的分支取得名為 之檔案的 base-64 編碼內容MyDemoRepo。aws codecommit get-file \ --repository-nameMyDemoRepo\ --commit-specifiermain\ --file-pathREADME.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-nameMyDemoRepo--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範例顯示名為 之來源分支bugfix-bug1234與名為 之儲存庫main中名為 之目的地分支合併遞交的詳細資訊MyDemoRepo。aws codecommit get-merge-commit \ --source-commit-specifierbugfix-bug1234\ --destination-commit-specifiermain\ --repository-nameMyDemoRepo輸出:
{ "sourceCommitId": "c5709475EXAMPLE", "destinationCommitId": "317f8570EXAMPLE", "baseCommitId": "fb12a539EXAMPLE", "mergeCommitId": "ffc4d608eEXAMPLE" }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的檢視遞交詳細資訊。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetMergeCommit
。
-
以下程式碼範例顯示如何使用 get-merge-conflicts。
- AWS CLI
-
檢視提取請求是否有任何合併衝突
下列
get-merge-conflicts範例顯示名為 的來源分支尖端feature-randomizationfeature與名為 'main' 的目的地分支在名為 的儲存庫中是否有任何合併衝突MyDemoRepo。aws codecommit get-merge-conflicts \ --repository-nameMyDemoRepo\ --source-commit-specifierfeature-randomizationfeature\ --destination-commit-specifiermain\ --merge-optionTHREE_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-specifierbugfix-bug1234\ --destination-commit-specifiermain\ --repository-nameMyDemoRepo輸出:
{ "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-id8\ --revision-id9f29d167EXAMPLE輸出:
{ "approvals": [ { "userArn": "arn:aws:iam::123456789012:user/Mary_Major", "approvalState": "APPROVE" } ] }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的檢視提取請求。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetPullRequestApprovalStates
。
-
以下程式碼範例顯示如何使用 get-pull-request-override-state。
- AWS CLI
-
取得提取請求覆寫狀態的相關資訊
下列
get-pull-request-override-state範例會傳回指定提取請求的覆寫狀態。在此範例中,提取請求的核准規則已由名為 Mary Major 的使用者覆寫,因此輸出會傳回 的值true。:aws codecommit get-pull-request-override-state \ --pull-request-id34\ --revision-id9f29d167EXAMPLE輸出:
{ "overridden": true, "overrider": "arn:aws:iam::123456789012:user/Mary_Major" }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的覆寫提取請求的核准規則。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetPullRequestOverrideState
。
-
以下程式碼範例顯示如何使用 get-pull-request。
- AWS CLI
-
檢視提取請求的詳細資訊
此範例示範如何檢視 ID 為 之提取請求的相關資訊
27。aws codecommit get-pull-request \ --pull-request-id27輸出:
{ "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-nameMyDemoRepo輸出:
{ "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" ] } ] }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetRepositoryTriggers
。
-
以下程式碼範例顯示如何使用 get-repository。
- AWS CLI
-
取得儲存庫的相關資訊
此範例顯示有關 AWS CodeCommit 儲存庫的詳細資訊。
aws codecommit get-repository \ --repository-nameMyDemoRepo輸出:
{ "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 \ --regionus-east-2輸出:
{ "approvalRuleTemplateNames": [ "2-approver-rule-for-main", "1-approver-rule-for-all-pull-requests" ] }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListApprovalRuleTemplates
。
-
以下程式碼範例顯示如何使用 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-nameMyDemoRepo輸出:
{ "approvalRuleTemplateNames": [ "2-approver-rule-for-main", "1-approver-rule-for-all-pull-requests" ] }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListAssociatedApprovalRuleTemplatesForRepository
。
-
以下程式碼範例顯示如何使用 list-branches。
- AWS CLI
-
檢視分支名稱清單
此範例會列出 AWS CodeCommit 儲存庫中的所有分支名稱。
aws codecommit list-branches \ --repository-nameMyDemoRepo輸出:
{ "branches": [ "MyNewBranch", "main" ] }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListBranches
。
-
以下程式碼範例顯示如何使用 list-pull-requests。
- AWS CLI
-
檢視儲存庫中的提取請求清單
此範例示範如何列出 ARN 為 'arn:aws:iam::111111111111:user/Li_Juan' 的 IAM 使用者所建立的提取請求,以及名為 'MyDemoRepo' 的 AWS CodeCommit 儲存庫中的 'CLOSED' 狀態:
aws codecommit list-pull-requests --author-arnarn:aws:iam::111111111111:user/Li_Juan--pull-request-statusCLOSED--repository-nameMyDemoRepo輸出:
{ "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-name2-approver-rule-for-main輸出:
{ "repositoryNames": [ "MyDemoRepo", "MyClonedRepo" ] }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的管理核准規則範本。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListRepositoriesForApprovalRuleTemplate
。
-
以下程式碼範例顯示如何使用 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-arnarn:aws:codecommit:us-west-2:111111111111:MyDemoRepo輸出:
{ "tags": { "Status": "Secret", "Team": "Saanvi" } }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的檢視儲存庫的標籤。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 ListTagsForResource
。
-
以下程式碼範例顯示如何使用 merge-branches-by-fast-forward。
- AWS CLI
-
使用快轉合併策略合併兩個分支
下列
merge-branches-by-fast-forward範例會將指定的來源分支與名為 的儲存庫中指定的目的地分支合併MyDemoRepo。aws codecommit merge-branches-by-fast-forward \ --source-commit-specifierbugfix-bug1234\ --destination-commit-specifierbugfix-bug1233\ --repository-nameMyDemoRepo輸出:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的比較和合併分支。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 MergeBranchesByFastForward
。
-
以下程式碼範例顯示如何使用 merge-branches-by-squash。
- AWS CLI
-
使用 squash 合併策略合併兩個分支
下列
merge-branches-by-squash範例會將指定的來源分支與名為 的儲存庫中的指定目的地分支合併MyDemoRepo。aws codecommit merge-branches-by-squash \ --source-commit-specifierbugfix-bug1234\ --destination-commit-specifierbugfix-bug1233\ --author-name"Maria Garcia"\ --email"maria_garcia@example.com"\ --commit-message"Merging two fix branches to prepare for a general patch."\ --repository-nameMyDemoRepo輸出:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的比較和合併分支。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 MergeBranchesBySquash
。
-
以下程式碼範例顯示如何使用 merge-branches-by-three-way。
- AWS CLI
-
使用三向合併策略合併兩個分支
下列
merge-branches-by-three-way範例會將指定的來源分支與名為 的儲存庫中的指定目的地分支合併MyDemoRepo。aws codecommit merge-branches-by-three-way \ --source-commit-specifiermain\ --destination-commit-specifierbugfix-bug1234\ --author-name"Jorge Souza"--email"jorge_souza@example.com"\ --commit-message"Merging changes from main to bugfix branch before additional testing."\ --repository-nameMyDemoRepo輸出:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的比較和合併分支。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 MergeBranchesByThreeWay
。
-
以下程式碼範例顯示如何使用 merge-pull-request-by-fast-forward。
- AWS CLI
-
合併和關閉提取請求
此範例示範如何在名為 的儲存庫中合併和關閉 ID 為 '47' 和來源遞交 ID 為 '99132ab0EXAMPLE' 的提取請求
MyDemoRepo。aws codecommit merge-pull-request-by-fast-forward \ --pull-request-id47\ --source-commit-id99132ab0EXAMPLE\ --repository-nameMyDemoRepo輸出:
{ "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 使用者指南中的合併提取請求。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 MergePullRequestByFastForward
。
-
以下程式碼範例顯示如何使用 merge-pull-request-by-squash。
- AWS CLI
-
使用 squash 合併策略合併提取請求
下列
merge-pull-request-by-squash範例會使用名為 的儲存庫中 ACCEPT_SOURCE 的衝突解決策略合併和關閉指定的提取請求MyDemoRepo。aws codecommit merge-pull-request-by-squash \ --pull-request-id47\ --source-commit-id99132ab0EXAMPLE\ --repository-nameMyDemoRepo\ --conflict-detail-levelLINE_LEVEL\ --conflict-resolution-strategyACCEPT_SOURCE\ --name"Jorge Souza"--email"jorge_souza@example.com"\ --commit-message"Merging pull request 47 by squash and accepting source in merge conflicts"輸出:
{ "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 使用者指南中的合併提取請求。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 MergePullRequestBySquash
。
-
以下程式碼範例顯示如何使用 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-id47\ --source-commit-id99132ab0EXAMPLE\ --repository-nameMyDemoRepo\ --name"Maria Garcia"\ --email"maria_garcia@example.com"\ --commit-message"Merging pull request 47 by three-way with default options"輸出:
{ "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 使用者指南中的合併提取請求。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 MergePullRequestByThreeWay
。
-
以下程式碼範例顯示如何使用 override-pull-request-approval-rules。
- AWS CLI
-
覆寫提取請求的核准規則需求
下列
override-pull-request-approval-rules範例會覆寫指定提取請求的核准規則。若要撤銷覆寫,請將--override-status參數值設定為REVOKE。aws codecommit override-pull-request-approval-rules \ --pull-request-id34\ --revision-id927df8d8EXAMPLE\ --override-statusOVERRIDE此命令不會產生輸出。
如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的覆寫提取請求的核准規則。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 OverridePullRequestApprovalRules
。
-
以下程式碼範例顯示如何使用 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-nameMyDemoRepo\ --before-commit-id317f8570EXAMPLE\ --after-commit-id5d036259EXAMPLE\ --client-request-token123Example\ --content"Can you add a test case for this?"\ --locationfilePath=cl_sample.js,filePosition=1232,relativeFileVersion=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" } }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 PostCommentForComparedCommit
。
-
以下程式碼範例顯示如何使用 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-nameMyDemoRepo\ --before-commit-id317f8570EXAMPLE\ --after-commit-id5d036259EXAMPLE\ --client-request-token123Example\ --content"These don't appear to be used anywhere. Can we remove them?"\ --locationfilePath=ahs_count.py,filePosition=367,relativeFileVersion=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" }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 PostCommentForPullRequest
。
-
以下程式碼範例顯示如何使用 post-comment-reply。
- AWS CLI
-
回覆遞交或提取請求中的註解
此範例示範如何使用系統產生的 ID
"Good catch. I'll remove them."將回覆新增至註解abcd1234EXAMPLEb5678efgh。aws codecommit post-comment-reply \ --in-reply-toabcd1234EXAMPLEb5678efgh\ --content"Good catch. I'll remove them."\ --client-request-token123Example輸出:
{ "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-idabcd1234EXAMPLEb5678efgh\ --reaction-value:thumbsup:此命令不會產生輸出。
如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的對遞交 inCodeCommit 的註解。 AWS CodeCommit
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 PutCommentReaction
。
-
以下程式碼範例顯示如何使用 put-file。
- AWS CLI
-
將檔案新增至儲存庫
下列
put-file範例會將名為 'ExampleSolution.py' 的檔案新增至名為 'MyDemoRepo' 的儲存庫,其最近遞交的 ID 為 '4c925148EXAMPLE' 的名為 'feature-randomizationfeature' 的分支。aws codecommit put-file \ --repository-nameMyDemoRepo\ --branch-namefeature-randomizationfeature\ --file-contentfile://MyDirectory/ExampleSolution.py\ --file-path/solutions/ExampleSolution.py\ --parent-commit-id4c925148EXAMPLE\ --name"Maria Garcia"\ --email"maria_garcia@example.com"\ --commit-message"I added a third randomization routine."輸出:
{ "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-nameMyDemoRepofile://MyTriggers.jsonMyTriggers.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" }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 PutRepositoryTriggers
。
-
以下程式碼範例顯示如何使用 tag-resource。
- AWS CLI
-
將 AWS 標籤新增至現有的儲存庫
下列
tag-resource範例使用兩個標籤來標記指定的儲存庫。aws codecommit tag-resource \ --resource-arnarn:aws:codecommit:us-west-2:111111111111:MyDemoRepo\ --tagsStatus=Secret,Team=Saanvi此命令不會產生輸出。
如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的將標籤新增至儲存庫。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 TagResource
。
-
以下程式碼範例顯示如何使用 test-repository-triggers。
- AWS CLI
-
在儲存庫中測試觸發
此範例示範如何在名為 MyDemoRepo 的CodeCommit 儲存庫中測試名為 'MyFirstTrigger' 的觸發。 AWS CodeCommit MyDemoRepo 在此範例中,儲存庫中的事件會從 Amazon Simple Notification Service (Amazon SNS) 主題觸發通知。
命令:
aws codecommit test-repository-triggers --repository-nameMyDemoRepo--triggersname=MyFirstTrigger,destinationArn=arn:aws:sns:us-east-1:111111111111:MyCodeCommitTopic,branches=mainline,preprod,events=all輸出:
{ "successfulExecutions": [ "MyFirstTrigger" ], "failedExecutions": [] }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 TestRepositoryTriggers
。
-
以下程式碼範例顯示如何使用 untag-resource。
- AWS CLI
-
從儲存庫移除 AWS 標籤
下列
untag-resource範例會從名為 的儲存庫中移除具有指定金鑰的標籤MyDemoRepo。aws codecommit untag-resource \ --resource-arnarn:aws:codecommit:us-west-2:111111111111:MyDemoRepo\ --tag-keysStatus此命令不會產生輸出。
如需詳細資訊,請參閱 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-name1-approver-rule\ --new-rule-content "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}"輸出:
{ "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 使用者指南中的管理核准規則範本。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateApprovalRuleTemplateContent
。
-
以下程式碼範例顯示如何使用 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-name1-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 使用者指南中的管理核准規則範本。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateApprovalRuleTemplateDescription
。
-
以下程式碼範例顯示如何使用 update-approval-rule-template-name。
- AWS CLI
-
更新核准規則範本的名稱
下列
update-approval-rule-template-name範例會將核准規則範本的名稱從 變更為1-approver-rule1-approver-rule-for-all-pull-requests`。aws codecommit update-approval-rule-template-name \ --old-approval-rule-template-name1-approver-rule\ --new-approval-rule-template-name1-approver-rule-for-all-pull-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 使用者指南中的管理核准規則範本。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateApprovalRuleTemplateName
。
-
以下程式碼範例顯示如何使用 update-comment。
- AWS CLI
-
更新遞交的註解
此範例示範如何將內容新增至 ID 為 的
"Fixed as requested. I'll update the pull request."評論442b498bEXAMPLE5756813。aws codecommit update-comment \ --comment-id442b498bEXAMPLE5756813\ --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-nameMyDemoRepo--default-branch-nameMyNewBranch輸出:
None.-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateDefaultBranch
。
-
以下程式碼範例顯示如何使用 update-pull-request-approval-rule-content。
- AWS CLI
-
編輯提取請求的核准規則
下列
update-pull-request-approval-rule-content範例會更新她指定的核准規則,要求核准集區中包含123456789012AWS 帳戶中任何 IAM 使用者的使用者核准。aws codecommit update-pull-request-approval-rule-content \ --pull-request-id27\ --approval-rule-name"Require two approved approvers"\ --approval-rule-content "{Version: 2018-11-08, Statements: [{Type: \"Approvers\", NumberOfApprovalsNeeded: 1, ApprovalPoolMembers:[\"CodeCommitApprovers:123456789012:user/*\"]}]}}"輸出:
{ "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 使用者指南中的編輯或刪除核准規則。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdatePullRequestApprovalRuleContent
。
-
以下程式碼範例顯示如何使用 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-id27\ --revision-id9f29d167EXAMPLE\ --approval-state"APPROVE"此命令不會產生輸出。
如需詳細資訊,請參閱 AWS CodeCommit 使用者指南中的檢閱提取請求。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdatePullRequestApprovalState
。
-
以下程式碼範例顯示如何使用 update-pull-request-description。
- AWS CLI
-
變更提取請求的描述
此範例示範如何變更 ID 為 的提取請求描述
47。aws codecommit update-pull-request-description \ --pull-request-id47\ --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" } }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdatePullRequestDescription
。
-
以下程式碼範例顯示如何使用 update-pull-request-status。
- AWS CLI
-
變更提取請求的狀態
此範例示範如何在名為 的 AWS CodeCommit 儲存庫
CLOSED中,將 ID42為 的提取請求狀態變更為 狀態MyDemoRepo。aws codecommit update-pull-request-status \ --pull-request-id42\ --pull-request-statusCLOSED輸出:
{ "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" } }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdatePullRequestStatus
。
-
以下程式碼範例顯示如何使用 update-pull-request-title。
- AWS CLI
-
變更提取請求的標題
此範例示範如何變更 ID 為 的提取請求標題
47。aws codecommit update-pull-request-title \ --pull-request-id47\ --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" } }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdatePullRequestTitle
。
-
以下程式碼範例顯示如何使用 update-repository-description。
- AWS CLI
-
變更儲存庫的描述
此範例會變更 AWS CodeCommit 儲存庫的描述。只有在發生錯誤時,此命令才會產生輸出。
命令:
aws codecommit update-repository-description --repository-nameMyDemoRepo--repository-description"This description was changed"輸出:
None.-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateRepositoryDescription
。
-
以下程式碼範例顯示如何使用 update-repository-name。
- AWS CLI
-
變更儲存庫的名稱
此範例會變更 AWS CodeCommit 儲存庫的名稱。只有在發生錯誤時,此命令才會產生輸出。變更 AWS CodeCommit 儲存庫的名稱會變更使用者連線到儲存庫所需的 SSH 和 HTTPS URLs。使用者將無法連接到此儲存庫,直到他們更新連線設定為止。此外,由於儲存庫的 ARN 將會變更,因此變更儲存庫名稱會使依賴此儲存庫 ARN 的任何 IAM 使用者政策失效。
命令:
aws codecommit update-repository-name --old-nameMyDemoRepo--new-nameMyRenamedDemoRepo輸出:
None.-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateRepositoryName
。
-