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

Refresh deps #632

Merged
merged 24 commits into from
Dec 28, 2023
Merged

Refresh deps #632

merged 24 commits into from
Dec 28, 2023

Conversation

Akiyamka
Copy link
Contributor

@Akiyamka Akiyamka commented Dec 15, 2023

Summary by CodeRabbit

  • New Features

    • Implemented a new deployment automation script to streamline application releases.
    • Added a search bar to enhance user navigation within the app.
    • Introduced a script for identifying unused dependencies to optimize app performance.
  • Bug Fixes

    • Corrected the import statement for jwtDecode to ensure proper functionality.
  • Documentation

    • Updated the .npmrc file to enable pre and post-install scripts for better dependency management.
  • Refactor

    • Transitioned from using mapboxgl.Expression to maplibregl.Expression to align with library updates.
    • Adjusted the isDownloadable logic for layer source types for clarity and correctness.
  • Style

    • Increased the margin of the .errorMessageContainer for better visual spacing in user interface.
  • Chores

    • Switched from npm to pnpm commands in various CI/CD workflows to improve build processes.
    • Updated Dependabot configuration to monthly interval for dependency checks.
    • Removed unnecessary console.debug statement for cleaner code.
  • Configurations

    • Removed VITE_HTTPS variable from development and production environments for simplified configuration management.
  • Security

    • Enabled HTTPS unconditionally in development mode for enhanced security during testing.

first round of non breaking updates
Copy link
Contributor

coderabbitai bot commented Dec 15, 2023

Walkthrough

The changes reflect a shift towards stricter type safety, enhanced script execution control in npm, a transition from npm to pnpm for package management, and adjustments in styling and configurations. There's also a move to update the map library expressions and streamline the deployment process with new scripts, indicating a focus on modernization and efficiency improvements.

Changes

File Path Change Summary
.npmrc Enabled pre-post scripts; retained strict peer dependencies setting.
src/core/.../LocalEditableGeojsonLayer.ts Removed assignment to data.features; updated destructuring for geojsonIcons.
src/core/.../stylesConfigs/mcda/types.ts Updated type from mapboxgl.Expression to maplibregl.Expression.
src/core/.../logicalLayerFabric.ts Simplified isDownloadable property logic.
src/features/.../FakeSensor.ts Used globalThis for interval methods; updated interval type.
src/features/mcda/parser/validator.ts Changed type declaration to maplibregl.Expression.
scripts/depcheck.js Added new script for dependency checking.
src/core/api_client/apiClient.ts Changed import for jwtDecode from default to named.
.github/dependabot.yml Modified Dependabot schedule from daily to monthly.
.github/workflows/... Replaced npm commands with pnpm; updated Node.js version to 18.
deployment.js Added new deployment automation script.
.eslintrc.json Added warning for any type usage.
src/features/.../LoginForm.module.css Increased margin-top in .errorMessageContainer.
src/utils/storage/index.ts Removed console.debug statement.
.env.development, .env.production Removed VITE_HTTPS variable; modified VITE_DEBUG_RENDER_TRACKER.
vite.config.ts Removed VITE_HTTPS variable; enabled HTTPS unconditionally for development.
scripts/deployment.mjs Introduced deployment automation script.

🐇✨
In the burrow of the code, beneath the moon's soft glow,
A rabbit hopped through lines, with updates in tow.
From npm to pnpm, with scripts anew,
A modern leap taken, to the future we hop through! 🚀🌟

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e97dd09 and 8c00033.
Files ignored due to filter (2)
  • package.json
  • pnpm-lock.yaml
Files selected for processing (6)
  • .npmrc (1 hunks)
  • src/core/draw_tools/layers/LocalEditableGeojsonLayer.ts (2 hunks)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/types.ts (1 hunks)
  • src/core/logical_layers/utils/logicalLayerFabric.ts (1 hunks)
  • src/features/live_sensor/tests/FakeSensor.ts (2 hunks)
  • src/features/mcda/parser/validator.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • .npmrc
Additional comments: 7
src/core/draw_tools/layers/LocalEditableGeojsonLayer.ts (2)
  • 86-91: The removal of the conditional logic and direct assignment of an empty array to data.features simplifies the code. However, ensure that this change does not affect the functionality where data.features is expected to be a transformed version of this.props.data.features.

  • 108-109: The restructuring of the destructuring assignment for this.props.geojsonIcons properties is a good improvement for code clarity and maintainability.

src/core/logical_layers/renderers/stylesConfigs/mcda/types.ts (1)
  • 1-4: The update to the ColorsByMapLibreExpression type's parameters property is consistent with the PR's objective to switch from Mapbox GL to MapLibre GL expressions. Ensure that all usages of this type are compatible with the new maplibregl.Expression type.
src/features/live_sensor/tests/FakeSensor.ts (4)
  • 12-12: The change from NodeJS.Timer to number for the interval property type aligns with the use of window.setInterval and window.clearInterval, which is appropriate for browser environments.

  • 21-23: Using window.setInterval ensures that the correct function is used in the browser context and avoids potential issues with Node.js types.

  • 29-29: Using window.clearInterval ensures that the correct function is used in the browser context.

  • 12-12: Verify if there are any other places in the codebase where the old NodeJS.Timer type is used and should be updated to number to ensure consistency with the changes made here.

Verification successful

The executed script searched for occurrences of NodeJS.Timer in TypeScript files throughout the codebase and did not produce any output. This suggests that there are no remaining references to NodeJS.Timer in TypeScript files, which would imply that the change to use number | null for the interval property in FakeSensor.ts is consistent with the rest of the codebase.

Given this information, it seems that the change to number | null is the only instance of this type change, and no further updates are needed to maintain consistency.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old `NodeJS.Timer` type usage in the codebase.
rg 'NodeJS.Timer' --type ts

Length of output: 27

src/features/mcda/parser/validator.ts Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8c00033 and ca934ce.
Files ignored due to filter (3)
  • package-lock.json
  • package.json
  • pnpm-lock.yaml
Files selected for processing (2)
  • scripts/depcheck.js (1 hunks)
  • src/core/api_client/apiClient.ts (1 hunks)
Additional comments: 1
src/core/api_client/apiClient.ts (1)
  • 4-4: The change from a default import to a named import of jwtDecode is consistent with the PR's objective of updating dependencies. Ensure that this change is reflected across the entire codebase wherever jwtDecode is used.
Verification successful

I will correct the regex errors in the shell scripts and rerun them to verify the usage of jwtDecode across the codebase.


To ensure that the change to the jwtDecode import is consistent across the codebase, I will search for any usage of jwtDecode to verify that it is not being imported using the old default import pattern elsewhere.


The search results indicate that jwtDecode is only used in src/core/api_client/apiClient.ts, where it is imported with the new named import pattern and used accordingly. There are no instances of the old default import pattern for jwtDecode in the codebase, which suggests that the update to the named import is consistent and complete.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old default import usage of jwtDecode and ensure it's replaced with the named import.
rg "import jwtDecode from 'jwt-decode'"
# Search for the new named import usage of jwtDecode to confirm the change is consistent across the codebase.
rg "import { jwtDecode } from 'jwt-decode'"

Length of output: 229



Script:

#!/bin/bash
# Search for the old default import usage of jwtDecode and ensure it's replaced with the named import.
rg "import jwtDecode from 'jwt-decode'"
# Search for the new named import usage of jwtDecode to confirm the change is consistent across the codebase.
rg "import \{ jwtDecode \} from 'jwt-decode'"

Length of output: 174



Script:

#!/bin/bash
# Search for usage of jwtDecode to ensure it's not being imported with the old pattern anywhere in the codebase.
rg "jwtDecode"

Length of output: 265

scripts/depcheck.js Show resolved Hide resolved
scripts/depcheck.js Show resolved Hide resolved
scripts/depcheck.js Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ca934ce and f368e78.
Files selected for processing (6)
  • .github/dependabot.yml (1 hunks)
  • .github/workflows/build.yml (3 hunks)
  • .github/workflows/deploy_cosmos.yml (1 hunks)
  • .github/workflows/size_report.yml (2 hunks)
  • .github/workflows/translations_report.yml (1 hunks)
  • deployment.js (1 hunks)
Files skipped from review due to trivial changes (2)
  • .github/workflows/size_report.yml
  • .github/workflows/translations_report.yml
Additional comments: 7
.github/dependabot.yml (1)
  • 11-11: The change to a monthly update interval for Dependabot will reduce the frequency of automated dependency updates. Ensure that this aligns with the project's maintenance strategy and that dependencies do not become too outdated, potentially missing important updates or security patches.
.github/workflows/build.yml (3)
  • 47-51: The steps to install dependencies and run scripts have been correctly updated to use pnpm commands. This change is consistent with the PR's objective to refresh dependencies and move from npm to pnpm.

  • 61-67: The Node.js version has been updated to version 18. Ensure that all project dependencies are compatible with this Node.js version to prevent any potential issues during the build or runtime.

Verification successful

The output from the shell script confirms that the package.json file specifies that the project requires a Node.js version of >=18. This means that the update to Node.js version 18 in the .github/workflows/build.yml is compatible with the project's requirements.

Final response:

The Node.js version has been updated to version 18 in the CI/CD workflow, which is compatible with the project's requirements as specified in the package.json file. No issues found with this change.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check the `package.json` file for engines.node to verify compatibility with Node.js version 18.
rg '"engines":' -A 3 package.json

Length of output: 89

* 64-65: The build job has been updated to use `pnpm ci --include=dev` and `pnpm run build`. These changes are consistent with the switch to pnpm and should work as expected if the project's `pnpm` scripts are correctly defined.
.github/workflows/deploy_cosmos.yml (1)
  • 19-20: The switch from npm to pnpm commands in the CI workflow is noted. Ensure that the CI environment has pnpm installed and that it is compatible with the project's package management setup.
deployment.js (2)
  • 15-15: Hardcoded tag value.

  • 94-94: Unclear assignment of prevCommitSHA.

.github/workflows/build.yml Outdated Show resolved Hide resolved
@konturio konturio deleted a comment from coderabbitai bot Dec 16, 2023
@konturio konturio deleted a comment from coderabbitai bot Dec 16, 2023
@konturio konturio deleted a comment from coderabbitai bot Dec 16, 2023
@konturio konturio deleted a comment from coderabbitai bot Dec 16, 2023
@konturio konturio deleted a comment from coderabbitai bot Dec 16, 2023
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ca934ce and 0488e17.
Files selected for processing (5)
  • .github/dependabot.yml (1 hunks)
  • .github/workflows/build.yml (4 hunks)
  • .github/workflows/deploy_cosmos.yml (1 hunks)
  • .github/workflows/size_report.yml (2 hunks)
  • .github/workflows/translations_report.yml (1 hunks)
Files skipped from review due to trivial changes (3)
  • .github/dependabot.yml
  • .github/workflows/deploy_cosmos.yml
  • .github/workflows/size_report.yml
Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/build.yml
  • .github/workflows/translations_report.yml

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0488e17 and 63f8b62.
Files selected for processing (3)
  • .github/workflows/build.yml (4 hunks)
  • .github/workflows/size_report.yml (1 hunks)
  • .github/workflows/translations_report.yml (1 hunks)
Files skipped from review due to trivial changes (2)
  • .github/workflows/build.yml
  • .github/workflows/size_report.yml
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/translations_report.yml

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 63f8b62 and 562c7eb.
Files selected for processing (3)
  • .github/workflows/build.yml (4 hunks)
  • .github/workflows/size_report.yml (1 hunks)
  • .github/workflows/translations_report.yml (1 hunks)
Files skipped from review due to trivial changes (2)
  • .github/workflows/size_report.yml
  • .github/workflows/translations_report.yml
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/build.yml

Copy link

[
{
language: 'ar',
fileName: '/ar/common.po',
counts: {
toRecheckStrings: 3,
toRecheckWords: 3,
fuzzyStrings: 7,
fuzzyWords: 24,
untranslatedStrings: 19,
untranslatedWords: 101,
totalUnverifiedWords: 128
}
},
{
language: 'de',
fileName: '/de/common.po',
counts: {
toRecheckStrings: 2,
toRecheckWords: 2,
fuzzyStrings: 7,
fuzzyWords: 24,
untranslatedStrings: 19,
untranslatedWords: 101,
totalUnverifiedWords: 127
}
},
{
language: 'es',
fileName: '/es/common.po',
counts: {
toRecheckStrings: 3,
toRecheckWords: 3,
fuzzyStrings: 7,
fuzzyWords: 24,
untranslatedStrings: 19,
untranslatedWords: 101,
totalUnverifiedWords: 128
}
},
{
language: 'id',
fileName: '/id/common.po',
counts: {
toRecheckStrings: 2,
toRecheckWords: 2,
fuzzyStrings: 7,
fuzzyWords: 24,
untranslatedStrings: 19,
untranslatedWords: 101,
totalUnverifiedWords: 127
}
},
{
language: 'ko',
fileName: '/ko/common.po',
counts: {
toRecheckStrings: 3,
toRecheckWords: 3,
fuzzyStrings: 7,
fuzzyWords: 24,
untranslatedStrings: 19,
untranslatedWords: 101,
totalUnverifiedWords: 128
}
},
{
language: 'uk',
fileName: '/uk/common.po',
counts: {
toRecheckStrings: 0,
toRecheckWords: 0,
fuzzyStrings: 1,
fuzzyWords: 7,
untranslatedStrings: 5,
untranslatedWords: 8,
totalUnverifiedWords: 15
}
}
]

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 562c7eb and b4164ac.
Files ignored due to filter (2)
  • package.json
  • pnpm-lock.yaml
Files selected for processing (1)
  • .eslintrc.json (1 hunks)
Additional comments: 1
.eslintrc.json (1)
  • 41-41: Adding the @typescript-eslint/no-explicit-any rule with a severity level of "warn" is a good practice to discourage the use of the any type and promote type safety.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b4164ac and 63cf0ed.
Files selected for processing (1)
  • src/features/user_profile/components/LoginForm/LoginForm.module.css (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/features/user_profile/components/LoginForm/LoginForm.module.css

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 63cf0ed and 3734e8d.
Files ignored due to filter (2)
  • package.json
  • pnpm-lock.yaml
Files selected for processing (2)
  • src/features/live_sensor/tests/FakeSensor.ts (2 hunks)
  • src/utils/storage/index.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/utils/storage/index.ts
Files skipped from review as they are similar to previous changes (1)
  • src/features/live_sensor/tests/FakeSensor.ts

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (4f300ef) 8.21% compared to head (1ec781a) 8.21%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #632   +/-   ##
=====================================
  Coverage   8.21%   8.21%           
=====================================
  Files        600     599    -1     
  Lines      40825   40800   -25     
  Branches    1051    1050    -1     
=====================================
- Hits        3354    3353    -1     
+ Misses     36950   36927   -23     
+ Partials     521     520    -1     
Files Coverage Δ
src/core/api_client/apiClient.ts 65.25% <100.00%> (ø)
src/features/live_sensor/tests/FakeSensor.ts 100.00% <100.00%> (ø)
src/utils/storage/index.ts 79.48% <ø> (-0.26%) ⬇️
...gical_layers/renderers/stylesConfigs/mcda/types.ts 0.00% <0.00%> (ø)
...rc/core/logical_layers/utils/logicalLayerFabric.ts 0.00% <0.00%> (ø)
src/features/mcda/parser/validator.ts 0.00% <0.00%> (ø)
...ore/draw_tools/layers/LocalEditableGeojsonLayer.ts 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3734e8d and a032679.
Files ignored due to filter (3)
  • devbox.json
  • package.json
  • pnpm-lock.yaml
Files selected for processing (3)
  • .env.development (1 hunks)
  • .env.production (1 hunks)
  • vite.config.ts (3 hunks)
Files skipped from review due to trivial changes (1)
  • .env.production
Additional comments: 2
.env.development (1)
  • 5-8: The removal of VITE_HTTPS=false from the .env.development file is not visible in the hunk but is mentioned in the summary. This change could have significant implications on the development environment's network communication protocol. Ensure that the application's behavior without this environment variable is well understood and documented, and that any necessary adjustments are made to the development setup and documentation.
vite.config.ts (1)
  • 97-103: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [34-117]

The removal of VITE_HTTPS from the environment configuration and the unconditional enabling of HTTPS in development mode with mkcert() should be double-checked for potential side effects. Ensure that all references to VITE_HTTPS are removed and that the development environment is correctly configured to serve over HTTPS by default.

Verification successful

The previous script attempted to use rg with an unrecognized file type typescript. Ripgrep does not have a built-in type for TypeScript, so we should use a wildcard pattern to include .ts and .tsx files in our search instead.

Let's correct the script to search for any remaining references to VITE_HTTPS in TypeScript files without specifying the file type.


The updated script did not find any references to VITE_HTTPS in TypeScript files within the codebase. This suggests that the variable has been successfully removed from the codebase, and there are no lingering references that could cause issues with the configuration changes.

Given this information, it appears that the removal of VITE_HTTPS was intentional and has been thoroughly applied. The development environment should now be configured to serve over HTTPS by default, as per the changes in the vite.config.ts file.

Since the script execution did not yield any results, and based on the previous context provided, it seems that the removal of VITE_HTTPS has been handled correctly.

The removal of VITE_HTTPS from the environment configuration and the unconditional enabling of HTTPS in development mode with mkcert() have been verified, and no remaining references to VITE_HTTPS were found in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to VITE_HTTPS in the codebase.
rg --type typescript 'VITE_HTTPS'

Length of output: 68



Script:

#!/bin/bash
# Search for any remaining references to VITE_HTTPS in TypeScript (.ts and .tsx) files.
rg 'VITE_HTTPS' -g '*.ts' -g '*.tsx'

Length of output: 36

.env.development Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a032679 and 1ec781a.
Files ignored due to filter (4)
  • devbox.json
  • devbox.lock
  • package.json
  • pnpm-lock.yaml
Files selected for processing (1)
  • scripts/deployment.mjs (1 hunks)
Additional comments: 2
scripts/deployment.mjs (2)
  • 16-50: The transformation functions for updating version and tag in YAML files use regular expressions and replacement logic. Ensure that the regular expressions are robust enough to handle different formatting in the YAML files and consider edge cases where the version or tag might appear in different contexts within the file.

  • 52-55: The Authorization header uses a token directly from the command line arguments. Ensure that this token is handled securely and not exposed in logs or error messages.

Comment on lines +1 to +8
const [version, stageName, build, token] = process.argv.slice(2);
if (!version) {
throw Error('You need to pass version');
}

if (!version) {
throw Error('You need to pass stage');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a redundant check for the version variable, which should likely be a check for stageName instead.

- if (!version) {
+ if (!stageName) {
  throw Error('You need to pass stage');
}

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const [version, stageName, build, token] = process.argv.slice(2);
if (!version) {
throw Error('You need to pass version');
}
if (!version) {
throw Error('You need to pass stage');
}
const [version, stageName, build, token] = process.argv.slice(2);
if (!version) {
throw Error('You need to pass version');
}
if (!stageName) {
throw Error('You need to pass stage');
}

Comment on lines +57 to +77
async function createBranchFromMain() {
// Get the latest commit from the main branch
const mainBranchData = await fetch(
`https://api.github.com/repos/${repoOwner}/${repoName}/git/ref/heads/${mainBranch}`,
{
headers: headers,
},
).then((response) => response.json());

const latestCommitSha = mainBranchData.object.sha;

// Create a new branch from the latest commit
return fetch(`https://api.github.com/repos/${repoOwner}/${repoName}/git/refs`, {
method: 'POST',
headers: headers,
body: JSON.stringify({
ref: `refs/heads/${branchName}`,
sha: latestCommitSha,
}),
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The createBranchFromMain function does not handle potential errors from the GitHub API requests. Implement error handling to catch and respond to issues such as network errors, authentication failures, or invalid responses.

// Add error handling for the fetch request
.then((response) => {
  if (!response.ok) {
    throw new Error(`GitHub API responded with status: ${response.status}`);
  }
  return response.json();
})

Comment on lines +79 to +159
async function changeConfigAndCommit() {
let prevCommitSHA;
const newFiles = await Promise.all(
Object.keys(transforms).map(async (file) => {
console.log(` /${file}:`);
// Retrieve the config file
const configFileData = await fetch(
`https://api.github.com/repos/${repoOwner}/${repoName}/contents/${file}?ref=${branchName}`,
{
headers: headers,
},
).then((response) => response.json());

prevCommitSHA = configFileData.sha; // TODO: What a correct way to get this?

// Decode the file content from base64
let content = Buffer.from(configFileData.content, 'base64').toString();

// Update file content
content = transforms[file](content);

// Encode the updated content back to base64
const updatedContent = Buffer.from(content, 'utf-8').toString('base64');
return {
path: file,
mode: '100644',
type: 'blob',
content: updatedContent,
};
}),
);

const treeData = await fetch(
`https://api.github.com/repos/${repoOwner}/${repoName}/git/trees`,
{
method: 'POST',
headers: headers,
body: JSON.stringify({
base_tree: prevCommitSHA, // Base tree of the current branch
tree: newFiles,
}),
},
).then((response) => response.json());

// Create a commit with both file changes
return fetch(`https://api.github.com/repos/${repoOwner}/${repoName}/git/commits`, {
method: 'POST',
headers: headers,
body: JSON.stringify({
message: commitMessage,
tree: treeData.sha,
parents: [prevCommitSHA],
}),
})
.then((response) => response.json())
.then((commitData) => {
// Update the reference of the branch to point to the new commit
return fetch(
`https://api.github.com/repos/${repoOwner}/${repoName}/git/refs/heads/${branchName}`,
{
method: 'PATCH',
headers: headers,
body: JSON.stringify({
sha: commitData.sha,
}),
},
);
});

// // Create a commit with the updated file
// return fetch(`https://api.github.com/repos/${repoOwner}/${repoName}/contents/${file}`, {
// method: 'PUT',
// headers: headers,
// body: JSON.stringify({
// message: commitMessage,
// content: updatedContent,
// branch: newBranch,
// sha: configFileData.sha,
// }),
// });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changeConfigAndCommit function has a TODO comment regarding the correct way to get the previous commit SHA. This needs to be resolved to ensure the script functions correctly. Additionally, the function should handle errors from the GitHub API requests and ensure that the file transformations are applied correctly.

// Resolve the TODO about the correct way to get the previous commit SHA
// Add error handling for the fetch requests

Comment on lines +161 to +172
async function createPullRequest() {
// Open a pull request from the new branch to the main branch
return fetch(`https://api.github.com/repos/${repoOwner}/${repoName}/pulls`, {
method: 'POST',
headers: headers,
body: JSON.stringify({
title: mergeRequestTitle,
head: branchName,
base: mainBranch,
body: 'Pull request created by script.',
}),
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The createPullRequest function does not handle potential errors from the GitHub API requests. Implement error handling to catch and respond to issues such as network errors, authentication failures, or invalid responses.

// Add error handling for the fetch request
.then((response) => {
  if (!response.ok) {
    throw new Error(`GitHub API responded with status: ${response.status}`);
  }
  return response.json();
})

Comment on lines +175 to +182
async function runScript() {
await createBranchFromMain();
console.log('Update configs:');
await changeConfigAndCommit();
await createPullRequest();
}

runScript();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runScript function calls other functions in sequence but does not handle any errors that may occur. Implement error handling to ensure that the script stops execution and reports errors when they occur.

// Add try-catch block to handle errors during script execution
try {
  await createBranchFromMain();
  console.log('Update configs:');
  await changeConfigAndCommit();
  await createPullRequest();
} catch (error) {
  console.error('Script failed:', error);
  process.exit(1);
}

@Akiyamka Akiyamka merged commit 0d351b0 into main Dec 28, 2023
8 of 9 checks passed
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.

2 participants