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

Rewrite update-badge action #1838

Merged
merged 8 commits into from
Apr 7, 2024
Merged

Rewrite update-badge action #1838

merged 8 commits into from
Apr 7, 2024

Conversation

ndunnett
Copy link
Contributor

@ndunnett ndunnett commented Apr 6, 2024

This rewrite changes how the action queries the GitHub API to drastically reduce the request rate, this allows processing multiple files so now the markdown files for all years can be updated rather than just the current year. See issue #1837 for context.

Dependency/version changes:

  • Updated action runner from npm12 -> npm20
  • Updated actions/checkout from v2 -> v4
  • Updated actions/core from 1.2.6 -> 1.10.1
  • Updated actions/github from 3.0.0 -> 6.0.0
  • Updated moment from 2.26.0 -> 2.30.1
  • Removed axios

Code changes:

  • update-badge now takes a space delimited list of filenames as an input rather than an input filename and output filename. It will process each file listed and write changes to the same file. The fileNames input in workflows/update-badge.yml will need to be updated each year when the new calendar is started.
  • update-badge now uses GraphQL rather than REST to query each repo's most recent commit. This is because using REST when processing multiple files caused it to get rate limited. The GraphQL queries are done in chunks of 200 repos to avoid getting timed out (too many at once would take >10 seconds to process).
  • GitHub repos that can't be queried (ie. 404) will now be given a red badge. This change can be reverted but IMO it's better to see that a repo is gone without having to click on it, but still keeps it listed for posterity.
  • I restructured the code in update-badge to more logically separate file processing in index.js from querying the GitHub API in updateRepos.js and generating badges in generateBadge.js.
  • Some lines were inadvertently reformatted by prettier (VSCode extension, default settings).

Apologies if I messed anything up, I ran the CI and did some testing locally and it seems to be working as intended. I'm not quite proficient at JS, it's not exactly my lang of choice. 😆

@ndunnett
Copy link
Contributor Author

ndunnett commented Apr 7, 2024

Fixed an edge case where if people added an external repo and didn't put a slash in the link title it would break the link and change the repo name to undefined. Example: 2022.md under M4, repo aoc_eblake. This was a pre-existing bug but probably never mattered because the repos in question were added to files that weren't processed in CI before. Also simplified the file parsing to reduce the amount of if/else nesting.

@Bogdanp
Copy link
Owner

Bogdanp commented Apr 7, 2024

Looks great! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants