-
Notifications
You must be signed in to change notification settings - Fork 52
Feat(jssg): better validation #1620
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
base: main
Are you sure you want to change the base?
Conversation
@AugustinMauroy is attempting to deploy a commit to the Codemod Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances validation for JavaScript AST-grep files and refactors package handling code to use "codemod" terminology consistently. The changes aim to reduce bugs by ensuring referenced JavaScript files exist before workflow execution.
- Adds validation for
js-ast-grep
step JavaScript file existence - Refactors function and variable names from "package" to "codemod" terminology
- Consolidates validation logic by moving duplicate code to shared functions
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
crates/models/src/workflow.rs | Adds validate_js_ast_grep_files method and optional name/description fields |
crates/models/Cargo.toml | Adds anyhow dependency for error handling |
crates/core/src/utils.rs | Adds file existence check in parse_workflow_file and reorganizes imports |
crates/core/Cargo.toml | Adds anyhow dependency |
crates/cli/src/commands/workflow/validate.rs | Moves validation logic here and integrates JS file validation |
crates/cli/src/commands/publish.rs | Refactors to use shared validation and "codemod" terminology |
crates/cli/README.md | Documents new JS file validation feature |
Comments suppressed due to low confidence (1)
crates/cli/src/commands/publish.rs:386
- The variable
tarball_data
is assigned but never used in the visible code. Consider removing it or using it in the multipart form creation.
let tarball_data = fs::read(tarball_path)?;
/// Parse a workflow definition from a file | ||
pub fn parse_workflow_file<P: AsRef<Path>>(path: P) -> Result<Workflow> { | ||
if !path.as_ref().exists() { | ||
return Err(anyhow!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The anyhow!
macro is used but anyhow
is imported with different syntax. The import shows use anyhow::{Context, Result};
but anyhow!
macro requires use anyhow::anyhow;
or the macro won't be available.
Copilot uses AI. Check for mistakes.
use butterflow_models::{Error, Node, Result, Workflow}; | ||
use serde_yaml; | ||
use std::collections::{HashMap, HashSet}; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
use butterflow_models::step::StepAction; | ||
use serde_yaml; | ||
|
||
use butterflow_models::{Error, Node, Result, Workflow}; | ||
|
||
/// Parse a workflow definition from a file | ||
pub fn parse_workflow_file<P: AsRef<Path>>(path: P) -> Result<Workflow> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are conflicting Result
imports. Line 1 imports anyhow::Result
and line 3 imports butterflow_models::Result
. This will cause a compilation error due to ambiguous type resolution.
Copilot uses AI. Check for mistakes.
@@ -186,7 +189,7 @@ pub async fn handler(args: &Command, telemetry: &dyn TelemetrySender) -> Result< | |||
})?; | |||
|
|||
// Upload package | |||
let response = upload_package( | |||
let response = upload_codemod( | |||
®istry_url, | |||
&bundle_path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable bundle_path
is used but it was renamed to tarball_path
on line 159. This will cause a compilation error.
&bundle_path, | |
&tarball_path, |
Copilot uses AI. Check for mistakes.
validate_codemod_manifest_structure( | ||
&args.workflow, | ||
&utils::parse_workflow_file(&args.workflow)?, | ||
)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Ok(())
return statement. The function signature indicates it returns Result<()>
but there's no explicit return value after the validation calls.
)?; | |
)?; | |
Ok(()) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI is failing. Have you tried running cargo check
and cargo clippy --fix --allow-dirty && cargo fmt
?
@@ -1,14 +1,20 @@ | |||
use anyhow::{Context, Result}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use anyhow in CLI only. In CLI, we use anyhow for ergonomic error propagation and user-facing reports.
In core/library crates, we define typed errors with thiserror
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it I had moved the function from cli to core to reused it so I have to modify that
Description
It's reduce the amount of possible bug