Skip to content

feat: support parse the source info from zeta repo#185

Merged
gaius-qi merged 1 commit into
mainfrom
feat/zeta
May 22, 2025
Merged

feat: support parse the source info from zeta repo#185
gaius-qi merged 1 commit into
mainfrom
feat/zeta

Conversation

@chlins

@chlins chlins commented May 21, 2025

Copy link
Copy Markdown
Member

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.mod file.

New Zeta Repository Support:

  • Added a new ParserTypeZeta constant and logic to handle Zeta repositories in the NewParser function in pkg/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))
  • Implemented the zeta parser 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))
  • Updated the getSourceInfo function in pkg/backend/build.go to detect and use the Zeta parser if a .zeta directory is present. ([pkg/backend/build.goR221-R228](https://github.com/modelpack/modctl/pull/185/files#diff-d6967c304021925580fe39f08821dc9e301bcc02a119e188d723e6939f170a5cR221-R228))
  • Added unit tests for the Zeta parser in pkg/source/zeta_test.go and test data in pkg/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:

  • Added github.com/antgroup/hugescm v0.17.2 to support Zeta repository parsing. ([go.modR7](https://github.com/modelpack/modctl/pull/185/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R7))
  • Updated several dependencies in go.mod, including github.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))
  • Added new indirect dependencies such as github.com/danieljoos/wincred, github.com/dgraph-io/ristretto/v2, and github.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

    • Added support for parsing repositories that use the Zeta version control system, in addition to existing Git support.
  • Tests

    • Introduced tests to validate Zeta repository parsing, ensuring correct extraction of repository metadata.
  • Chores

    • Updated dependencies to newer versions and added new dependencies.

Signed-off-by: chlins <chlins.zhang@gmail.com>
@chlins chlins added the enhancement New feature or request label May 21, 2025
@coderabbitai

coderabbitai Bot commented May 21, 2025

Copy link
Copy Markdown

Walkthrough

The 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

File(s) Change Summary
go.mod Added direct dependency on github.com/antgroup/hugescm v0.17.2 and several new/updated indirect dependencies.
pkg/backend/build.go Modified getSourceInfo to detect .zeta directories and use the new Zeta parser if present.
pkg/source/parser.go Added ParserTypeZeta constant and updated NewParser to support the Zeta parser.
pkg/source/zeta.go Introduced new zeta parser implementation with a Parse method for extracting repo info.
pkg/source/zeta_test.go Added tests for the Zeta parser using test data.
pkg/source/testdata/zeta-repo/.zeta/*
pkg/source/testdata/zeta-repo/.zetaignore
pkg/source/testdata/zeta-repo/LEGAL.md
pkg/source/testdata/zeta-repo/Readme.md
Added Zeta repository test data: HEAD, logs, refs, config, ignore file, legal, and readme.

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
Loading

Poem

In the warren of code, a new path appears,
Zeta hops in, with commits and cheers!
Parsers now know both Git and Zeta’s tune,
Test data and hashes, all added in June.
A rabbit’s delight—new features to see,
Hopping through history, as happy as can be!
🐇✨

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
Failed executing command with 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, Windsurf

CodeRabbit 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.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit 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 Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
    • 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (4)
pkg/source/zeta_test.go (1)

1-15: Copyright year needs correction

The 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 code

Both 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 correction

The 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 timeout

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between ffd7149 and 7e1bfaf.

⛔ Files ignored due to path filters (1)
  • go.sum is 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.md file serves as placeholder documentation in the zeta-repo testdata. 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.md file 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/HEAD file 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 .zetaignore file 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.0 remote 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 appropriate

The 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 good

The 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 testing

The 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 good

This 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 constant

The 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 good

The NewParser function 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 good

The 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 good

The implementation follows the same pattern as the Git repository detection. It checks for the existence of a .zeta directory and creates the appropriate parser.

go.mod (2)

33-33: Dependency version updates look appropriate

The updated dependency versions for github.com/ProtonMail/go-crypto (v1.2.0) and github.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.2 has 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/hugescm

Length 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.2

Length of output: 112


Dependency Verified: github.com/antgroup/hugescm v0.17.2

The hugescm module and its tag v0.17.2 both exist on GitHub, so this new dependency is valid and can be approved.

• go.mod (line 7): github.com/antgroup/hugescm v0.17.2

pkg/source/zeta.go (2)

51-55: Good practice to check worktree status

Checking if the worktree is dirty is a good practice. This matches the expected behavior of the Info struct's Dirty field.


40-43: 🛠️ Refactor suggestion

Remote URL handling needs improvement

The code assumes that repo.Core.Remote contains 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.

@gaius-qi gaius-qi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@gaius-qi gaius-qi merged commit 0be2a48 into main May 22, 2025
6 checks passed
@gaius-qi gaius-qi deleted the feat/zeta branch May 22, 2025 03:26
SAY-5 added a commit to SAY-5/modctl that referenced this pull request May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants