

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

# 檢閱提取請求
<a name="how-to-review-pull-request"></a>

您可以使用 AWS CodeCommit 主控台來檢閱提取請求中包含的變更。您可以對請求、檔案，以及個別的程式碼行新增評論。您也可以回覆其他使用者的評論。如果您的儲存庫[已設定通知](how-to-repository-email.md)，當使用者回覆您的評論或是當使用者對提取請求加上評論時，您會收到電子郵件。

您可以使用 AWS CLI 對提取請求進行註解，並回覆註解。若要檢閱變更，您必須使用 CodeCommit 主控台、 **git diff**命令或 diff 工具。

**Topics**
+ [檢閱提取請求 （主控台）](#how-to-review-pull-request-console)
+ [檢閱提取請求 (AWS CLI)](#how-to-review-pull-request-cli)

## 檢閱提取請求 （主控台）
<a name="how-to-review-pull-request-console"></a>

您可以使用 CodeCommit 主控台來檢閱 CodeCommit 儲存庫中的提取請求。

1. 在 https：//[https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home) 開啟 CodeCommit 主控台。

1. 在 **Repositories (儲存庫)** 中，選擇儲存庫的名稱。

1. 在導覽窗格中，選擇 **Pull requests (提取請求)**。

1. 依預設，會顯示所有開啟的提取請求清單。選擇您想要檢閱的開啟中提取請求。  
![開啟 CodeCommit 主控台中顯示的提取請求。](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-pull-request-view-list.png)
**注意**  
您可以對已關閉或合併的提取請求作評論，但無法合併或重新開啟該提取請求。

1. 在提取請求中，選擇 **Changes (變更)**。

1. 執行以下任意一項：
   + 若要對整個提取請求加上一般性評論，請在 **Comments on changes (對變更加上評論)** 的 **New comment (新增評論)** 中，輸入評論，然後選擇 **Save (儲存)**。您可以使用 [Markdown](https://docs.aws.amazon.com/general/latest/gr/aws-markdown.html)，或也可以純文字輸入您的評論。  
![對提取請求中變更的一般評論。](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-commenting-changecomment.png)
   + 若要對遞交中的檔案新增評論，請在 **Changes (變更)** 中找到檔案的名稱。選擇檔案名稱旁顯示的評論圖示 ![The comment bubble icon that that indicates that you can leave a comment on that line of code.](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-commentbubble.png)，輸入評論，然後選擇 **Save (儲存)**。  
![對提取請求中的檔案新增評論。](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-commenting-addfilecomment.png)
   + 若要對提取請求中變更的行新增評論，在 **Changes (變更)** 中，移至您要加上評論的行。選擇該行顯示的評論圖示 ![The comment bubble icon that that indicates that you can leave a comment on that line of code.](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-commentbubble.png)，輸入評論，然後選擇 **Save (儲存)**。  
![對提取請求中的行新增評論。](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-pull-request-comment.png)

1. 若要回覆對遞交的評論，在 **Changes (變更)** 或 **Activity (活動)** 中，選擇 **Reply (回覆)**。您可以使用文字和表情符號來回覆 。  
![將回應和表情符號反應新增至註解。](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-commenting-commenttab.png)

   您可以選擇回應特定表情符號回應的人員名稱。若要檢視所有表情符號反應，以及誰回應哪些表情符號的相關資訊，請選擇**檢視所有反應**。如果您已使用表情符號回應註解，您的回應會顯示在表情符號反應按鈕的 圖示中。
**注意**  
在載入頁面時，主控台中顯示的反應計數是準確的。如需表情符號反應計數的最新資訊，請重新整理頁面，或選擇**檢視所有反應**。  
![檢視使用表情符號反應回應評論之使用者的相關資訊。](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-comment-view-reaction.png)

1. （選用） 若要回覆 Amazon CodeGuru Reviewer 建立的建議，包括提供建議品質的意見回饋，請選擇**回覆**。使用反應按鈕，提供有關您是否核准或拒絕建議的一般資訊。使用評論欄位提供有關反應的更多詳細資料。
**注意**  
Amazon CodeGuru Reviewer 是一種自動化程式碼檢閱服務，使用程式分析和機器學習來偵測常見問題，並建議修正 Java 或 Python 程式碼。  
只有在您已將儲存庫與 Amazon CodeGuru Reviewer 建立關聯、分析完成，以及提取請求中的程式碼為 Java 或 Python 程式碼時，您才會看到 Amazon CodeGuru Reviewer 註解。如需詳細資訊，請參閱[將儲存 AWS CodeCommit 庫與 Amazon CodeGuru Reviewer 建立關聯或取消關聯](how-to-amazon-codeguru-reviewer.md)。
只有在對提取請求的最近修訂做出註解時，Amazon CodeGuru Reviewer 註解才會出現在**變更**索引標籤中。它們一律會出現在**活動**索引標籤中。
雖然您可以使用任何可用的表情符號反應來回應 Amazon CodeGuru Reviewer 建議，但只會使用大拇指和大拇指來評估建議的實用性。  
![由 Amazon CodeGuru Reviewer 建立並正在進行檢閱任務的建議。](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-pull-request-reply-bot.png)

1. 若要核准提取請求中所做的變更，請選擇 **Approve (核准)**。
**注意**  
您無法核准您建立的提取請求。

   您可以在 **Approvals (核准)** 中檢視核准、提取請求的核准規則、以及由核准規則範本建立的核准規則。如果您最後決定不要核准提取請求，您可以選擇 **Revoke approval (撤銷核准)**。
**注意**  
您只能核准或撤銷未結案提取請求的核准。如果提取請求的狀態為 Merged (已合併) 或 Closed (已關閉)，您無法核准或撤銷核准。  
![提取請求中的核准與核准規則。](http://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/images/codecommit-approval-rule-met.png)

## 檢閱提取請求 (AWS CLI)
<a name="how-to-review-pull-request-cli"></a>

若要搭配 CodeCommit 使用 AWS CLI 命令，請安裝 AWS CLI。如需詳細資訊，請參閱[命令列參考](cmd-ref.md)。

您可以使用下列 AWS CLI 命令檢閱提取請求：
+ [**post-comment-for-pull-request**](#post-comment-reply)，將註解新增至提取請求
+ [**get-comments-for-pull-request**](#get-comments-for-pull-request)，檢視提取請求上留下的評論
+ [**update-pull-request-approval-state**](#update-pull-request-approval-state)，以核准或撤銷提取請求的核准
+ [**post-comment-reply**](#post-comment-reply)，以回覆提取請求中的註解

您也可以在具有下列命令的提取請求中使用具有註解的表情符號：
+ 若要使用表情符號回覆註解，請執行 [**put-comment-reaction**](how-to-commit-comment.md#how-to-commit-comment-cli-commit-reply-emoji)。
+ 若要檢視註解的表情符號反應，請執行 [**get-comment-reactions**](how-to-commit-comment.md#how-to-commit-comment-cli-commit-emoji-view)。

**使用 AWS CLI 來檢閱 CodeCommit 儲存庫中的提取請求**

1. 若要將評論新增至儲存庫中的提取請求，請執行 **post-comment-for-pull-request** 命令，指定：
   + 提取請求的 ID (使用 **--pull-request-id** 選項)。
   + 包含提取請求的儲存庫名稱 (使用 **--repository-name** 選項)。
   + 將合併提取請求所在目的地分支中遞交的完整遞交 ID (使用 **--before-commit-id** 選項)。
   + 當您張貼評論時，為提取請求分支目前頂端的來源分支中遞交的完整遞交 ID (使用 **--after-commit-id** 選項)。
   + 唯一的用戶端產生冪等符記 (使用 **--client-request-token** 選項)。
   + 評論的內容 (使用 **--content** 選項)。
   + 可放置評論位置的清單位置相關資訊，包括：
     + 要比較的檔案名稱，包括其副檔名和子目錄 (如果有) (使用 **filePath** 屬性)。
     + 比較檔案中變更的行號 (使用 **filePosition** 屬性)。
     + 對變更的評論在來源與目的地分支之間比較中為 "before" 或 "after" (使用 **relativeFileVersion** 屬性)。

   例如，使用此命令來新增註解{{「這些似乎不會在任何地方使用。我們是否可以移除它們？」}} 在名為 {{MyDemoRepo}} 的儲存庫中，提取請求中的 {{ahs\_count.py}} 檔案變更 ID 為 {{47}}。

   ```
   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,
                  "lastModifiedDate": 1508369622.123,
                  "callerReactions": [],
                  "reactionCounts": []
               }
                "location": { 
                  "filePath": "ahs_count.py",
                  "filePosition": 367,
                  "relativeFileVersion": "AFTER"
                },
            "repositoryName": "MyDemoRepo",
            "pullRequestId": "47"
    }
   ```

1. 若要檢視提取請求的評論，請執行 **get-comments-for-pull-request** 命令，指定：
   + CodeCommit 儲存庫的名稱 （使用 `--repository-name`選項）。
   + 系統產生的提取請求 ID (使用 `--pull-request-id` 選項)。
   + (選用) 用來傳回下一個批次結果的列舉符記 (使用 `--next-token` 選項)。
   + (選用) 一個非負整數，用來限制傳回的結果 (使用 `--max-results` 選項)。

   例如，使用這個命令來檢視 ID 為 42 的提取請求的評論。

   ```
   aws codecommit get-comments-for-pull-request --pull-request-id 42
   ```

   如果此命令成功，則會產生類似如下的輸出：

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

1. <a name="update-pull-request-approval-state"></a>若要核准或撤銷提取請求的核准，請執行 **update-pull-request-approval-state** 命令，並指定：
   + 提取請求的 ID (使用 **--pull-request-id** 選項)。
   + 提取請求的修訂 ID (使用 **--revision-id option)**。您可以使用 [get-pull-request](how-to-view-pull-request.md#get-pull-request) 命令取得提取請求的目前修訂 ID。
   + 您要套用的核准狀態 (使用 **--approval-state**) 選項。有效的核准狀態包括 `APPROVE` 和 `REVOKE`。

   例如，使用此命令來核准 ID 為 {{27}} 且修訂 ID 為 {{9f29d167EXAMPLE}} 的提取請求。

   ```
   aws codecommit update-pull-request-approval-state --pull-request-id {{27}} --revision-id {{9f29d167EXAMPLE}} --approval-state "APPROVE"
   ```

   若成功，此命令不會傳回任何內容。

1. 若要對提取請求中的評論張貼回覆，請執行 **post-comment-reply** 命令，指定：
   + 您要回覆的評論由系統產生的 ID (使用 **--in-reply-to** 選項)。
   + 唯一的用戶端產生冪等符記 (使用 **--client-request-token** 選項)。
   + 回覆的內容 (使用 **--content** 選項)。

    例如，使用此命令來新增「{{良好捕獲」回覆。我將移除它們。」}} 至系統產生的 ID 為 {{abcd1234EXAMPLEb5678efgh}} 的註解。

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

   如果此命令成功，則會產生類似如下的輸出：

   ```
   { 
       "comment": {
           "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
           "clientRequestToken": "123Example",
           "commentId": "442b498bEXAMPLE5756813",
           "content": "Good catch. I'll remove them.",
           "creationDate": 1508369829.136,
           "deleted": false,
           "lastModifiedDate": 150836912.221,
           "callerReactions": [],
           "reactionCounts": []
       }
    }
   ```