This repository was archived by the owner on Jun 15, 2025. It is now read-only.
Poll for Git Mastery problem sets #136
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Poll for Git Mastery problem sets | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 12 * * *" | |
jobs: | |
poll: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fetch all | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.ORG_PAT }} | |
script: | | |
const repos = await github.paginate(github.rest.search.repos, { | |
q: "topic:problem-set org:git-mastery", | |
}) | |
const repoGroups = new Map(); | |
for (const repo of repos) { | |
for (const topic of repo.topics) { | |
if (topic !== "problem-set") { | |
if (!repoGroups.has(topic)) { | |
repoGroups.set(topic, []) | |
} | |
repoGroups.get(topic).push(repo) | |
} | |
} | |
} | |
let newReadme = ` | |
# Git Mastery Problems Directory | |
To download any of these repositories, follow the [setup instructions here](https://git-mastery.github.io/website/docs/setup/prerequisite-setup/). | |
With the download script, run the following command for each problem set: | |
\`\`\`bash | |
bash download.sh <exercise name> | |
\`\`\` | |
` | |
new Map([...repoGroups.entries()].sort()).forEach((value, key) => { | |
const data = value.map(v => `|${v.name}|[Instructions](${v.html_url})|${v.forks_count}|`).join("\n") | |
newReadme += ` | |
## \`${key}\` | |
|Exercise|Link|Attempts| | |
|--------|----|--------| | |
${data} | |
` | |
}) | |
const existingReadme = await github.rest.repos.getContent({ | |
owner: context.repo.owner, | |
repo: "problems-directory", | |
path: "README.md", | |
}) | |
const existingMap = await github.rest.repos.getContent({ | |
owner: context.repo.owner, | |
repo: "problems-directory", | |
path: "problems.json", | |
}) | |
await github.rest.repos.createOrUpdateFileContents({ | |
owner: context.repo.owner, | |
repo: "problems-directory", | |
path: "README.md", | |
message: "Update problem sets list in README", | |
content: btoa(newReadme), | |
sha: existingReadme.data.sha, | |
}) | |
await github.rest.repos.createOrUpdateFileContents({ | |
owner: context.repo.owner, | |
repo: "problems-directory", | |
path: "problems.json", | |
message: "Update problem sets data", | |
content: btoa(JSON.stringify(repos)), | |
sha: existingMap.data.sha, | |
}) |