Shows a list of all open PR's across all of your Github repos. Includes ones created by you as well as ones requesting your review. Selecting a pull request will open it directly in the browser
// Name: Open Pull Requests// Author: Manan Joshi// Twitter: @manan__joshiimport "@johnlindquist/kit";import { Choice } from "@johnlindquist/kit";const GITHUB_ACCESS_TOKEN = "<YOUR_GITHUB_ACCESS_TOKEN>";const GITHUB_GRAPHQL_ENDPOINT = "https://api.github.com/graphql";const myRequests = async () =>await fetch(GITHUB_GRAPHQL_ENDPOINT, {headers: { Authorization: `token ${GITHUB_ACCESS_TOKEN}` },method: "POST",body: JSON.stringify({query: `query {viewer {pullRequests(first: 100orderBy: { field: CREATED_AT, direction: DESC }states: OPEN) {nodes {author {loginavatarUrl}urltitlebodyrepository {nameWithOwner}}}}}`,}),});const reviewRequests = async () =>await fetch(GITHUB_GRAPHQL_ENDPOINT, {headers: { Authorization: `token ${GITHUB_ACCESS_TOKEN}` },method: "POST",body: JSON.stringify({query: `query {search(query: "is:pr is:open review-requested:<your_github_username>"type: ISSUEfirst: 100) {nodes {... on PullRequest {titleurlbodyauthor {loginavatarUrl}repository {nameWithOwner}}}}}`,}),});["Mine", "Requested"].forEach((type) => {onTab(type, async () => {const pullRequestUrl = await arg("Select a Pull Request", async () => {let requests = [];if (type === "Mine") {const data = await myRequests();requests = (await data.json()).data.viewer.pullRequests.nodes;} else {const data = await reviewRequests();requests = (await data.json()).data.search.nodes;}return requests.map((request) =>({name: request.title,description: `${request.repository.nameWithOwner} | ${request.author.login}`,value: request.url,icon: request.author.avatarUrl,preview: md(`# ${request.title}`).concat(md(request.body)),} as Choice<string>));});exec(`open ${pullRequestUrl}`);});});