创建新的合并请求线程时引用的 GitLab line_code 是什么
What is a GitLab line_code as referenced when creating a new merge request thread
我正在尝试使用此端点使用 GitLab api 在文件的特定行上创建关于合并请求的讨论说明:https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread
部分有效载荷要求 line_code
Attribute
Type
Required
Description
position[line_range][start][line_code]
string
yes
Line code for the start line
当我发出 POST 时,我得到的回复是:
"message": "400 (Bad request) \"Note {:line_code=>[\"can't be blank\", \"must be a valid line code\"], :position=>[\"is incomplete\"]}\" not given"
这是什么line_code
?它是某种计算值吗?这里的文档相当模糊。
当我为 merge_request 上的所有当前笔记发出 GET 时,我可以看到一些笔记有这个 line_code
(见下文)。我正在尝试弄清楚如何为新笔记创造价值。
{
"id": 89,
"type": "DiffNote",
"body": "4",
"attachment": null,
"author": {
"id": 6,
"name": "brian c",
"username": "bc",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/f590a9cf57136732dd0cb5z9b1563390?s=80&d=identicon",
"web_url": "http://gitlab.mycompany.us/thisIsMe"
},
"created_at": "2021-01-11T21:46:23.861Z",
"updated_at": "2021-01-11T21:46:23.861Z",
"system": false,
"noteable_id": 21,
"noteable_type": "MergeRequest",
"position": {
"base_sha": "3bf8094f0d54fc70a66698bd582f25c77243de3b",
"start_sha": "3bf8094f0d54fc70a66698bd582f25c77243de3b",
"head_sha": "a10e73cf84eae38286df56f4b58fa221d7eefc44",
"old_path": "b.txt",
"new_path": "b.txt",
"position_type": "text",
"old_line": null,
"new_line": 4,
"line_range": {
"start": {
"line_code": "aceba96ffdf13ce4cd4171c0248420cc03108ef0_0_4",
"type": "new",
"old_line": null,
"new_line": 4
},
"end": {
"line_code": "aceba96ffdf13ce4cd4171c0248420cc03108ef0_0_4",
"type": "new",
"old_line": null,
"new_line": 4
}
}
},
"resolvable": true,
"resolved": false,
"resolved_by": null,
"confidential": false,
"noteable_iid": 3,
"commands_changes": {}
},
代表文件中您希望评论出现的行。对于 Merge Requests,注释可以在代码上或一般性讨论中(尽管 API 名称似乎是倒退的)。
要添加一般性讨论评论,您可以使用注释 API:https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note. This will look like the comment here: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52673#note_495396729
要在合并请求中对更改后的代码添加评论,您可以使用此处的讨论 API:https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread. This operation has options to set the file path and line number a comment should start on, a range that a comment applies to, etc. This is an example of a comment on the code itself: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52673/diffs#2eda52c44979de93f257b305ada778372eacba0b_6_5
线路代码为hash of the file name + underscore + old line number + underscore + new line number
文档有误。 line_code
仅当您使用 position.line_range
时才需要,这仅在添加跨越多行差异的差异注释时才需要。对于单行差异注释,您不需要处理 line_code
。所以它不是必需的参数。您可以只使用 position.old_line
或 position.new_line
.
我正在尝试使用此端点使用 GitLab api 在文件的特定行上创建关于合并请求的讨论说明:https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread
部分有效载荷要求 line_code
Attribute | Type | Required | Description |
---|---|---|---|
position[line_range][start][line_code] | string | yes | Line code for the start line |
当我发出 POST 时,我得到的回复是:
"message": "400 (Bad request) \"Note {:line_code=>[\"can't be blank\", \"must be a valid line code\"], :position=>[\"is incomplete\"]}\" not given"
这是什么line_code
?它是某种计算值吗?这里的文档相当模糊。
当我为 merge_request 上的所有当前笔记发出 GET 时,我可以看到一些笔记有这个 line_code
(见下文)。我正在尝试弄清楚如何为新笔记创造价值。
{
"id": 89,
"type": "DiffNote",
"body": "4",
"attachment": null,
"author": {
"id": 6,
"name": "brian c",
"username": "bc",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/f590a9cf57136732dd0cb5z9b1563390?s=80&d=identicon",
"web_url": "http://gitlab.mycompany.us/thisIsMe"
},
"created_at": "2021-01-11T21:46:23.861Z",
"updated_at": "2021-01-11T21:46:23.861Z",
"system": false,
"noteable_id": 21,
"noteable_type": "MergeRequest",
"position": {
"base_sha": "3bf8094f0d54fc70a66698bd582f25c77243de3b",
"start_sha": "3bf8094f0d54fc70a66698bd582f25c77243de3b",
"head_sha": "a10e73cf84eae38286df56f4b58fa221d7eefc44",
"old_path": "b.txt",
"new_path": "b.txt",
"position_type": "text",
"old_line": null,
"new_line": 4,
"line_range": {
"start": {
"line_code": "aceba96ffdf13ce4cd4171c0248420cc03108ef0_0_4",
"type": "new",
"old_line": null,
"new_line": 4
},
"end": {
"line_code": "aceba96ffdf13ce4cd4171c0248420cc03108ef0_0_4",
"type": "new",
"old_line": null,
"new_line": 4
}
}
},
"resolvable": true,
"resolved": false,
"resolved_by": null,
"confidential": false,
"noteable_iid": 3,
"commands_changes": {}
},
代表文件中您希望评论出现的行。对于 Merge Requests,注释可以在代码上或一般性讨论中(尽管 API 名称似乎是倒退的)。
要添加一般性讨论评论,您可以使用注释 API:https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note. This will look like the comment here: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52673#note_495396729
要在合并请求中对更改后的代码添加评论,您可以使用此处的讨论 API:https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread. This operation has options to set the file path and line number a comment should start on, a range that a comment applies to, etc. This is an example of a comment on the code itself: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52673/diffs#2eda52c44979de93f257b305ada778372eacba0b_6_5
线路代码为hash of the file name + underscore + old line number + underscore + new line number
文档有误。 line_code
仅当您使用 position.line_range
时才需要,这仅在添加跨越多行差异的差异注释时才需要。对于单行差异注释,您不需要处理 line_code
。所以它不是必需的参数。您可以只使用 position.old_line
或 position.new_line
.