

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

# 评论中的提交 AWS CodeCommit
<a name="how-to-commit-comment"></a>

您可以使用 CodeCommit 控制台对仓库中的提交进行评论，以及查看和回复其他用户对提交的评论。这可以帮助您讨论在存储库中进行的更改，包括：
+ 进行更改的原因。
+ 是否需要进行多处更改。
+ 是否应将更改合并到其他分支中。

您可以对整个提交、提交中的某个文件或文件中特定的行或更改发表评论。您也可以通过以下方式链接到一行代码：选择一行，然后在浏览器中复制生成的 URL。

**注意**  
为了获得最佳结果，请在以 IAM 用户身份登录时使用评论功能。评论功能并未针对用根账户凭证、联合访问或临时凭证登录的用户进行优化。

**Topics**
+ [查看对存储库中的提交的评论](#how-to-commit-comment-view-console)
+ [在存储库中添加和回复对提交的评论](#how-to-commit-comment-add-console)
+ [查看、添加、更新和回复评论 (AWS CLI)](#how-to-commit-comment-cli)

## 查看对存储库中的提交的评论
<a name="how-to-commit-comment-view-console"></a>

您可以使用 CodeCommit 控制台查看对提交的评论。

**查看对提交进行的评论**

1. 在 [https://console.aws.amazon.com/codesuite/codemmit](https://console.aws.amazon.com/codesuite/codecommit/home) /home 打开 CodeCommit 控制台。

1. 在**存储库**中，选择要查看对其提交进行的评论的存储库。

1. 在导航窗格中，选择 **Commits**。选择您要查看任何评论的提交的提交 ID。

   该提交的页面将与任何评论一起显示。

## 在存储库中添加和回复对提交的评论
<a name="how-to-commit-comment-add-console"></a>

您可以使用 CodeCommit 控制台为提交和父提交的比较或两个指定提交之间的比较添加注释。您还可以使用表情符号和/或您自己的评论来回复评论。

### 添加和回复对提交的评论（控制台）
<a name="how-to-commit-comment-add-cpage"></a>

您可以使用文本和表情符号添加和回复对提交的评论。您的评论和表情符号将标记为属于用于登录控制台的 IAM 用户或角色。

**添加和回复对提交进行的评论**

1. 在 [https://console.aws.amazon.com/codesuite/codemmit](https://console.aws.amazon.com/codesuite/codecommit/home) /home 打开 CodeCommit 控制台。

1. 在**存储库**中，选择要在其中对提交进行评论的存储库。

1. 在导航窗格中，选择 **Commits**。选择您要在其中添加或回复评论的提交的提交 ID。

   该提交的页面将与任何评论一起显示。

1. 要添加评论，请执行以下操作之一：
   + 要添加一般评论，请在**对更改的评论**中输入评论，然后选择**保存**。您可以使用 [Markdown](https://en.wikipedia.org/wiki/Markdown)，也可以纯文本格式输入评论。  
![\[对提交中更改的一般评论。\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-commenting-changecomment.png)
   + 要向提交中的文件添加评论，请找到该文件的名称。选择**对文件的评论**，输入评论，然后选择**保存**。  
![\[对提交中的文件添加评论。\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-commenting-addfilecomment.png)
   + 要向提交中的已更改行添加评论，请转到显示更改的行。选择评论气泡 ![\[The comment bubble icon that that indicates that you can leave a comment on that line of code.\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-commentbubble.png)，输入评论，然后选择**保存**。  
![\[对提交中的行添加评论。\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-commenting-addlinecomment.png)
**注意**  
您可以在保存评论后编辑它。您也可以删除其内容。评论将保留一条消息，说明内容已被删除。请考虑在保存您的评论之前为该评论使用**预览 markdown** 模式。

1. 要回复对提交的评论，请选择**回复**。要使用表情符号回复评论，请从列表中选择所需的表情符号。每条评论只能选择一个表情符号。如果要更改表情符号反应，请从列表中选择其他表情符号，或选择**无**以删除反应。  
![\[在评论中添加回复和表情符号反应。\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-commenting-commenttab.png)

### 在比较两个提交说明符时添加和回复评论
<a name="how-to-commit-comment-console-compare"></a>

您可以向两个分支、标签或提交之间的比较添加评论。

**在比较提交说明符时添加或回复评论**

1. 在 [https://console.aws.amazon.com/codesuite/codemmit](https://console.aws.amazon.com/codesuite/codecommit/home) /home 打开 CodeCommit 控制台。

1. 在**存储库**中，选择要比较提交、分支或已标记提交的存储库。

1. 在导航窗格中，选择**提交**，然后选择**比较提交**选项卡。  
![\[比较任意两个提交说明符\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-compare-1.png)

1. 使用**目标**和**源**字段来比较两个提交说明符。使用下拉列表或粘贴提交 IDs。选择 **Compare**。  
![\[将提交 ID 与分支比较时的示例结果\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-compare-4.png)

1. 执行以下一个或多个操作：
   + 要添加对文件或行的评论，请选择评论气泡 ![\[The comment bubble icon that that indicates that you can leave a comment on that line of code.\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-commentbubble.png)。
   + 要添加对所比较更改的一般评论，请转到 **Comments on changes**。

## 查看、添加、更新和回复评论 (AWS CLI)
<a name="how-to-commit-comment-cli"></a>

您可以通过运行以下命令来查看、添加、回复、更新和删除评论内容：
+ 要查看对两个提交之间的比较进行的评论，请运行 **[get-comments-for-compared-commit](#how-to-commit-comment-cli-get-comments)**。
+ 要查看有关评论的详细信息，请运行 [**get-comment**](#how-to-commit-comment-cli-get-comment-info)。
+ 要删除您创建的评论的内容，请运行 [**delete-comment-content**](#how-to-commit-comment-cli-commit-delete)。
+ 要创建对两个提交之间的比较进行的评论，请运行 [**post-comment-for-compared-commit**](#how-to-commit-comment-cli-comment)。
+ 要更新评论，请运行 [**update-comment**](#how-to-commit-comment-cli-commit-update)。
+ 要回复评论，请运行 [**post-comment-reply**](#how-to-commit-comment-cli-commit-reply)。
+ 要使用表情符号回复评论，请运行 [**put-comment-reaction**](#how-to-commit-comment-cli-commit-reply-emoji)。
+ 要查看对评论的表情符号反应，请运行 [**get-comment-reactions**](#how-to-commit-comment-cli-commit-emoji-view)。

### 查看对提交进行的评论
<a name="how-to-commit-comment-cli-get-comments"></a>

1. 运行 **get-comments-for-compared-commit** 命令，并指定：
   +  CodeCommit 存储库的名称（带`--repository-name`选项）。
   + “after”提交的完整提交 ID，用于建立比较的方向性（使用 `--after-commit-id option`）。
   + “before”提交的完整提交 ID，用于建立比较的方向性（使用 `--before-commit-id` 选项）。
   + （可选）要返回下一批结果的枚举令牌（使用 `--next-token` 选项）。
   + (可选) 一个用于限制返回的结果数的非负整数 (使用 `--max-results` 选项)。

   例如，要查看对名为 *MyDemoRepo* 的存储库中两个提交之间的比较做出的评论，请运行以下命令：

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

1. 如果成功，该命令产生类似以下内容的输出：

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

### 查看提交评论的详细信息
<a name="how-to-commit-comment-cli-get-comment-info"></a>

1. 运行 **get-comment** 命令，并指定系统生成的评论 ID。例如：

   ```
   aws codecommit get-comment --comment-id ff30b348EXAMPLEb9aa670f
   ```

1. 如果成功，该命令返回类似以下内容的输出：

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

### 删除提交评论的内容
<a name="how-to-commit-comment-cli-commit-delete"></a>

1. 运行 **delete-comment-content** 命令，并指定系统生成的评论 ID。例如：

   ```
   aws codecommit delete-comment-content --comment-id ff30b348EXAMPLEb9aa670f
   ```
**注意**  
只有在应用了 AWSCodeCommitFullAccess 策略或将`DeleteCommentContent`权限设置为 “**允**许” 的情况下，您才能删除评论的内容。

1. 如果成功，该命令产生类似以下内容的输出：

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

### 创建提交评论
<a name="how-to-commit-comment-cli-comment"></a>

1. 运行 **post-comment-for-compared-commit** 命令，并指定：
   +  CodeCommit 存储库的名称（带`--repository-name`选项）。
   + “after”提交的完整提交 ID，用于建立比较的方向性（使用 `--after-commit-id ` 选项）。
   + “before”提交的完整提交 ID，用于建立比较的方向性（使用 `--before-commit-id` 选项）。
   + 客户端生成的唯一等幂令牌（使用 **--client-request-token** 选项）。
   + 您的评论的内容（使用 **--content** 选项）。
   + 有关评论放置位置信息的列表，包括：
     + 所比较文件的名称，包括其扩展名和子目录（如果有，则使用 **filePath** 属性）。
     + 在比较文件中更改的行号（使用 **filePosition** 属性）。
     + 对更改的评论在源分支与目标分支之间比较“之前”还是“之后”（使用 **relativeFileVersion** 属性）。

   例如，在比较名为*MyDemoRepo*：*"Can you add a test case for this?"*的存储库中的两个提交时，要添加对*cl\$1sample.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   
   ```

1. 如果成功，该命令产生类似以下内容的输出：

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

### 更新提交评论
<a name="how-to-commit-comment-cli-commit-update"></a>

1. 运行 **update-comment** 命令，并指定要替换任何现有内容的系统生成的评论 ID 和内容。

   例如，要将内容添加到 ID *"Fixed as requested. I'll update the pull request."* 为的评论中，请执行*442b498bEXAMPLE5756813*以下操作：

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

1. 如果成功，该命令产生类似以下内容的输出：

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

### 回复提交评论
<a name="how-to-commit-comment-cli-commit-reply"></a>

1. 要在拉取请求中发布对评论的回复，请运行 **post-comment-reply** 命令，并且指定：
   + 要回复的评论的系统生成的 ID（使用 **--in-reply-to** 选项）。
   + 客户端生成的唯一等幂令牌（使用 **--client-request-token** 选项）。
   + 您的回复的内容（使用 **--content** 选项）。

    例如，要将系统生成的 ID 的回复*"Good catch. I'll remove them."*添加到评论中，请执行以下操作：*abcd1234EXAMPLEb5678efgh*

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

1. 如果成功，该命令产生类似以下内容的输出：

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

### 使用表情符号回复对提交的评论
<a name="how-to-commit-comment-cli-commit-reply-emoji"></a>

1. 要使用表情符号回复拉取请求中的评论，或者要更改表情符号反应的值，请运行 **put-comment-reaction** 命令，指定以下内容：
   + 要使用表情符号回复的评论的系统生成的 ID。
   + 要添加或更新的反应的值。可接受的值包括支持的表情符号、简码和 Unicode 值。<a name="emoji-reaction-table"></a>

   中的表情符号支持以下值： CodeCommit  
****    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/how-to-commit-comment.html)

    例如，要将系统生成的 ID *:thumbsup:* 为的表情符号添加到评论中：*abcd1234EXAMPLEb5678efgh*

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

1. 如果成功，此命令不会产生任何输出。

### 查看对评论的表情符号反应
<a name="how-to-commit-comment-cli-commit-emoji-view"></a>

1. 要查看对评论的表情符号反应（包括使用这些表情符号做出了反应的用户），请运行 **get-comment-reactions** 命令，指定评论的系统生成的 ID。

    例如，要查看表情符号对评论的反应，系统生成的 ID 为*abcd1234EXAMPLEb5678efgh*：

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

1. 如果成功，该命令产生类似以下内容的输出：

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