Skip to content

Instantly share code, notes, and snippets.

@dsosby
Created September 7, 2022 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsosby/cc3a0238feba3111fe4bb50705a0ffa8 to your computer and use it in GitHub Desktop.
Save dsosby/cc3a0238feba3111fe4bb50705a0ffa8 to your computer and use it in GitHub Desktop.
// Name: pull requests
import "@johnlindquist/kit";
const ghToken = await env('GH_TOKEN', 'Add your Github Personal Access Token');
const repo = 'johnlindquist/kit';
const [owner, name] = repo.split('/', 2);
const query = `
query pullRequests($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
pullRequests(states: OPEN, first: 10) {
pageInfo {
hasNextPage
endCursor
}
nodes {
author {
... on User {
avatarUrl
name
}
}
body
isDraft
title
url
}
}
}
}`.trim().replaceAll('\n', '');
type Query = {
data: {
repository: {
pullRequests: {
nodes: {
author: {
name: string;
}
body: string;
title: string;
url: string;
}[]
}
}
}
}
const queryResponse = post<Query>(
`https://api.github.com/graphql`,
{
query,
variables: {
owner,
name
}
},
{
headers: {
'Authorization': `Bearer ${ghToken}`,
'Content-Type': 'application/json'
}
});
const pullRequestUrl = await arg({
placeholder: `Open Pull Requests:`,
},
async () => (await
queryResponse).data?.data.repository.pullRequests.nodes.map(({ author: { name }, body, title, url }) => ({
name: title,
description: name,
preview: md(body),
value: url,
})));
browse(pullRequestUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment