Skip to content

Conversation

@jortel
Copy link
Contributor

@jortel jortel commented Jul 5, 2025

problem

This is needed to support working with multiple repositories simultaneously.

solution

The configuration and credentials cannot be written into the HOME directory. Further, each instance of
the SCM needs to have their own.
Add command.Command.Env support.
Update ssh, git, subversion to write credentials and run with HOME=dir where dir is specific to each instance.
The ssh.Agent writes keys in .ssh/ with identity ID prefix.

closes #76

Summary by CodeRabbit

  • New Features

    • Added support for customizing environment variables when running commands.
  • Refactor

    • Simplified and unified identity and credential handling for Git, Maven, and Subversion repositories.
    • Repository-specific configuration and credential files are now stored in hashed directories under the current working directory.
    • Improved flexibility in repository creation and configuration options with a new option mechanism.
    • Updated SSH agent handling and environment setup for enhanced reliability and consistent environment variables.
    • Enhanced Git command execution with improved environment isolation and updated command options.

jortel added 3 commits July 5, 2025 17:32
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Jul 5, 2025

Walkthrough

The changes refactor identity and environment handling across repository, SSH, and command execution modules. Identity management is simplified from lists to single identities, with new flexible option mechanisms for repository creation. Environment variables are now explicitly set for command execution, and configuration files are written to the current working directory instead of the home directory. Several method signatures are updated to reflect these changes.

Changes

File(s) Change Summary
cmd/main.go Updated call to repository.New to remove one nil argument, matching new function signature.
command/cmd.go Added Env []string field to Command struct; RunWith now sets command environment from this field.
repository/factory.go Refactored New to use variadic options; SCM interface gains Use(option any) error; identity handling now single, not list; added flexible option mechanism.
repository/git.go Added git() and home() methods; centralized environment and credential handling; config and credential files now in working directory; identity usage simplified; updated git commands and error returns.
repository/maven.go CreateSettingsFile now accesses credentials via embedded identity; file close and error handling improved.
repository/subversion.go Added home() method; identity usage refactored to embedded field; environment and config paths now use working directory; method signatures updated; environment variables explicitly set.
ssh/ssh.go Directory paths now use working directory; writeAsk returns script path; environment variables set explicitly for SSH commands; file handling improved; unconditional file overwrite for SSH key.

Sequence Diagram(s)

sequenceDiagram
    participant Main
    participant RepoFactory as repository.New
    participant SCM
    participant AddonStore
    participant Command
    participant OS

    Main->>RepoFactory: New(destDir, remote, option...)
    RepoFactory->>SCM: create SCM instance
    loop For each option
        RepoFactory->>SCM: Use(option)
        alt option is api.Ref
            SCM->>AddonStore: Fetch Identity by Ref
            SCM->>SCM: Set Identity
        else option is api.Identity
            SCM->>SCM: Set Identity
        else
            SCM->>RepoFactory: Return error
        end
    end
    Main->>SCM: Use SCM (e.g., Fetch, Commit)
    SCM->>Command: Prepare command with Env
    Command->>OS: Execute with set Env
Loading

Possibly related issues

Poem

In burrows deep, with code anew,
Identity’s now just one, not two!
Environment set, commands run bright,
Configs in the working site.
Hop, hop, the rabbit’s glee—
Simpler paths for SCM!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cfe5632 and d3be562.

📒 Files selected for processing (1)
  • repository/subversion.go (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • repository/subversion.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-and-upload-for-global-ci
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

jortel added 6 commits July 6, 2025 06:11
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
jortel added 5 commits July 6, 2025 11:37
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
@jortel jortel marked this pull request as ready for review July 6, 2025 18:54
Copy link

@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

🔭 Outside diff range comments (1)
repository/git.go (1)

84-96: Inconsistent command creation in Branch method.

The fallback command still uses command.New directly instead of r.git(), which means it won't have the necessary environment variables set (HOME, GIT_TERMINAL_PROMPT, etc.).

Apply this diff to fix the inconsistency:

 func (r *Git) Branch(ref string) (err error) {
 	cmd := r.git()
 	cmd.Dir = r.Path
 	cmd.Options.Add("checkout", ref)
 	err = cmd.Run()
 	if err != nil {
-		cmd = command.New("/usr/bin/git")
+		cmd = r.git()
 		cmd.Dir = r.Path
 		cmd.Options.Add("checkout", "-b", ref)
 	}
 	r.Remote.Branch = ref
 	err = cmd.Run()
 	return
 }
🧹 Nitpick comments (3)
repository/maven.go (1)

46-48: Consider using the cleaner defer pattern.

While explicitly ignoring the close error is acceptable here, the more idiomatic Go pattern would be:

-	defer func() {
-		_ = f.Close()
-	}()
+	defer f.Close()
repository/subversion.go (1)

199-199: Minor: Comment grammar improvement.

-// writeConfig writes configuration file.
+// writeConfig writes the configuration file.
repository/factory.go (1)

16-18: Consider handling the error from os.Getwd().

The init function ignores the error from os.Getwd(). If the working directory cannot be determined, Dir will remain an empty string, which could cause issues when constructing file paths.

Consider logging or handling the error:

 func init() {
-	Dir, _ = os.Getwd()
+	var err error
+	Dir, err = os.Getwd()
+	if err != nil {
+		// Log the error or use a default directory
+		Dir = "."
+	}
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 17140aa and c4c3ac0.

📒 Files selected for processing (7)
  • cmd/main.go (1 hunks)
  • command/cmd.go (2 hunks)
  • repository/factory.go (3 hunks)
  • repository/git.go (10 hunks)
  • repository/maven.go (1 hunks)
  • repository/subversion.go (6 hunks)
  • ssh/ssh.go (6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
repository/subversion.go (3)
ssh/ssh.go (2)
  • Agent (30-31)
  • Dir (20-20)
repository/factory.go (1)
  • Dir (13-13)
command/cmd.go (1)
  • Options (93-93)
repository/git.go (3)
ssh/ssh.go (2)
  • Agent (30-31)
  • Dir (20-20)
repository/factory.go (2)
  • Dir (13-13)
  • New (28-63)
command/cmd.go (3)
  • Options (93-93)
  • Command (28-35)
  • New (22-25)
🔇 Additional comments (17)
command/cmd.go (1)

32-32: LGTM! Clean implementation of environment variable support.

The addition of the Env field and its usage in RunWith enables proper environment isolation for SCM operations, which is essential for managing multiple repository instances concurrently.

Also applies to: 67-67

cmd/main.go (1)

12-12: LGTM! Correctly updated to match the new repository.New signature.

The call properly reflects the API change from accepting identity slices to using variadic options.

repository/maven.go (1)

50-55: LGTM! Clean refactor to use embedded Identity.

The direct use of r.Identity simplifies the code and aligns with the broader refactoring to use a single embedded identity instead of dynamic lookups.

ssh/ssh.go (5)

25-26: LGTM! Directory initialization supports instance isolation.

Using the current working directory instead of the home directory enables proper isolation between multiple repository instances.


38-38: LGTM! Explicit HOME environment ensures SSH agent isolation.

Setting HOME to the instance-specific directory prevents SSH configuration conflicts between concurrent repository operations.


84-84: Good improvement to return the script path.

The signature change to return the script path is cleaner than relying on a hardcoded path assumption.

Also applies to: 116-116


93-97: LGTM! Proper environment setup for non-interactive SSH key addition.

The explicit environment variable setup correctly configures SSH_ASKPASS for automated password entry.


129-134: Good improvements to script writing logic.

The deferred close and simplified string concatenation make the code cleaner and more maintainable.

repository/subversion.go (4)

51-56: LGTM! Consistent identity refactoring.

The changes properly use the embedded r.Identity field, aligning with the simplified identity management approach across all SCM implementations.

Also applies to: 61-61, 66-66


145-145: LGTM! Environment isolation for SVN commands.

Setting HOME ensures SVN configuration and credentials are isolated per repository instance.


238-240: LGTM! Clean refactor of writePassword method.

The method now properly uses the embedded identity, and the parameter removal simplifies the API while maintaining functionality.

Also applies to: 249-251, 306-311


202-202: LGTM! Path changes support instance isolation.

Using Dir (current working directory) instead of the home directory ensures proper isolation of SVN configuration between repository instances.

Also applies to: 258-258

repository/factory.go (2)

23-63: Well-implemented factory pattern with flexible options.

The refactored New function with variadic options provides a clean and extensible API for SCM configuration. The error handling ensures proper validation and option application.


81-115: Robust option handling with comprehensive type support.

The Use method implementation properly handles all documented option types with appropriate nil checks and clear error messages for invalid options.

repository/git.go (3)

141-151: Well-designed git command factory method.

The git() method correctly sets up the environment for isolated repository operations by:

  • Setting HOME to the instance-specific directory
  • Disabling terminal prompts for non-interactive operation
  • Enabling trace logs for debugging
  • Preserving existing environment variables

171-190: Proper isolation of git configuration.

The configuration is correctly written to the instance-specific directory, and the credential helper path is properly configured to use the local credentials file.


209-250: Clean refactoring of credential management.

The simplified method signature and direct use of r.Identity makes the code cleaner and more maintainable. The credentials are properly isolated to the instance-specific directory.

Signed-off-by: Jeff Ortel <[email protected]>
jortel added 5 commits July 7, 2025 07:29
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
jortel added a commit to konveyor/tackle2-addon-analyzer that referenced this pull request Sep 17, 2025
This spot missed.  
Related to: konveyor/tackle2-addon#75 - handle
working with multiple repositories concurrently in 0.8.

```
    - '[RULESET] fetching: id=30 (__Target(Test)-ac32d015-93df-11f0-8d81-4661cd220ef3)'
    - '[GIT] Home (directory): /addon/.git/8c35e7c2'
    - '[GIT] Cloning: https://github.com/abrugaro/book-server'
    - '[CMD] /usr/bin/git succeeded.'
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved error handling when associating identities with ruleset
repositories so identity lookup failures are reported early and prevent
partial repository setup.

* **Refactor**
* Repository initialization updated to a more flexible options-based
pattern, improving extensibility while preserving existing behavior for
users.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jeff Ortel <[email protected]>
github-actions bot pushed a commit to konveyor/tackle2-addon-analyzer that referenced this pull request Sep 17, 2025
This spot missed.
Related to: konveyor/tackle2-addon#75 - handle
working with multiple repositories concurrently in 0.8.

```
    - '[RULESET] fetching: id=30 (__Target(Test)-ac32d015-93df-11f0-8d81-4661cd220ef3)'
    - '[GIT] Home (directory): /addon/.git/8c35e7c2'
    - '[GIT] Cloning: https://github.com/abrugaro/book-server'
    - '[CMD] /usr/bin/git succeeded.'
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved error handling when associating identities with ruleset
repositories so identity lookup failures are reported early and prevent
partial repository setup.

* **Refactor**
* Repository initialization updated to a more flexible options-based
pattern, improving extensibility while preserving existing behavior for
users.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>
jortel added a commit to konveyor/tackle2-addon-analyzer that referenced this pull request Sep 17, 2025
This spot missed.
Related to: konveyor/tackle2-addon#75 - handle
working with multiple repositories concurrently in 0.8.

Tested.
```
    - '[RULESET] fetching: id=30 (__Target(Test)-ac32d015-93df-11f0-8d81-4661cd220ef3)'
    - '[GIT] Home (directory): /addon/.git/8c35e7c2'
    - '[GIT] Cloning: https://github.com/abrugaro/book-server'
    - '[CMD] /usr/bin/git succeeded.'
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved error handling when associating identities with ruleset
repositories so identity lookup failures are reported early and prevent
partial repository setup.

* **Refactor**
* Repository initialization updated to a more flexible options-based
pattern, improving extensibility while preserving existing behavior for
users.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>

Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>
Co-authored-by: Jeff Ortel <[email protected]>
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.

✨ Support using multiple SCM (repositories) simultaneously.

2 participants