Skip to content

Commit

Permalink
fix: avoid reading GITHUB_TOKEN env var unnecessarily (#108)
Browse files Browse the repository at this point in the history
Closes #107
  • Loading branch information
razonyang authored Nov 7, 2024
1 parent a54844f commit 5bcb02c
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions layouts/partials/hb/modules/revision/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,27 @@
{{- $editURL = printf "https://github.com/%s/%s/edit/%s/%s" $params.repo_owner $params.repo_name $repoBranch $path }}
{{- $viewURL = printf "https://github.com/%s/%s/blob/%s/%s" $params.repo_owner $params.repo_name $repoBranch $path }}
{{- $historyURL = printf "https://github.com/%s/%s/commits/%s/%s" $params.repo_owner $params.repo_name $repoBranch $path }}
{{- $opts := dict "key" $.Lastmod }}
{{- with getenv "GITHUB_TOKEN" }}
{{- $opts = merge $opts (dict "headers" (dict "Authorization" (printf "Bearer %s" .))) }}
{{- end }}
{{- with and $showContributors (resources.GetRemote $url $opts) }}
{{- with .Err }}
{{- errorf "[github.com/hbstack/revision] failed to fetch %s: %s" $url . }}
{{- if $showContributors }}
{{- $opts := dict "key" $.Lastmod }}
{{- with getenv "GITHUB_TOKEN" }}
{{- $opts = merge $opts (dict "headers" (dict "Authorization" (printf "Bearer %s" .))) }}
{{- end }}
{{- range $weight, $commit := transform.Unmarshal . }}
{{- if not .author }}
{{- continue }}
{{- with resources.GetRemote $url $opts }}
{{- with .Err }}
{{- errorf "[github.com/hbstack/revision] failed to fetch %s: %s" $url . }}
{{- end }}
{{- if not (isset $contributors .author.login) }}
{{- $contributors = merge $contributors (dict .author.login (dict
"weight" $weight
"name" .commit.author.name
"img" .author.avatar_url
"url" .author.html_url))
}}
{{- range $weight, $commit := transform.Unmarshal . }}
{{- if not .author }}
{{- continue }}
{{- end }}
{{- if not (isset $contributors .author.login) }}
{{- $contributors = merge $contributors (dict .author.login (dict
"weight" $weight
"name" .commit.author.name
"img" .author.avatar_url
"url" .author.html_url))
}}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Expand Down

0 comments on commit 5bcb02c

Please sign in to comment.