patch: Add proper fallback for versioning.js#3224
patch: Add proper fallback for versioning.js#3224vipulgupta2048 wants to merge 1 commit intomasterfrom
Conversation
Signed-off-by: Vipul Gupta (@vipulgupta2048) <vipulgupta2048@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the versioning.js tool that fetches GitHub repository releases and creates versioned documentation. The changes improve code organization, error handling, and add comprehensive documentation while maintaining the same core functionality.
- Adds comprehensive JSDoc documentation for all functions
- Refactors large functions into smaller, more focused utility functions
- Improves configuration management with centralized constants
- Enhances error handling and fallback mechanisms
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| REQUEST_TIMEOUT: 10000, | ||
| MIN_SEMANTIC_VERSIONS: 10, | ||
| MIN_COMPATIBLE_TAGS: 5, | ||
| ONE_YEAR_IN_MS: 365 * 24 * 60 * 60 * 1000 |
There was a problem hiding this comment.
The ONE_YEAR_IN_MS constant is defined but never used in the code. Consider removing it or using it in the getOneYearAgo function to replace the setFullYear approach for consistency.
| return createVersionEntry("latest", `${tag.name} latest`, tag.name, tagDate); | ||
| } | ||
|
|
||
| if (tagDate.getTime() < oneYearAgo.getTime()) { |
There was a problem hiding this comment.
Calling getTime() on dates that are already compared multiple times is inefficient. Consider converting dates to timestamps once at the beginning of the function.
| * @returns {Object} Configuration paths and names | ||
| */ | ||
| function generateConfigPaths(repoName) { | ||
| const versionsFileName = repoName.replaceAll(/-/g, ""); |
There was a problem hiding this comment.
Using replaceAll with a global regex is redundant. Use replace(/-/g, '') instead, or keep replaceAll but remove the 'g' flag: replaceAll('-', '').
| const versionsFileName = repoName.replaceAll(/-/g, ""); | |
| const versionsFileName = repoName.replaceAll("-", ""); |
|
Website deployed to CF Pages, 👀 preview link https://ff22ddab.balenacloud-docs.pages.dev |
Create atleast a fallback for the lastest docs and bunch of refactoring fixed to make it more readable.
Signed-off-by: Vipul Gupta (@vipulgupta2048) vipulgupta2048@gmail.com