Debian Codegraph @

docs/layouts/_partials/helpers/funcs/get-github-info.html

raw
1 {{ $url := "https://api.github.com/repos/gohugoio/hugo" }}
2 {{ $cacheKey := print $url (now.Format "2006-01-02") }}
3 {{ $headers := dict }}
4 {{ with os.Getenv "HUGO_GH_TOKEN" }}
5 {{ $headers = dict "Authorization" (printf "Bearer %s" .) }}
6 {{ end }}
7 {{ $opts := dict "headers" $headers "key" $cacheKey }}
8 {{ $githubRepoInfo := dict }}
9 {{ with try (resources.GetRemote $url $opts) }}
10 {{ with .Err }}
11 {{ warnf "Failed to get GitHub repo info: %s" . }}
12 {{ else with (.Value | transform.Unmarshal) }}
13 {{ $githubRepoInfo = dict
14 "html_url" .html_url
15 "stargazers_url" .stargazers_url
16 "watchers_count" .watchers_count
17 "stargazers_count" .stargazers_count
18 "forks_count" .forks_count
19 "contributors_url" .contributors_url
20 "releases_url" .releases_url
21 "forks_count" .forks_count
22 }}
23 {{ else }}
24 {{ errorf "Unable to get remote resource %q" $url }}
25 {{ end }}
26 {{ end }}
27
28 {{ return $githubRepoInfo }}