![](/img/trans.png)
[英]What's the difference between "Submit review" and "Add comment now" in GitLab's merge request discussions?
[英]GitLab API to post inline comment to Merge Request
notes API仅用于向合并请求添加注释。
为了向源代码添加内联注释,您必须使用此其他API端点:
https://docs.gitlab.com/ce/api/commits.html#post-comment-to-commit
但是这个API在提交列表中设置了注释。 您不会在“合并请求”页面中的任何位置看到评论。
为了添加合并请求的内联注释,有Discussions API: https : //docs.gitlab.com/ce/api/discussions.html
每个讨论都可以在代码中包含一个位置,如下所示:
"position": {
"base_sha": "b5d6e7b1613fca24d250fa8e5bc7bcc3dd6002ef",
"start_sha": "7c9c2ead8a320fb7ba0b4e234bd9529a2614e306",
"head_sha": "4803c71e6b1833ca72b8b26ef2ecd5adc8a38031",
"old_path": "package.json",
"new_path": "package.json",
"position_type": "text",
"old_line": 27,
"new_line": 27
},
functions.yml
.commit_comment:
script:
- export GITLAB_TOKEN="PROJECT_ACCESS_TOKEN"
- |
commit_comment() {
curl --location --request POST "https://gitlab.com/api/v4/projects/$CI_MERGE_REQUEST_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes" --header "PRIVATE-TOKEN: $GITLAB_TOKEN" --header "Content-Type: application/json" --data-raw "{ \"body\": \"$1\" }"
}
# ...
script:
- !reference [.commit_comment, script]
- commit_comment "YOUR_MESSAGE"
# ...
ℹ️ Markdown 被允许用于消息
Reporter
作为角色api
scope。 您可以添加更多范围,但这就是我们所需要的 Ps 在这里,我创建了一个 function 用于多个作业,但您也可以通过将$1
替换为您的消息直接在任何地方直接使用curl
命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.