Querying Github using GraphQL and Golang
Summary
I recently had to compile a list of changes(pull requests that have been merged) to make a changelog for an open source project. This is can be done manually if there are only a few of them but in my case I had around 40 changes that needed to be compiled.
Luckily for me, Github has an api which can be used to automate that and more.
My scripting language for this will be Golang for no particular reason,
1. Github token
2. Github explorer to make query
3. Golang script https://gist.github.com/Lougarou/9a69c31f1e0e505ac2f032f31df4d571
Note: Does not cover how to make a GraphQL query but has an example
Github Token
Settings
Developer Settings
Personal Access Tokens
Finally generate new token
Github Explorer
Next go to https://developer.github.com/v4/explorer/ and try your GraphQl query
Notice that we have queried 50 entries with the state required to be MERGED
Golang Script
For Golang, you will need the following libraries https://github.com/shurcooL/githubv4 and https://godoc.org/golang.org/x/oauth2
The library does not support the format of the query we made in GraphQL. Instead we have to prepare structs for the result and the queries formatted as shown in the gist below.
Finally, we loop through our result and output the changes in a markdown format.
Comments
Post a Comment