Skip to content

Instantly share code, notes, and snippets.

@dpmex4527
Last active November 15, 2018 21:30
Show Gist options
  • Save dpmex4527/10fa4bee7ddad1ba0db1efce9cb59d77 to your computer and use it in GitHub Desktop.
Save dpmex4527/10fa4bee7ddad1ba0db1efce9cb59d77 to your computer and use it in GitHub Desktop.
Search Pull Request that contains a specific commit hash

You can execute the query using the following curl command

curl --request POST \
  --url https://api.github.com/graphql \
  --header 'authorization: Bearer <GITHUB_TOKEN>' \
  --header 'content-type: application/json' \
  --data '{"query":"query SearchPullRequestFromCommitSha {\n  search (\n    first: 100, type: ISSUE,\n    query: \"type:pr repo:octokit/octokit.rb cd410f734e090e49d0f6e1ccff7ad3403259bd4d\"\n  ) {\n    nodes {\n      ... on PullRequest {\n        id, number, title, headRefName\n      }\n    }\n  }\n}","operationName":"SearchPullRequestFromCommitSha"}'

Query

query SearchPullRequestFromCommitSha {
  search (
    first: 100, type: ISSUE,
    query: "type:pr repo:octokit/octokit.rb cd410f734e090e49d0f6e1ccff7ad3403259bd4d"
  ) {
    nodes {
      ... on PullRequest {
        id, number, title, headRefName
      }
    }
  }
}

Response

{
	"data": {
		"search": {
			"nodes": [
				{
					"id": "MDExOlB1bGxSZXF1ZXN0MjE5Mzk3MjE4",
					"number": 1078,
					"title": "Add new strict validation preview header",
					"headRefName": "tarebyte/strict-validation-preview"
				}
			]
		}
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment