Conversation
Signed-off-by: chlins <chlins.zhang@gmail.com>
WalkthroughThe changes introduce support for a new "zeta" source parser alongside the existing "git" parser. This includes updates to parser selection logic, the addition of a new parser implementation, and relevant test data and tests. Dependency updates and additions are also made in the module configuration. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant getSourceInfo
participant ParserFactory
participant ZetaParser
participant Repo
Caller->>getSourceInfo: Call with workspace path
getSourceInfo->>getSourceInfo: Check for .git directory
getSourceInfo->>ParserFactory: (if .git) NewParser("git")
getSourceInfo->>getSourceInfo: Check for .zeta directory
getSourceInfo->>ParserFactory: (if .zeta) NewParser("zeta")
getSourceInfo->>ZetaParser: Parse(workspace)
ZetaParser->>Repo: Open(.zeta repo)
Repo-->>ZetaParser: Return repo handle
ZetaParser->>Repo: Get remote URL, HEAD, status
Repo-->>ZetaParser: Return info
ZetaParser-->>getSourceInfo: Return Info struct
getSourceInfo-->>Caller: Return Info or error
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
pkg/source/zeta_test.go (1)
1-15: Copyright year needs correctionThe copyright header uses "2025" but it should be "2024" to match the rest of the codebase.
-/* - * Copyright 2025 The CNAI Authors - * + * Copyright 2024 The CNAI Authors + *pkg/backend/build.go (1)
202-241: Consider refactoring repeated parser initialization codeBoth Git and Zeta parser initialization follow the same pattern, which could be refactored to eliminate duplication.
Consider refactoring this method to reduce duplication of error handling:
func getSourceInfo(workspace string, buildConfig *config.Build) (*source.Info, error) { info := &source.Info{ URL: buildConfig.SourceURL, Commit: buildConfig.SourceRevision, } // Try to parse the source information if user not specified. if info.URL == "" { var parser source.Parser var err error - gitPath := filepath.Join(workspace, ".git") - if _, err := os.Stat(gitPath); err == nil { - parser, err = source.NewParser(source.ParserTypeGit) - if err != nil { - return nil, err - } - } - - zetaPath := filepath.Join(workspace, ".zeta") - if _, err := os.Stat(zetaPath); err == nil { - parser, err = source.NewParser(source.ParserTypeZeta) - if err != nil { - return nil, err - } - } + // Check for known repository types + repoTypes := map[string]string{ + ".git": source.ParserTypeGit, + ".zeta": source.ParserTypeZeta, + } + + for dirName, parserType := range repoTypes { + repoPath := filepath.Join(workspace, dirName) + if _, err := os.Stat(repoPath); err == nil { + parser, err = source.NewParser(parserType) + if err != nil { + return nil, err + } + break + } + } // Parse the source information if available. if parser != nil { parsedInfo, err := parser.Parse(workspace) if err != nil { return nil, err } return parsedInfo, nil } } return info, nil }pkg/source/zeta.go (2)
1-15: Copyright year needs correctionThe copyright header uses "2025" but it should be "2024" to match the rest of the codebase.
-/* - * Copyright 2025 The CNAI Authors - * + * Copyright 2024 The CNAI Authors + *
28-62: Implementation looks good, but consider adding context timeoutThe Parse method implementation correctly extracts repository information using the pkgzeta package, but it's using a background context without a timeout, which could potentially lead to hanging operations if the repository operations take too long.
Consider adding a timeout to the context:
func (z *zeta) Parse(workspace string) (*Info, error) { - ctx := context.Background() + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() repo, err := pkgzeta.Open(ctx, &pkgzeta.OpenOptions{ Worktree: workspace, Quiet: true, Verbose: false, }) // Rest of the method...Don't forget to add the time package import:
import ( "context" "fmt" + "time" pkgzeta "github.com/antgroup/hugescm/pkg/zeta" )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (14)
go.mod(5 hunks)pkg/backend/build.go(2 hunks)pkg/source/parser.go(2 hunks)pkg/source/testdata/zeta-repo/.zeta/HEAD(1 hunks)pkg/source/testdata/zeta-repo/.zeta/logs/HEAD(1 hunks)pkg/source/testdata/zeta-repo/.zeta/logs/refs/heads/v1.0.0(1 hunks)pkg/source/testdata/zeta-repo/.zeta/refs/heads/v1.0.0(1 hunks)pkg/source/testdata/zeta-repo/.zeta/refs/remotes/origin/v1.0.0(1 hunks)pkg/source/testdata/zeta-repo/.zeta/zeta.toml(1 hunks)pkg/source/testdata/zeta-repo/.zetaignore(1 hunks)pkg/source/testdata/zeta-repo/LEGAL.md(1 hunks)pkg/source/testdata/zeta-repo/Readme.md(1 hunks)pkg/source/zeta.go(1 hunks)pkg/source/zeta_test.go(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
pkg/source/zeta.go (1)
pkg/source/parser.go (1)
Info(35-45)
pkg/backend/build.go (1)
pkg/source/parser.go (2)
NewParser(47-56)ParserTypeZeta(26-26)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Lint
🔇 Additional comments (17)
pkg/source/testdata/zeta-repo/Readme.md (1)
1-2: Approve new test fixture file for the Zeta repository.The
Readme.mdfile serves as placeholder documentation in thezeta-repotestdata. Its inclusion helps simulate real-world repository structures for the parser tests.pkg/source/testdata/zeta-repo/LEGAL.md (1)
1-1: Approve legal metadata file in test data.The
LEGAL.mdfile is correctly added to the testdata to simulate repository compliance metadata and does not impact parsing logic.pkg/source/testdata/zeta-repo/.zeta/HEAD (1)
1-1: Approve HEAD pointer file in Zeta test repository.The
.zeta/HEADfile correctly references the active branch (refs/heads/v1.0.0) and is essential for the parser to detect the current HEAD state.pkg/source/testdata/zeta-repo/.zetaignore (1)
1-1: Approve .zetaignore file for test repository.The
.zetaignorefile correctly simulates ignore patterns in the Zeta repository to test parser behavior for untracked files.pkg/source/testdata/zeta-repo/.zeta/refs/remotes/origin/v1.0.0 (1)
1-1: Approve remote reference commit hash in test data.The file contains the commit hash for the
origin/v1.0.0remote ref, which is used by the parser to verify remote state.pkg/source/testdata/zeta-repo/.zeta/refs/heads/v1.0.0 (1)
1-2: Test data looks appropriateThe commit hash format appears to be using SHA-256 (64 characters), which is consistent with a Zeta repository reference file. This test fixture will effectively support testing the Zeta parser functionality.
pkg/source/testdata/zeta-repo/.zeta/zeta.toml (1)
1-3: Configuration structure looks goodThe TOML configuration properly defines the core repository settings including the remote URL and compression algorithm. These values will be useful for testing the Zeta parser's ability to extract repository metadata.
pkg/source/testdata/zeta-repo/.zeta/logs/HEAD (1)
1-1: Log format is appropriate for testingThe log entry correctly captures a reference update with old hash (zeros), new hash, timestamp, and operation message. Note that the timestamp (1744943558) corresponds to a date in 2025, which I assume is intentional for testing purposes.
pkg/source/testdata/zeta-repo/.zeta/logs/refs/heads/v1.0.0 (1)
1-1: Branch creation log looks goodThis log entry appropriately documents the branch creation event with the expected format. The consistent use of the same commit hash across test files helps create a coherent test repository structure.
pkg/source/parser.go (2)
24-26: Well-documented parser type constantThe constant for the Zeta parser type is appropriately defined and documented with a clear comment describing its purpose, following the same pattern as the existing Git parser type.
51-52: Parser factory implementation looks goodThe
NewParserfunction is properly extended to support the new Zeta parser type, maintaining the same pattern used for the Git parser. This change correctly integrates the Zeta parser into the existing parser framework.pkg/source/zeta_test.go (1)
25-32: Test case looks goodThe test correctly verifies the zeta parser's ability to extract repository information. It validates the URL, commit hash, and dirty status against expected values.
pkg/backend/build.go (1)
221-227: Zeta repository detection looks goodThe implementation follows the same pattern as the Git repository detection. It checks for the existence of a
.zetadirectory and creates the appropriate parser.go.mod (2)
33-33: Dependency version updates look appropriateThe updated dependency versions for
github.com/ProtonMail/go-crypto(v1.2.0) andgithub.com/klauspost/compress(v1.18.0) seem appropriate and are likely needed for compatibility with the hugescm package.Also applies to: 61-62
7-7:Details
✅ Verification successful
Verify hugescm dependency
New dependency
github.com/antgroup/hugescm v0.17.2has been added for Zeta repository support.
🏁 Script executed:
#!/bin/bash # Check if the hugescm package is available on GitHub curl -s -o /dev/null -w "%{http_code}" https://github.com/antgroup/hugescmLength of output: 80
🏁 Script executed:
#!/bin/bash # Verify that tag v0.17.2 exists in the hugescm repository curl -s -o /dev/null -w "%{http_code}" https://api.github.com/repos/antgroup/hugescm/git/refs/tags/v0.17.2Length of output: 112
Dependency Verified: github.com/antgroup/hugescm v0.17.2
The
hugescmmodule and its tagv0.17.2both exist on GitHub, so this new dependency is valid and can be approved.• go.mod (line 7):
github.com/antgroup/hugescm v0.17.2pkg/source/zeta.go (2)
51-55: Good practice to check worktree statusChecking if the worktree is dirty is a good practice. This matches the expected behavior of the
Infostruct'sDirtyfield.
40-43: 🛠️ Refactor suggestionRemote URL handling needs improvement
The code assumes that
repo.Core.Remotecontains exactly one URL, but doesn't properly handle multiple remotes like the Git implementation might. Consider enhancing this to handle multiple remotes or to be more explicit about which remote is being used.Consider improving remote URL handling:
- url := repo.Core.Remote - if len(url) == 0 { + url, ok := repo.Core.Remote["origin"] + if !ok || url == "" { return nil, fmt.Errorf("no remote URL found") }If the Zeta API doesn't support multiple remotes in this way, at least add a comment explaining that this is the expected behavior.
Likely an incorrect or invalid review comment.
Signed-off-by: SAY-5 <say.apm35@gmail.com>
This pull request introduces support for a new repository type, Zeta, by adding a parser for Zeta repositories and updating dependencies. It also includes test data and unit tests for the new functionality. Additionally, several dependency updates and additions are made in the
go.modfile.New Zeta Repository Support:
ParserTypeZetaconstant and logic to handle Zeta repositories in theNewParserfunction inpkg/source/parser.go. ([[1]](https://github.com/modelpack/modctl/pull/185/files#diff-4c37edab4bdc04d211b5bf1ddae0b4f98567c8047f1a2aee502b4774893736bcR24-R26),[[2]](https://github.com/modelpack/modctl/pull/185/files#diff-4c37edab4bdc04d211b5bf1ddae0b4f98567c8047f1a2aee502b4774893736bcR51-R52))zetaparser in a new file,pkg/source/zeta.go, which parses repository information such as URL, commit hash, and dirty status using the Zeta SCM library. ([pkg/source/zeta.goR1-R62](https://github.com/modelpack/modctl/pull/185/files#diff-a20308e07c0abd3eb6f614a76c4a2dc1815fa0dbd73ea3e8f7b22a63353a3f7eR1-R62))getSourceInfofunction inpkg/backend/build.goto detect and use the Zeta parser if a.zetadirectory is present. ([pkg/backend/build.goR221-R228](https://github.com/modelpack/modctl/pull/185/files#diff-d6967c304021925580fe39f08821dc9e301bcc02a119e188d723e6939f170a5cR221-R228))pkg/source/zeta_test.goand test data inpkg/source/testdata/zeta-repo/. ([[1]](https://github.com/modelpack/modctl/pull/185/files#diff-3c3dfca32f91b8dd7dc8c7a069b67c1f20f402153359df3a7f9944f796404811R1-R32),[[2]](https://github.com/modelpack/modctl/pull/185/files#diff-f76554d8ca235eca551aa1c4941707dcefbf8da602a61695905d02d1e47b8d37R1),[[3]](https://github.com/modelpack/modctl/pull/185/files#diff-4ad91a5df3c6e614e5dcbbd1a5cb928d84c1e2849929216cc8e134c0168c7ac3R1),[[4]](https://github.com/modelpack/modctl/pull/185/files#diff-f86234230fee75c374296e65cf79f23b66c79e3f4dd7da1517e6bd4ed5026dc9R1),[[5]](https://github.com/modelpack/modctl/pull/185/files#diff-780fcf49c75c8a32a9fea25bc20546738dba5dba0da82e53e26522d27fab9218R1),[[6]](https://github.com/modelpack/modctl/pull/185/files#diff-0986d0892a270f7d8067d47c06017c23a2512efe29d2a67271a02d0f60b2f4f9R1-R3),[[7]](https://github.com/modelpack/modctl/pull/185/files#diff-1831783bc833ddf71a374ceb1c0b0a2e2962d7735778080cb33c469041d63b0aR1),[[8]](https://github.com/modelpack/modctl/pull/185/files#diff-413616e6bafd54ab1f12578a923717e2ce3bdc4e8a82ba879727b22cd9f78745R1),[[9]](https://github.com/modelpack/modctl/pull/185/files#diff-2628925360ff89f1f7cf172669fdfef8ffe25787aff947bbf6d4a17d78f7c56aR1-R2))Dependency Updates:
github.com/antgroup/hugescm v0.17.2to support Zeta repository parsing. ([go.modR7](https://github.com/modelpack/modctl/pull/185/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R7))go.mod, includinggithub.com/ProtonMail/go-crypto(v1.1.6 → v1.2.0),github.com/klauspost/compress(v1.17.11 → v1.18.0), and others. ([[1]](https://github.com/modelpack/modctl/pull/185/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R31-R43),[[2]](https://github.com/modelpack/modctl/pull/185/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6L56-R66))github.com/danieljoos/wincred,github.com/dgraph-io/ristretto/v2, andgithub.com/godbus/dbus/v5. ([[1]](https://github.com/modelpack/modctl/pull/185/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R31-R43),[[2]](https://github.com/modelpack/modctl/pull/185/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R52))Summary by CodeRabbit
New Features
Tests
Chores