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 all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 1 addition & 3 deletions common-theme/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ repo = "https://github.com/YOUR_ORG_HERE/YOUR_REPO/"
root = "YOUR_REPO_I_THINK"
orgapi = "https://api.github.com/repos/YOUR_ORG_HERE/"
pdrepo = "PD-curriculum-repo"
# 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/"


[markup]
[markup.tableOfContents]
Expand Down
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
1 change: 0 additions & 1 deletion common-theme/layouts/partials/block/pullreq.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ <h2 class="e-heading__2" id="{{ $id }}">
>See more pull requests</a
>
</section>
{{ else if eq ($response | len) 0 }}
{{ else }}
{{ errorf "Error, fetch of %s failed: %v" $blockData.api $response }}
{{ end }}
29 changes: 29 additions & 0 deletions common-theme/layouts/partials/fetch-paginated-issues.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{/* # 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 using the new style in v0.127 */}}
{{ $pageOfIssues := resources.GetRemote $issuesUrl .headers }}

{{ if eq nil $pageOfIssues }}
{{ errorf "🏷️ Issues not fetched: API at %s returned nil" $issuesUrl }}
{{ else if $pageOfIssues.Err }}
{{ errorf "🏷️ Issues not fetched: %s" $pageOfIssues.Err }}
{{ else }}
{{ if ne $pageOfIssues nil }}
{{ $pageOfIssues = $pageOfIssues.Content | transform.Unmarshal }}

{{/* get the issues we have so far in our Scratch.
This how we make these issues available to our parent partial issues.html
*/}}
{{ $fetchedIssues := .Scratch.Get "issues" }}
{{ .Scratch.Set "issues" (append $fetchedIssues $pageOfIssues) }}
{{/* If we got 100 issues, there might be more. Let's fetch the next page */}}
{{ if eq (len $pageOfIssues) 99 }}
{{ $nextPage := add .page 1 }}
{{ partial "fetch-paginated-issues.html" (dict "Scratch" .Scratch "issuesUrlBase" .issuesUrlBase "page" $nextPage "headers" .headers ) }}
{{ end }}
{{ end }}
{{ end }}
27 changes: 16 additions & 11 deletions common-theme/layouts/partials/issues.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
{{ $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
{{ $filter := .Params.backlog_filter }}
{{ $issuesUrlBase := print $.Site.Params.orgapi $repo "/issues?per_page=100&state=open&direction=asc&page=" }}
{{ $currentPath := .Page.RelPermalink }}
<!-- 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"))) }}
{{/* <!-- api call --> */}}
{{ $headers := dict }}
{{ $token := os.Getenv "HUGO_CURRICULUM_GITHUB_BEARER_TOKEN" }}
{{ if ne $token "" }}
{{ $headers = dict "headers" (dict "Authorization" (print "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 +30,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 +69,5 @@
{{ end }}
{{ end }}
{{ else }}
{{ errorf "Error, fetch of %s failed: %v" $issuesUrl $issues }}
{{ errorf "Error, fetch of %s failed: %v" $issuesUrlBase $issues }}
{{ end }}
31 changes: 19 additions & 12 deletions common-theme/layouts/shortcodes/contributors.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
{{ $repo := .Get 0 }}
{{ $repo := .Get 0 |default $.Site.Params.orgapi }}
{{ $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 }}
{{ $contributors := getJSON (printf "%s%s/contributors" $.Site.Params.orgapi $repo) $headers }}
{{ $contributors := printf "%s/contributors" $repo }}
{{ $contributors := resources.GetRemote $contributors $headers }}

{{ if $contributors.Err }}
{{ errorf "🏷️ No contributors: %s . Error: %s" $repo $contributors.Err }}
{{ else }}
{{ $contributors = $contributors.Content | transform.Unmarshal }}

<ol class="c-contributors">
{{ range sort $contributors ".contributions" "desc" }}
<li class="c-contributor">
<h3 class="c-contributor__name">
<a class="c-contributor__link" href="{{ .html_url }}">{{ .login }}</a>
</h3>
<img class="c-contributor__avatar" src="{{ .avatar_url }}" alt="" />
</li>
{{ end }}
</ol>

<ol class="c-contributors">
{{ range sort $contributors ".contributions" "desc" }}
<li class="c-contributor">
<h3 class="c-contributor__name">
<a class="c-contributor__link" href="{{ .html_url }}">{{ .login }}</a>
</h3>
<img class="c-contributor__avatar" src="{{ .avatar_url }}" alt="" />
</li>
{{ end }}
</ol>
{{ end }}
4 changes: 2 additions & 2 deletions org-cyf-guides/content/contributing/contributors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ emoji: 🧑🏿‍🤝‍🧑🏿

## ⏳ 2023 Curriculum

{{< contributors "curriculum">}}
{{< contributors "https://api.github.com/repos/CodeYourFuture/curriculum" >}}

## ⌛ [2020 Syllabus](https://syllabus.codeyourfuture.io/)

{{< contributors "syllabus">}}
{{< contributors "https://api.github.com/repos/CodeYourFuture/syllabus" >}}

➕➕ Plus hundreds of volunteers who have contributed to the curriculum and classes since 2016.

Expand Down
3 changes: 0 additions & 3 deletions org-cyf-guides/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ repo = "https://github.com/CodeYourFuture/curriculum/"
pdrepo = "CYF-PD"
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/"


[caches.getjson]
Expand Down
4 changes: 2 additions & 2 deletions org-cyf-guides/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "dotenv -e ../.env -- hugo server --environment issues-are-cached-and-incomplete",
"build:dev": "dotenv -e ../.env -- hugo --environment issues-are-cached-and-incomplete"
"start:dev": "dotenv -e ../.env -- hugo server --environment development",
"build:dev": "dotenv -e ../.env -- hugo --environment development"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 0 additions & 4 deletions org-cyf-itp/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ repo = "https://github.com/CodeYourFuture/curriculum/"
pdrepo = "CYF-PD"
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/"


[caches.getjson]
# Disable caching of fetches - we want every build to get up to date content for issues, so that if people make clarifications or fixes to issues, we pick them up.
Expand Down
4 changes: 2 additions & 2 deletions org-cyf-itp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "dotenv -e ../.env -- hugo server --environment issues-are-cached-and-incomplete",
"build:dev": "dotenv -e ../.env -- hugo --environment issues-are-cached-and-incomplete"
"start:dev": "dotenv -e ../.env -- hugo server --environment development",
"build:dev": "dotenv -e ../.env -- hugo --environment development"
},
"keywords": [],
"author": "",
Expand Down
3 changes: 0 additions & 3 deletions org-cyf-piscine/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ repo = "https://github.com/CodeYourFuture/curriculum/"
pdrepo = "CYF-PD"
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/"


[caches.getjson]
Expand Down
4 changes: 2 additions & 2 deletions org-cyf-piscine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "dotenv -e ../.env -- hugo server --environment issues-are-cached-and-incomplete",
"build:dev": "dotenv -e ../.env -- hugo --environment issues-are-cached-and-incomplete"
"start:dev": "dotenv -e ../.env -- hugo server --environment development",
"build:dev": "dotenv -e ../.env -- hugo --environment development"
},
"keywords": [],
"author": "",
Expand Down
3 changes: 0 additions & 3 deletions org-cyf-sdc/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ repo = "https://github.com/CodeYourFuture/curriculum/"
pdrepo = "CYF-PD"
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/"


[caches.getjson]
Expand Down
4 changes: 2 additions & 2 deletions org-cyf-sdc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "dotenv -e ../.env -- hugo server --environment issues-are-cached-and-incomplete",
"build:dev": "dotenv -e ../.env -- hugo --environment issues-are-cached-and-incomplete"
"start:dev": "dotenv -e ../.env -- hugo server --environment development",
"build:dev": "dotenv -e ../.env -- hugo --environment development"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 0 additions & 4 deletions org-cyf/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ repo = "https://github.com/CodeYourFuture/curriculum/"
pdrepo = "CYF-PD"
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/"


[caches.getjson]
# Disable caching of fetches - we want every build to get up to date content for issues, so that if people make clarifications or fixes to issues, we pick them up.
Expand Down
4 changes: 2 additions & 2 deletions org-cyf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "dotenv -e ../.env -- hugo server --environment issues-are-cached-and-incomplete",
"build:dev": "dotenv -e ../.env -- hugo --environment issues-are-cached-and-incomplete"
"start:dev": "dotenv -e ../.env -- hugo server --environment development",
"build:dev": "dotenv -e ../.env -- hugo --environment development"
},
"keywords": [],
"author": "",
Expand Down
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"
6 changes: 0 additions & 6 deletions org-mcb/content/_index copy.md

This file was deleted.

7 changes: 0 additions & 7 deletions org-mcb/content/cloud/_index.md

This file was deleted.

Loading
Loading