Skip to content

Commit

Permalink
Simplify API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
heinrichreimer committed Mar 4, 2024
1 parent f839cf3 commit 66a098c
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions layouts/shortcodes/cv/open-source.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
{{- $username = index (split $username ":") 0 -}}
{{- end -}}

{{- $githubApiUrl := "https://api.github.com/" -}}
{{- $githubGraphQLApiUrl := urls.JoinPath $githubApiUrl "graphql" -}}

{{/* For debugging, use https://docs.github.com/en/graphql/overview/explorer. */}}
{{- $pinnedReposQuery := printf `
{
query {
user(login: "%s") {
pinnedItems(first: 6, types: REPOSITORY) {
nodes {
Expand Down Expand Up @@ -44,15 +41,13 @@
{{- $pinnedReposBody := dict "query" $pinnedReposQuery | jsonify (dict "noHTMLEscape" true) -}}
{{- $pinnedReposOpts := dict "method" "post" "body" $pinnedReposBody "headers" $githubHeaders -}}

{{ with resources.GetRemote $githubGraphQLApiUrl $pinnedReposOpts }}
{{- with resources.GetRemote "https://api.github.com/graphql" $pinnedReposOpts -}}
{{- with .Err -}}{{- errorf "%s" . -}}{{- end -}}

{{ $pinnedReposData := .Content | transform.Unmarshal }}
{{- with $pinnedReposData.data.user.pinnedItems.nodes -}}
{{- with .Content | transform.Unmarshal -}}
<figure>
<table>
<tbody>
{{- range . -}}
{{- range .data.user.pinnedItems.nodes -}}
<tr>
<th>
{{- time.Format "01/2006" .createdAt -}}
Expand Down Expand Up @@ -119,7 +114,9 @@
</tbody>
</table>
</figure>
{{- else -}}
{{- errorf "Unable to parse GitHub GraphQL API response." -}}
{{- end -}}
{{ else }}
{{ errorf "Unable to get remote resource %q" $githubGraphQLApiUrl }}
{{ end }}
{{- else -}}
{{- errorf "Unable to get GitHub GraphQL API response." -}}
{{- end -}}

0 comments on commit 66a098c

Please sign in to comment.