Created
December 4, 2024 09:49
-
-
Save SallyMcGrath/88626b3c219cb74fe844aedd7f3cd586 to your computer and use it in GitHub Desktop.
Sort GQL issues by title
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
| {{/* This uses graphQL instead of REST | |
| It returns a map of "blocks" so issues can be passed into the blocks loop instead of needing its own system | |
| If we decide we like this better, we should probably systematise this and store | |
| the graphql queries in their own dir | |
| https://docs.github.com/en/graphql/reference/objects#issue | |
| This exact matches on labels unlike the current system which partial matches inside Hugo | |
| We did that because PD kept making partially matching labels, but maybe we should be stricter | |
| TODO But it means someone has to go round and clean up | |
| */}} | |
| {{ $variables := dict | |
| "owner" site.Params.owner | |
| "repo" .backlog | |
| "labels" .backlog_filter | |
| }} | |
| <!--prettier-ignore--> | |
| {{ $query := `query($owner: String!, $repo: String!, $labels: [String!]) { | |
| repository(owner: $owner, name: $repo) { | |
| issues( | |
| last: 100, | |
| filterBy: { | |
| states: OPEN, | |
| labels: $labels | |
| } | |
| ) { | |
| nodes { | |
| title | |
| url | |
| number | |
| labels( | |
| first: 25 | |
| orderBy: { | |
| direction: DESC | |
| field: NAME | |
| } | |
| ) { | |
| nodes { | |
| name | |
| color | |
| description | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }` }} | |
| {{ $request := dict | |
| "method" "POST" | |
| "body" (dict "query" $query "variables" $variables | jsonify) | |
| }} | |
| {{ $issueBlocks := slice }} | |
| {{ with resources.GetRemote "https://api.github.com/graphql" (merge $request (partial "github-auth.html" .)) }} | |
| {{ with .Content | unmarshal }} | |
| {{ with .data.repository.issues.nodes }} | |
| {{ range sort . "title" "asc" }} | |
| {{ $issueBlocks = $issueBlocks | append (dict "name" .title "src" .url "number" .number "labels" .labels) }} | |
| {{ end }} | |
| {{ end }} | |
| {{ end }} | |
| {{ end }} | |
| {{ return $issueBlocks }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment