Skip to content

Commit

Permalink
fix(git-repo): correct the humanize function for "m" unit. (#564)
Browse files Browse the repository at this point in the history
fix(git-org): correct the humanize function for `m` unit.
fix(git-repo): replace `getJSON` with `resources.getRemote`.
fix(git-org): replace `getJSON` with `resources.getRemote`.
  • Loading branch information
razonyang authored Mar 25, 2024
1 parent 4f7c0dd commit 93fe92a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
{{- $data := newScratch }}
{{- $service := default "github" .service }}
{{- if eq $service "github" }}
{{- $opts := dict }}
{{- $opts := newScratch }}
{{- $ghToken := getenv "GITHUB_TOKEN" }}
{{- with $ghToken }}
{{- $opts := dict "Authorization" (printf "Bearer %s" .) }}
{{- $opts.SetInMap "headers" "Authorization" (printf "Bearer %s" .) }}
{{- end }}
{{- with getJSON (printf "https://api.github.com/users/%s" .name) $opts }}
{{- $data.Set "URL" .html_url }}
{{- $data.Set "Name" .name }}
{{- $data.Set "Repos" .public_repos }}
{{- $data.Set "Followers" .followers }}
{{- $data.Set "AvatarURL" (printf "%s&s=32" .avatar_url) }}
{{- with resources.GetRemote (printf "https://api.github.com/users/%s" .name) $opts.Values }}
{{- with .Err }}
{{- errorf "[git-org] unable to fetch org information from GitHub: %s." . }}
{{- else }}
{{- $org := .Content | transform.Unmarshal }}
{{- $data.Set "URL" $org.html_url }}
{{- $data.Set "Name" $org.name }}
{{- $data.Set "Repos" $org.public_repos }}
{{- $data.Set "Followers" $org.followers }}
{{- $data.Set "AvatarURL" (printf "%s&s=32" $org.avatar_url) }}
{{- end }}
{{- end }}
{{/* Get stars. */}}
{{- $stars := 0 }}
{{- with getJSON (printf "https://api.github.com/users/%s/repos?per_page=100" .name) $opts }}
{{- with resources.GetRemote (printf "https://api.github.com/users/%s/repos?per_page=100" .name) $opts.Values }}
{{- $repos := slice }}
{{- range . }}
{{- $reposResponse := .Content | transform.Unmarshal }}
{{- range $reposResponse }}
{{- $repos = $repos | append (printf "repo:%s" .full_name) }}
{{- end }}
{{- $graphqlAPI := "https://api.github.com/graphql" }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if gt . 1e5 -}}
{{- if gt . 1e6 -}}
{{- printf "%.1fm" (div . 1e6) -}}
{{- else if gt . 1e3 -}}
{{- printf "%.1fk" (div . 1e3) -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,39 @@
{{- $service := default "github" .service }}
{{- $params := default dict site.Params.hb.header.git_repo }}
{{- if eq $service "github" }}
{{- $opts := dict }}
{{- $opts := newScratch }}
{{- with getenv "GITHUB_TOKEN" }}
{{- $opts := dict "Authorization" (printf "Bearer %s" .) }}
{{- $opts.SetInMap "headers" "Authorization" (printf "Bearer %s" .) }}
{{- end }}
{{- with getJSON (printf "https://api.github.com/repos/%s/%s" .owner .name) $opts }}
{{- $data.Set "Title" .full_name }}
{{- $data.Set "URL" .html_url }}
{{- $data.Set "Stars" .stargazers_count }}
{{- $data.Set "Forks" .forks_count }}
{{- with resources.GetRemote (printf "https://api.github.com/repos/%s/%s" .owner .name) $opts.Values }}
{{- with .Err }}
{{- errorf "[git-repo] unable to fetch repo information from GitHub: %s." . }}
{{- else }}
{{- $repo := .Content | transform.Unmarshal }}
{{- $data.Set "Title" $repo.full_name }}
{{- $data.Set "URL" $repo.html_url }}
{{- $data.Set "Stars" $repo.stargazers_count }}
{{- $data.Set "Forks" $repo.forks_count }}
{{- end }}
{{- end }}
{{- if default true $params.tag }}
{{- with getJSON (printf "https://api.github.com/repos/%s/%s/releases/latest" .owner .name) $opts }}
{{- $data.Set "Tag" .tag_name }}
{{- with resources.GetRemote (printf "https://api.github.com/repos/%s/%s/releases/latest" .owner .name) $opts.Values }}
{{- with .Err }}
{{- errorf "[git-repo] unable to fetch latest release from GitHub: %s." . }}
{{- else }}
{{- $release := .Content | transform.Unmarshal }}
{{- $data.Set "Tag" $release.tag_name }}
{{- end }}
{{- end }}
{{- end }}
{{- with $params.docker }}
{{- with getJSON (printf "https://hub.docker.com/v2/repositories/%s/%s" .namespace .name) $opts }}
{{- $data.Set "DockerPulls" .pull_count }}
{{- with resources.GetRemote (printf "https://hub.docker.com/v2/repositories/%s/%s" .namespace .name) }}
{{- with .Err }}
{{- errorf "[git-repo] unable to fetch stats from DockerHub: %s." . }}
{{- else }}
{{- $dockerHubData := .Content | transform.Unmarshal }}
{{- $data.Set "DockerPulls" $dockerHubData.pull_count }}
{{- end }}
{{- end }}
{{- end }}
{{- else }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if gt . 1e5 -}}
{{- if gt . 1e6 -}}
{{- printf "%.1fm" (div . 1e6) -}}
{{- else if gt . 1e3 -}}
{{- printf "%.1fk" (div . 1e3) -}}
Expand Down

0 comments on commit 93fe92a

Please sign in to comment.