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

added stage field in spec and solved issue of checking duplicates of multip… #1875

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

octocamocoder47
Copy link

@octocamocoder47 octocamocoder47 commented Jan 23, 2025

added stage field in spec and solved issue of checking duplicates in multiple stages

solves issue: #1795

Summary by CodeRabbit

  • New Features

    • Enhanced variable specification process with stage-specific handling.
    • Added support for stage-aware duplicate variable checking.
  • Improvements

    • Improved robustness of variable specification management.
    • Added context tracking for variables across different stages.

Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Walkthrough

The changes modify the variable specification handling in the backend services. A new Stage field is introduced to the VariableSpec struct, allowing stage-specific context for variables. The getVariablesSpecFromEnvMap function now accepts a stage parameter, and a new findDuplicatesInStage function is added to check for duplicate variable names within a specific stage. The GetSpecFromJob function has been updated to use these new methods for more robust variable processing.

Changes

File Change Summary
libs/spec/models.go Added Stage field to VariableSpec struct with JSON tag
backend/services/spec.go - Updated getVariablesSpecFromEnvMap to include stage parameter
- Added new findDuplicatesInStage function
- Modified GetSpecFromJob to use stage-specific duplicate checking

Poem

🐰 A rabbit's tale of variables bright,
Stages now tagged with coding might!
No duplicates shall slip through the cracks,
Our specs now dance on clearer tracks!
Hop, hop, hooray for clean code's delight! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
backend/services/spec.go (1)

118-120: Consider using constants for stage names.

The stage names are currently hardcoded strings. To prevent inconsistencies and improve maintainability, consider defining these as constants.

+const (
+    StageState    = "state"
+    StageCommands = "commands"
+    StageRun      = "run"
+)

-	stateVariables := getVariablesSpecFromEnvMap(jobSpec.StateEnvVars, "state")
-	commandVariables := getVariablesSpecFromEnvMap(jobSpec.CommandEnvVars, "commands")
-	runVariables := getVariablesSpecFromEnvMap(jobSpec.RunEnvVars, "run")
+	stateVariables := getVariablesSpecFromEnvMap(jobSpec.StateEnvVars, StageState)
+	commandVariables := getVariablesSpecFromEnvMap(jobSpec.CommandEnvVars, StageCommands)
+	runVariables := getVariablesSpecFromEnvMap(jobSpec.RunEnvVars, StageRun)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e88db8 and 47f3163.

📒 Files selected for processing (2)
  • backend/services/spec.go (3 hunks)
  • libs/spec/models.go (1 hunks)
🔇 Additional comments (3)
libs/spec/models.go (1)

48-48: LGTM! Stage field addition looks good.

The new Stage field is properly added to the VariableSpec struct with appropriate JSON tagging, aligning with the PR's objective to support stage-specific variable handling.

backend/services/spec.go (2)

Line range hint 63-85: LGTM! Stage parameter properly integrated.

The function now correctly sets the stage field for both interpolated and non-interpolated variables.


122-130: LGTM! Stage-specific duplicate checking is well implemented.

The duplicate checking is properly implemented for each stage before combining the variables, which aligns with the PR's objective of solving the issue of checking duplicates across multiple stages.

Comment on lines 89 to 108
func findDuplicatesInStage(variablesSpec []spec.VariableSpec, stage string) (error) {
// Extract the names from VariableSpec
justNames := lo.Map(variablesSpec, func(item VariableSpec, i int) string {
return item.Name
})

// Group names by their occurrence
nameCounts := lo.CountValues(justNames)

// Filter names that occur more than once
duplicates := lo.Keys(lo.Filter(nameCounts, func(count int, name string) bool {
return count > 1
}))

if len(duplicates) > 0 {
return fmt.Errorf("In %v stage, found duplicate variables: %v", stage, duplicates)
}

return nil // No duplicates found
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix compilation issues and improve error handling in duplicate check function.

There are several issues in this function:

  1. The function is defined but never used (GetSpecFromJob calls checkDuplicatesInStage instead)
  2. The Map function uses undefined type VariableSpec instead of spec.VariableSpec
  3. The error message could be more specific

Apply these fixes:

-func findDuplicatesInStage(variablesSpec []spec.VariableSpec, stage string) (error) {
+func checkDuplicatesInStage(variablesSpec []spec.VariableSpec, stage string) error {
 	// Extract the names from VariableSpec
-	justNames := lo.Map(variablesSpec, func(item VariableSpec, i int) string {
+	justNames := lo.Map(variablesSpec, func(item spec.VariableSpec, i int) string {
 		return item.Name
 	})

 	// Group names by their occurrence
 	nameCounts := lo.CountValues(justNames)

 	// Filter names that occur more than once
 	duplicates := lo.Keys(lo.Filter(nameCounts, func(count int, name string) bool {
 		return count > 1
 	}))

 	if len(duplicates) > 0 {
-		return fmt.Errorf("In %v stage, found duplicate variables: %v", stage, duplicates)
+		return fmt.Errorf("duplicate variable names found in '%s' stage: %v", stage, strings.Join(duplicates, ", "))
 	}

 	return nil // No duplicates found
}

Committable suggestion skipped: line range outside the PR's diff.

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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
backend/services/spec.go (2)

89-108: Remove unnecessary parentheses in function signature.

The function implementation looks good, but there's a minor style improvement needed.

-func findDuplicatesInStage(variablesSpec []spec.VariableSpec, stage string) (error) {
+func findDuplicatesInStage(variablesSpec []spec.VariableSpec, stage string) error {

118-130: Consider defining stage names as constants.

The stage names ("state", "commands", "run") are used multiple times. To prevent typos and ensure consistency, consider defining them as package-level constants.

+const (
+    StageState    = "state"
+    StageCommands = "commands"
+    StageRun      = "run"
+)

-	stateVariables := getVariablesSpecFromEnvMap(jobSpec.StateEnvVars, "state")
-	commandVariables := getVariablesSpecFromEnvMap(jobSpec.CommandEnvVars, "commands")
-	runVariables := getVariablesSpecFromEnvMap(jobSpec.RunEnvVars, "run")
+	stateVariables := getVariablesSpecFromEnvMap(jobSpec.StateEnvVars, StageState)
+	commandVariables := getVariablesSpecFromEnvMap(jobSpec.CommandEnvVars, StageCommands)
+	runVariables := getVariablesSpecFromEnvMap(jobSpec.RunEnvVars, StageRun)

-	if err := findDuplicatesInStage(stateVariables, "state"); err != nil {
+	if err := findDuplicatesInStage(stateVariables, StageState); err != nil {
 		return nil, err
 	}
-	if err := findDuplicatesInStage(commandVariables, "commands"); err != nil {
+	if err := findDuplicatesInStage(commandVariables, StageCommands); err != nil {
 		return nil, err
 	}
-	if err := findDuplicatesInStage(runVariables, "run"); err != nil {
+	if err := findDuplicatesInStage(runVariables, StageRun); err != nil {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34e2b2a and 318babd.

📒 Files selected for processing (1)
  • backend/services/spec.go (3 hunks)
🔇 Additional comments (1)
backend/services/spec.go (1)

Line range hint 63-85: LGTM! Clean implementation of stage-specific variable handling.

The stage parameter is correctly propagated to both interpolated and non-interpolated variables while maintaining the original logic.

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