是否可以通过GitHub API查找是否已通过拉取请求解决了问题 [英] Is it possible to find out, via the GitHub API, if an issue has been closed via a pull request

查看:77
本文介绍了是否可以通过GitHub API查找是否已通过拉取请求解决了问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将

  • 如果已通过提交关闭了问题,则会添加commit_id
  • 如果该问题已从GitHub应用关闭(显然不包括网络),则将 performed_via_github_app 设置为非null.

但是,似乎并没有一种特别的方法来表明问题已由拉取请求关闭.是吗?

解决方案

使用

I'm using github-script for GitHub actions, which allows you to easily access GitHub API. I'm trying to check if an issue has not been closed by clicking on the "close button", that is, via a commit or via merging a pull request that includes a closing commit (or closes in the PR body). However, there does not seem an easy way to do that. This is the event information the GitHub API returns:

  • If the issue has been closed from a commit, it adds the commit_id
  • If the issue has been closed from GitHub app (this does not include the web, apparently), performed_via_github_app is set to non-null.

However, there does not seem to be a special way to signal an issue has been closed by a pull request, apparently. Or is it?

解决方案

It's possible to check whether a specific issue was closed by pull request, commit or button/API using the GraphQL API with timelineItems and filtering on event with state CLOSED_EVENT :

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

Try it in the explorer

The closer field contains the source of the closing (check __typename value) :

The following requests are example for the 3 types of closing

Closing via pull request

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
            }
          }
        }
      }
    }
  }
}

Output

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

Closing via commit message

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
            }
          }
        }
      }
    }
  }
}

Output

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

Closing via button or Github API

This issue was closed via the close button :

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

Output

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

Github app uses Github API to make call to close an issue, performed_via_github_app is set non null if you open an issue from an api call generated via a Github app. But performed_via_github_app doesn't specify by which mean the issue was closed :

这篇关于是否可以通过GitHub API查找是否已通过拉取请求解决了问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆