Poll for Git Mastery problem sets #21
This file contains 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", | |
}) | |
await github.rest.repos.createOrUpdateFileContents({ | |
owner: context.repo.owner, | |
repo: "problems-directory", | |
path: "README.md", | |
message: "Update problem sets list", | |
content: btoa(newReadme), | |
sha: existingReadme.data.sha, | |
}) |