List all open PR's across all repos. Includes ones created by you as well as ones requesting your review

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__joshi
import "@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: 100
orderBy: { field: CREATED_AT, direction: DESC }
states: OPEN
) {
nodes {
author {
login
avatarUrl
}
url
title
body
repository {
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: ISSUE
first: 100
) {
nodes {
... on PullRequest {
title
url
body
author {
login
avatarUrl
}
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}`);
});
});

pika-2022-05-01T09_04_11 591Z