Created
September 7, 2022 15:48
-
-
Save dsosby/cc3a0238feba3111fe4bb50705a0ffa8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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