使用 GitHub 的 GraphQL API,我如何知道谁关闭了问题或拉取请求?
Using GitHub's GraphQL API, how can I tell who closed an issue or pull request?
给定问题或拉取请求编号,我想使用对 GitHub GraphQL API 的单个查询获取以下信息:
- 无论是问题还是拉取请求
- 问题的状态(打开、关闭)或 PR(打开、关闭、合并)
- 如果问题或 PR 已关闭,谁关闭了它,何时关闭
- 如果问题或 PR 被合并,合并的人和时间
使用以下查询,除了确定 谁 关闭了问题或 PR:
之外,我已经完成了所有这些工作
{
repository(owner: "Automattic", name: "wp-calypso") {
issueOrPullRequest(number: 23226) {
__typename
... on Closable {
closed
closedAt
# TODO: How to get ClosedEvent { actor } ?
}
... on Issue {
issueState: state
title
}
... on PullRequest {
prState: state
title
merged
mergedAt
mergeCommit {
committer {
user {
login
}
}
}
}
}
}
}
我 运行 使用 GitHub 的 GraphQL Explorer 工具进行此查询:https://developer.github.com/v4/explorer/
我可以将问题或 PR 视为影响该对象的 Closable
but I think I need to get from there to the last ClosedEvent
。这是我还没弄清楚的部分。
在 GitHub 的 v3 REST API 中,确定所有这些信息可能需要 2 个请求。对于 closed(不是 merged)的拉取请求,closed_by
字段仅在请求拉取请求时出现 作为一个问题(通过 issues
API call). All other pull request information is available via the pulls
API 调用。
获取关闭问题的演员的一种迂回(和丑陋)方式如下(受此 answer 启发)。我希望可能有更好的方法,但这是目前的一种方法。
诀窍是在给定的时间线上查询相当数量的事件(如果你绝对确定issue/PR关闭后没有评论,你可以说timeline(last: 1)
), 找出其中的ClosedEvent
或MergedEvent
并提取actor
{
repository(owner: "Automattic", name: "wp-calypso") {
issueOrPullRequest(number: 23226) {
__typename
... on Closable {
closed
closedAt
}
... on Issue {
timeline(last: 100) {
edges {
node {
__typename
... on ClosedEvent {
actor{
login
}
}
}
}
}
}
... on PullRequest {
timeline(last: 100) {
edges {
node {
__typename
... on MergedEvent {
actor{
login
}
}
}
}
}
}
}
}
}
给定问题或拉取请求编号,我想使用对 GitHub GraphQL API 的单个查询获取以下信息:
- 无论是问题还是拉取请求
- 问题的状态(打开、关闭)或 PR(打开、关闭、合并)
- 如果问题或 PR 已关闭,谁关闭了它,何时关闭
- 如果问题或 PR 被合并,合并的人和时间
使用以下查询,除了确定 谁 关闭了问题或 PR:
之外,我已经完成了所有这些工作{
repository(owner: "Automattic", name: "wp-calypso") {
issueOrPullRequest(number: 23226) {
__typename
... on Closable {
closed
closedAt
# TODO: How to get ClosedEvent { actor } ?
}
... on Issue {
issueState: state
title
}
... on PullRequest {
prState: state
title
merged
mergedAt
mergeCommit {
committer {
user {
login
}
}
}
}
}
}
}
我 运行 使用 GitHub 的 GraphQL Explorer 工具进行此查询:https://developer.github.com/v4/explorer/
我可以将问题或 PR 视为影响该对象的 Closable
but I think I need to get from there to the last ClosedEvent
。这是我还没弄清楚的部分。
在 GitHub 的 v3 REST API 中,确定所有这些信息可能需要 2 个请求。对于 closed(不是 merged)的拉取请求,closed_by
字段仅在请求拉取请求时出现 作为一个问题(通过 issues
API call). All other pull request information is available via the pulls
API 调用。
获取关闭问题的演员的一种迂回(和丑陋)方式如下(受此 answer 启发)。我希望可能有更好的方法,但这是目前的一种方法。
诀窍是在给定的时间线上查询相当数量的事件(如果你绝对确定issue/PR关闭后没有评论,你可以说timeline(last: 1)
), 找出其中的ClosedEvent
或MergedEvent
并提取actor
{
repository(owner: "Automattic", name: "wp-calypso") {
issueOrPullRequest(number: 23226) {
__typename
... on Closable {
closed
closedAt
}
... on Issue {
timeline(last: 100) {
edges {
node {
__typename
... on ClosedEvent {
actor{
login
}
}
}
}
}
}
... on PullRequest {
timeline(last: 100) {
edges {
node {
__typename
... on MergedEvent {
actor{
login
}
}
}
}
}
}
}
}
}