Skip to content

Instantly share code, notes, and snippets.

@int128
Last active February 20, 2022 08:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save int128/86b9e1fa5aba5f7244c7ddaacb208f89 to your computer and use it in GitHub Desktop.
Save int128/86b9e1fa5aba5f7244c7ddaacb208f89 to your computer and use it in GitHub Desktop.
GraphQL query to find PRs in commit history of a sub tree in a repository

associatedPullRequestsInCommitHistoryOfSubTree

This query returns a list of pull request in the commit history of a sub tree in a repository.

Problem to solve

Let us think about a monorepo, for example,

.
└── components
    ├── frontend
    │   └── package.json
    └── backend
        └── package.json

I want to get a list of pull request merged into a component such as frontend.

Solution

Use the query.

  • Very low cost
  • You can get additional fields such as title
query associatedPullRequestsInCommitHistoryOfSubTree {
rateLimit {
cost
}
repository(owner: "int128", name: "sandbox") {
object(expression: "refs/heads/master") {
... on Commit {
history(path: ".github/workflows", since: "2021-11-01T00:00:00+09:00") {
nodes {
message
pushedDate
associatedPullRequests(first: 2, orderBy: {field: UPDATED_AT, direction: DESC}) {
nodes {
number
mergedAt
}
}
}
}
}
}
}
}
{
"data": {
"rateLimit": {
"cost": 1
},
"repository": {
"object": {
"history": {
"nodes": [
{
"message": "Show debug logs (#150)",
"pushedDate": "2021-12-07T05:05:15Z",
"associatedPullRequests": {
"nodes": [
{
"number": 150,
"mergedAt": "2021-12-07T05:05:14Z"
}
]
}
},
{
"message": "Update helloworld--build.yaml",
"pushedDate": "2021-12-07T04:55:23Z",
"associatedPullRequests": {
"nodes": []
}
},
{
"message": "Run after build (#149)",
"pushedDate": "2021-12-07T04:49:12Z",
"associatedPullRequests": {
"nodes": [
{
"number": 149,
"mergedAt": "2021-12-07T04:49:12Z"
}
]
}
},
{
"message": "Build with Kaniko (#147)\n\n* Build with Kaniko\r\n\r\n* Update helloworld--build.yaml",
"pushedDate": "2021-12-07T04:20:11Z",
"associatedPullRequests": {
"nodes": [
{
"number": 147,
"mergedAt": "2021-12-07T04:20:10Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-12-06T05:41:35Z",
"associatedPullRequests": {
"nodes": [
{
"number": 144,
"mergedAt": "2021-12-06T05:46:46Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-12-06T05:41:12Z",
"associatedPullRequests": {
"nodes": [
{
"number": 144,
"mergedAt": "2021-12-06T05:46:46Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-12-06T05:14:58Z",
"associatedPullRequests": {
"nodes": [
{
"number": 143,
"mergedAt": "2021-12-06T05:16:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-12-06T05:06:52Z",
"associatedPullRequests": {
"nodes": [
{
"number": 143,
"mergedAt": "2021-12-06T05:16:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:37:10Z",
"associatedPullRequests": {
"nodes": [
{
"number": 143,
"mergedAt": "2021-12-06T05:16:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:29:21Z",
"associatedPullRequests": {
"nodes": [
{
"number": 143,
"mergedAt": "2021-12-06T05:16:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:26:43Z",
"associatedPullRequests": {
"nodes": [
{
"number": 142,
"mergedAt": "2021-11-23T06:27:27Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:23:45Z",
"associatedPullRequests": {
"nodes": [
{
"number": 142,
"mergedAt": "2021-11-23T06:27:27Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:22:07Z",
"associatedPullRequests": {
"nodes": [
{
"number": 142,
"mergedAt": "2021-11-23T06:27:27Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:19:58Z",
"associatedPullRequests": {
"nodes": [
{
"number": 142,
"mergedAt": "2021-11-23T06:27:27Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:18:20Z",
"associatedPullRequests": {
"nodes": [
{
"number": 142,
"mergedAt": "2021-11-23T06:27:27Z"
}
]
}
},
{
"message": "Update release.yaml",
"pushedDate": "2021-11-23T06:16:31Z",
"associatedPullRequests": {
"nodes": [
{
"number": 142,
"mergedAt": "2021-11-23T06:27:27Z"
}
]
}
},
{
"message": "Update release.yaml",
"pushedDate": "2021-11-23T06:15:42Z",
"associatedPullRequests": {
"nodes": [
{
"number": 142,
"mergedAt": "2021-11-23T06:27:27Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:14:46Z",
"associatedPullRequests": {
"nodes": [
{
"number": 142,
"mergedAt": "2021-11-23T06:27:27Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:09:39Z",
"associatedPullRequests": {
"nodes": [
{
"number": 140,
"mergedAt": "2021-11-23T06:10:14Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T06:05:39Z",
"associatedPullRequests": {
"nodes": [
{
"number": 140,
"mergedAt": "2021-11-23T06:10:14Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T05:35:03Z",
"associatedPullRequests": {
"nodes": [
{
"number": 140,
"mergedAt": "2021-11-23T06:10:14Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T05:32:04Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T05:27:49Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T05:23:09Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T05:21:21Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T05:17:56Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T05:11:33Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T03:19:36Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T03:18:38Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T03:17:54Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T03:16:48Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T03:15:45Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T03:13:46Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T03:12:05Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T03:08:48Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T03:02:35Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T01:17:00Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T01:14:52Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T01:08:19Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T01:05:22Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-23T01:03:24Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update add-issue-label-by-mention.yml",
"pushedDate": "2021-11-21T12:33:11Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T09:30:18Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T09:26:31Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T09:24:37Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T09:22:32Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T09:17:20Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T09:08:24Z",
"associatedPullRequests": {
"nodes": [
{
"number": 139,
"mergedAt": "2021-11-23T05:32:31Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T09:06:55Z",
"associatedPullRequests": {
"nodes": [
{
"number": 136,
"mergedAt": "2021-11-21T09:07:20Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T09:05:12Z",
"associatedPullRequests": {
"nodes": [
{
"number": 136,
"mergedAt": "2021-11-21T09:07:20Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T09:01:38Z",
"associatedPullRequests": {
"nodes": [
{
"number": 136,
"mergedAt": "2021-11-21T09:07:20Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T07:39:32Z",
"associatedPullRequests": {
"nodes": [
{
"number": 136,
"mergedAt": "2021-11-21T09:07:20Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T07:23:19Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T07:20:44Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T06:49:43Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T06:44:15Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T06:42:39Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T06:38:01Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T06:33:21Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update and rename helloworld.yaml to helloworld--build.yaml",
"pushedDate": "2021-11-21T06:24:52Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Delete pull-request-merged.yml",
"pushedDate": "2021-11-21T06:24:27Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Delete pull-request-labeled.yml",
"pushedDate": "2021-11-21T06:24:20Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update add-issue-to-project-on-assigned.yaml",
"pushedDate": "2021-11-21T06:23:57Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update add-issue-to-project-by-label.yml",
"pushedDate": "2021-11-21T06:23:32Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T06:22:00Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update bot.yaml",
"pushedDate": "2021-11-21T06:21:15Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Create bot.yaml",
"pushedDate": "2021-11-21T00:57:06Z",
"associatedPullRequests": {
"nodes": [
{
"number": 133,
"mergedAt": "2021-11-21T07:33:15Z"
}
]
}
},
{
"message": "Update release.yaml",
"pushedDate": "2021-11-20T12:33:33Z",
"associatedPullRequests": {
"nodes": [
{
"number": 132,
"mergedAt": "2021-11-20T12:35:58Z"
}
]
}
},
{
"message": "Update release.yaml",
"pushedDate": "2021-11-20T12:32:32Z",
"associatedPullRequests": {
"nodes": [
{
"number": 132,
"mergedAt": "2021-11-20T12:35:58Z"
}
]
}
},
{
"message": "Update release.yaml",
"pushedDate": "2021-11-20T12:31:31Z",
"associatedPullRequests": {
"nodes": [
{
"number": 132,
"mergedAt": "2021-11-20T12:35:58Z"
}
]
}
},
{
"message": "Update release.yaml",
"pushedDate": "2021-11-20T12:30:27Z",
"associatedPullRequests": {
"nodes": [
{
"number": 132,
"mergedAt": "2021-11-20T12:35:58Z"
}
]
}
},
{
"message": "Update and rename create-release-pr.yaml to release.yaml",
"pushedDate": "2021-11-20T12:27:20Z",
"associatedPullRequests": {
"nodes": [
{
"number": 132,
"mergedAt": "2021-11-20T12:35:58Z"
}
]
}
},
{
"message": "Create create-release-pr.yaml",
"pushedDate": "2021-11-20T12:26:03Z",
"associatedPullRequests": {
"nodes": [
{
"number": 132,
"mergedAt": "2021-11-20T12:35:58Z"
}
]
}
}
]
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment