Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: make issues and github stuff work outside of CYF #773

Merged
merged 18 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common-theme/layouts/partials/block/data.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{{ else }}
{{ if "github" | in $src }}
{{/* Change base URL to api.github.com */}}
{{ $newSrc := replace $src "https://github.com/CodeYourFuture/" "https://api.github.com/repos/CodeYourFuture/" }}
{{ $newSrc := replace $src "https://github.com/" "https://api.github.com/repos/" }}

{{ if (in $src "issues") }}
{{ .Scratch.SetInMap "blockData" "type" "issue" }}
Expand Down
22 changes: 22 additions & 0 deletions common-theme/layouts/partials/fetch-paginated-issues.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{/* # This is a recursive partial
# The point is to walk the paginated issues
# So we don't lose coursework tasks pushed off page 1 as pull requests start piling up
*/}}
{{/* set the current page we are getting */}}
{{ $issuesUrl := print .issuesUrlBase .page }}
{{/* fetch the issues */}}
{{ $pageOfIssues := getJSON $issuesUrl .headers }}
{{/* get the issues we have so far in our Scratch */}}
{{ $fetchedIssues := .Scratch.Get "issues" }}

{{ if and $pageOfIssues (gt (len $pageOfIssues) 0) }}
{{ range $pageOfIssues }}
{{ $fetchedIssues = $fetchedIssues | append . }}
{{ end }}
{{ .Scratch.Set "issues" $fetchedIssues }}
{{/* If we got 100 issues, there might be more. Let's fetch the next page */}}
{{ if eq (len $pageOfIssues) 100 }}
SallyMcGrath marked this conversation as resolved.
Show resolved Hide resolved
{{ $nextPage := add .page 1 }}
{{ partial "fetch-paginated-issues.html" (dict "Scratch" .Scratch "issuesUrlBase" .issuesUrlBase "page" $nextPage "headers" .headers ) }}
{{ end }}
{{ end }}
20 changes: 12 additions & 8 deletions common-theme/layouts/partials/issues.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
{{ $repo := .Params.backlog }}
{{ $issuesUrl := print .Site.Params.issuesorgapi $repo "/issues?per_page=100&state=open&direction=asc&type=issue" }}
SallyMcGrath marked this conversation as resolved.
Show resolved Hide resolved
{{ $issuesUrlBase := print .Site.Params.issuesorgapi $repo "/issues?per_page=100&state=open&direction=asc&page=" }}
{{ $filter := .Params.backlog_filter }}
{{ $currentPath := .Page.RelPermalink }}
<!-- api call -->
{{/* <!-- api call --> */}}
{{ $headers := (dict) }}
{{ if ne (os.Getenv "HUGO_CURRICULUM_GITHUB_BEARER_TOKEN") "" }}
{{ $headers = merge $headers (dict "Authorization" (printf "Bearer %s" (getenv "HUGO_CURRICULUM_GITHUB_BEARER_TOKEN"))) }}
{{ end }}
{{ $issues := getJSON $issuesUrl $headers }}
<!-- if no object show error -->
{{/* <!-- walk through paginated issues --> */}}
{{ .Page.Scratch.Set "issues" slice }}
SallyMcGrath marked this conversation as resolved.
Show resolved Hide resolved
{{ partial "fetch-paginated-issues.html" (dict "Scratch" .Page.Scratch "issuesUrlBase" $issuesUrlBase "currentPath" $currentPath "page" 1 "headers" $headers) }}
{{ $issues := .Page.Scratch.Get "issues" }}

{{/* <!-- if no object show error --> */}}
{{ if ne $issues nil }}
<!-- range over issues list and pull out useful data -->
{{/* <!-- range over issues list and pull out useful data --> */}}
{{ range $issues }}

{{ $showIssue := true }}
<!-- if a filter exists, only show issues with the right label -->
{{/* <!-- if a filter exists, only show issues with the right label --> */}}
{{ if $filter }}
{{ $showIssue = false }}
{{ range .labels }}
Expand All @@ -25,7 +29,7 @@
{{ end }}
{{ end }}
{{ end }}
<!-- now show the issue -->
{{/* <!-- now show the issue --> */}}
{{ if $showIssue }}
{{ if strings.Contains .body "_No response_" }}
{{ errorf "Issue %s contains _No response_ - please edit the issue to remove it." .html_url }}
Expand Down Expand Up @@ -64,5 +68,5 @@
{{ end }}
{{ end }}
{{ else }}
{{ errorf "Error, fetch of %s failed: %v" $issuesUrl $issues }}
{{ errorf "Error, fetch of %s failed: %v" $issuesUrlBase $issues }}
{{ end }}
3 changes: 2 additions & 1 deletion org-mcb/assets/custom-images/site-logo/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions org-mcb/config/issues-are-cached-and-incomplete/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This config is optimised for speed of local interation of general Hugo set-up without worrying about issue freshness or completeness.
# To build with this config, run `hugo server --environment issues-are-cached-and-incomplete`.

[params]
# Don't use the paginating proxy, because it's slow.
# This means some issues will be missing when fetched.
issuesorgapi = "https://api.github.com/repos/Migracode-Barcelona/"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can probably rm all this, though I did like just skipping pagination on local


[caches.getjson]
# Cache JSON responses because making fetches is slow when iterating.
# This means updates to issues (or newly created ones) won't be picked up when rebuilding.
maxAge = "4h"
10 changes: 4 additions & 6 deletions org-mcb/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ description = "A free and open source software development programme."
main_website = "https://migracode.org/"
main_org_name = "MigraCode Barcelona"
our_name="MCB"
org = "https://github.com/CodeYourFuture"
repo = "https://github.com/CodeYourFuture/curriculum/"
org = "https://github.com/Migracode-Barcelona"
SallyMcGrath marked this conversation as resolved.
Show resolved Hide resolved
repo = "https://github.com/CodeYourFuture/curriculum/org-mcb"
root = "curriculum"
orgapi = "https://api.github.com/repos/CodeYourFuture/"
# We use a proxy which concatenates paginated responses, otherwise we miss results.
# Daniel is currently hosting this code https://github.com/illicitonion/github-issue-proxy but we should work out a long-term maintainable solution to this problem.
issuesorgapi = "https://github-issue-proxy.illicitonion.com/repos/CodeYourFuture/"
orgapi = "https://api.github.com/repos/Migracode-Barcelona/"



[security.funcs]
Expand Down
Loading