gpt4 book ai didi

github - 列出所有 Unresolved 拉取请求评论

转载 作者:行者123 更新时间:2023-12-04 02:49:26 26 4
gpt4 key购买 nike

我们正在使用 @octokit/rest客户端获取拉取请求的所有评论:

client.pulls
.listComments({
owner,
repo,
pull_number: 34,
per_page: 100,
})
.then((result) => {
console.log(result.data.length);
console.log(result.data[0]);
});

如果我们可以只列出 Unresolved 评论怎么办?数据中似乎没有指示某人是否已解决评论的属性。

最佳答案

使用 GitHub's v4 GraphQL API , GraphQL API Explorer (探索/建立我的查询),GitHub CLI (以简化调用 GraphQL API)和 jq (过滤结果);我提出了以下解决方案(编写为 bash 脚本以简化调用,但如果从代码调用 GraphQL API 也适用相同的原则):

# Usage:
# Retrieve unresolved review comments
# ./pr-unresolved-review-comments myorganisation myrepo 1337
#
# Count of unresolved review comment threads
# ./pr-unresolved-review-comments myorganisation myrepo 1337 | jq length

gh api graphql -f owner="$1" -f repo="$2" -F pr="$3" -f query='
query FetchReviewComments($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
url
reviewDecision
reviewThreads(first: 100) {
edges {
node {
isResolved
isOutdated
isCollapsed
comments(first: 100) {
totalCount
nodes {
author {
login
}
body
url
}
}
}
}
}
}
}
}
' | jq '.data.repository.pullRequest.reviewThreads.edges | map(select(.node.isResolved == false))'

您作为 GraphQL 查询的一部分包含的特定字段是可自定义的,但这似乎满足了我的需求。

运行上述脚本的输出将如下所示:

[
{
"node": {
"isResolved": false,
"isOutdated": true,
"isCollapsed": false,
"comments": {
"totalCount": 7,
"nodes": [
{
"author": {
"login": "0xdevalias"
},
"body": "This is an unresolved comment that is important!",
"url": "https://github.com/myorganisation/myrepo/pull/1337#discussion_r559294516"
},
..snip..
]
}
}
},
..snip..
]

要列出针对 repo 的所有个 Unresolved 评论,可以使用此脚本:

# Usage:
# Retrieve all unresolved review comments for a repo
# ./pr-unresolved-review-comments myorganisation myrepo

gh api graphql -f owner="$1" -f repo="$2" -f query='
query FetchReviewComments($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
pullRequests(first: 30, states: OPEN) {
edges {
node {
url
reviewDecision
reviewThreads(first: 100) {
edges {
node {
isResolved
isOutdated
isCollapsed
comments(first: 100) {
totalCount
nodes {
author {
login
}
body
url
}
}
}
}
}
}
}
}
}
}
' | jq '.data.repository.pullRequests.edges[].node.reviewThreads.edges | map(select(.node.isResolved == false))'

关于github - 列出所有 Unresolved 拉取请求评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55713929/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com