Github API - 如何知道问题是否已被分叉请求关闭?

Github API - How to know if an issue was closed by a fork pull request?

我怎么知道给定一个已关闭的问题,如果它是通过拉取请求关闭的,特别是通过分叉拉取请求,我如何获得分叉的 ID?

我一直在阅读 issues/pull request/events API 文档,但没有找到任何内容。

可以使用 GraphQL API v4 using timelineItems 并过滤状态为 CLOSED_EVENT

的事件
{
  repository(name: "material-ui", owner: "mui-org") {
    issue(number: 19641) {
      timelineItems(itemTypes: CLOSED_EVENT, last: 1) {
        nodes {
          ... on ClosedEvent {
            createdAt
            closer {
              ...on PullRequest {
                baseRefName
                baseRepository {
                  nameWithOwner
                }
                headRefName
                headRepository {
                  nameWithOwner
                }
              }
            }
          }
        }
      }
    }
  }
}

Try it in the explorer

closer 字段包含结束的来源:

以下请求是 3 种关闭类型的示例

通过拉取请求关闭

This pull request closed this issue

{
  repository(name: "material-ui", owner: "mui-org") {
    issue(number: 19641) {
      timelineItems(itemTypes: CLOSED_EVENT, last: 1) {
        nodes {
          ... on ClosedEvent {
            createdAt
            closer {
              __typename
            }
          }
        }
      }
    }
  }
}

输出

{
  "data": {
    "repository": {
      "issue": {
        "timelineItems": {
          "nodes": [
            {
              "createdAt": "2020-05-20T09:06:11Z",
              "closer": {
                "__typename": "PullRequest"
              }
            }
          ]
        }
      }
    }
  }
}

通过提交消息关闭

This commit closed this issue

{
  repository(name: "rubinius", owner: "rubinius") {
    issue(number: 1536) {
      timelineItems(itemTypes: CLOSED_EVENT, last: 1) {
        nodes {
          ... on ClosedEvent {
            createdAt
            closer {
              __typename
            }
          }
        }
      }
    }
  }
}

输出

{
  "data": {
    "repository": {
      "issue": {
        "timelineItems": {
          "nodes": [
            {
              "createdAt": "2012-01-30T22:33:11Z",
              "closer": {
                "__typename": "Commit"
              }
            }
          ]
        }
      }
    }
  }
}

通过按钮关闭

This issue 已通过关闭按钮关闭:

{
  repository(name: "rubinius", owner: "rubinius") {
    issue(number: 3830) {
      timelineItems(itemTypes: CLOSED_EVENT, last: 1) {
        nodes {
          ... on ClosedEvent {
            createdAt
            closer {
              __typename
            }
          }
        }
      }
    }
  }
}

输出

{
  "data": {
    "repository": {
      "issue": {
        "timelineItems": {
          "nodes": [
            {
              "createdAt": "2020-02-02T22:31:05Z",
              "closer": null
            }
          ]
        }
      }
    }
  }
}