【发布时间】:2021-04-13 02:28:24
【问题描述】:
我有一个监听所有代码审查的 webhook,然后我获取此 PR 审查的 cmets 以获得评论在 diff 中的位置。 我正在使用 GitHub REST API,但我遇到的问题与 GraphQL API 相同。
所以工作流程是:
- 从 webhook 中获取评论 ID
- 获取该评论的评论列表
- 对于每条评论,获取 diff hunk 和查找编辑行的位置
所有这些在 99% 的情况下都能正常工作。
有时我在位置上得到null,我忽略了这些cmets。
但这一次,我遇到了另一个奇怪的问题。 通常,位置是指 diff 中行的索引。
例如,在:
@@ -1 +1,3 @@
-# sedy-test
\\ No newline at end of file
+# sedy-test
+
+This repository is used to test [sedy](https://github.com/marmelab/sedy).
如果位置为3,则编辑的行为+# sedy-test。
问题在于,对于某些 cmets,我得到的位置不能在 diff 内。 例如,请参阅this PR。
当我尝试通过以下请求获取评论的评论位置时:
{
repository(owner: "Kmaschta", name: "comfygure") {
pullRequest(number: 1) {
reviews(last: 1) {
edges {
node {
state
comments(first: 1) {
edges {
node {
bodyText
authorAssociation
position
originalPosition
diffHunk
}
}
}
}
}
}
}
}
}
响应如下:
{
"data": {
"repository": {
"pullRequest": {
"reviews": {
"edges": [
{
"node": {
"state": "COMMENTED",
"comments": {
"edges": [
{
"node": {
"bodyText": "s/fot/for/",
"authorAssociation": "OWNER",
"position": 71,
"originalPosition": 71,
"diffHunk": "@@ -24,31 +34,39 @@ const ls = (ui, modules) => function* () {\n };\n \n const add = (ui, modules, options) => function* () {\n- const { red, bold } = ui.colors;\n+ const { red, bold, green } = ui.colors;\n \n if (!options.length) {\n ui.error(`${red('No environment specified.')}`);\n- help(ui, 1);\n }\n \n if (options.length > 1) {\n ui.error(`${red('Invalid environment format. The environment name should be one word.')}`);\n- help(ui, 1);\n+ }\n+\n+ if (options.length !== 1) {\n+ ui.print(`${bold('SYNOPSIS')}\n+ ${bold('comfy')} env add <environment>\n+\n+Type ${green('comfy env --help')} for details`);\n+\n+ return ui.exit(0);\n }\n \n const project = yield modules.project.retrieveFromConfig();\n const environment = yield modules.environment.add(project, options[0]);\n- const addCommand = `comfy add ${environment.name}`;\n+ const addCommand = `comfy setall ${environment.name}`;\n \n- ui.print(`${bold('Cool!')} Your new environment \"${bold(environment.name)}\" was successfully saved.`);\n- ui.print(`You can now add a configuration, try ${bold(addCommand)}`);\n+ ui.print(`${bold(green('Environment successfully created'))}`);\n+ ui.print(`You can now set a configuration fot this environment using ${bold(addCommand)}`);"
}
}
]
}
}
}
]
}
}
}
}
}
位置是 71,但差异不超过 40 行。
那么如果是 GitHub API 的 bug,还是我没有理解 position 字段的意义?
【问题讨论】:
标签: github graphql github-api github-graphql github-api-v4