Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/nexus/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,33 @@ func (c *Client) CreateNpmGroupRepository(req RepositoryRequest) error {
return nil
}

// CreateRawHostedRepository 创建 Raw hosted 仓库

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion (docs/enhancement): Consider updating the CLAUDE.md documentation to mention that raw format is now a supported repository format. This helps future developers understand the tool's capabilities.

func (c *Client) CreateRawHostedRepository(req RepositoryRequest) error {
_, err := c.post("/service/rest/v1/repositories/raw/hosted", req)
if err != nil {
return fmt.Errorf("failed to create raw hosted repository %s: %w", req.Name, err)
}
return nil
}

// CreateRawProxyRepository 创建 Raw proxy 仓库
func (c *Client) CreateRawProxyRepository(req RepositoryRequest) error {
_, err := c.post("/service/rest/v1/repositories/raw/proxy", req)
if err != nil {
return fmt.Errorf("failed to create raw proxy repository %s: %w", req.Name, err)
}
return nil
}

// CreateRawGroupRepository 创建 Raw group 仓库
func (c *Client) CreateRawGroupRepository(req RepositoryRequest) error {
_, err := c.post("/service/rest/v1/repositories/raw/group", req)
if err != nil {
return fmt.Errorf("failed to create raw group repository %s: %w", req.Name, err)
}
return nil
}

// GetRepository 获取仓库信息
func (c *Client) GetRepository(name string) (map[string]interface{}, error) {
data, err := c.get(fmt.Sprintf("/service/rest/v1/repositories/%s", name))
Expand Down
32 changes: 23 additions & 9 deletions pkg/service/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,15 @@ func (s *ApplyService) createRepository(repo config.Repository) error {
}
}

// 根据格式和类型调用相应的创建方法
switch repo.Format {
return s.dispatchRepositoryCreate(repo.Format, repo.Type, req)
}

// dispatchRepositoryCreate 根据 format/type 分发到具体的 Create*Repository 客户端调用。
// 抽出为独立函数避免 createRepository 整体超过 gocyclo 复杂度阈值。
func (s *ApplyService) dispatchRepositoryCreate(format, repoType string, req nexus.RepositoryRequest) error {
switch format {
case "maven2":
switch repo.Type {
switch repoType {
case "hosted":
return s.client.CreateMavenHostedRepository(req)
case "proxy":
Expand All @@ -284,7 +289,7 @@ func (s *ApplyService) createRepository(repo config.Repository) error {
return s.client.CreateMavenGroupRepository(req)
}
case "docker":
switch repo.Type {
switch repoType {
case "hosted":
return s.client.CreateDockerHostedRepository(req)
case "proxy":
Expand All @@ -293,7 +298,7 @@ func (s *ApplyService) createRepository(repo config.Repository) error {
return s.client.CreateDockerGroupRepository(req)
}
case "npm":
switch repo.Type {
switch repoType {
case "hosted":
return s.client.CreateNpmHostedRepository(req)
case "proxy":
Expand All @@ -302,7 +307,7 @@ func (s *ApplyService) createRepository(repo config.Repository) error {
return s.client.CreateNpmGroupRepository(req)
}
case "pypi":
switch repo.Type {
switch repoType {
case "hosted":
return s.client.CreatePypiHostedRepository(req)
case "proxy":
Expand All @@ -311,19 +316,28 @@ func (s *ApplyService) createRepository(repo config.Repository) error {
return s.client.CreatePypiGroupRepository(req)
}
case "go":
switch repo.Type {
switch repoType {
case "proxy":
return s.client.CreateGoProxyRepository(req)
case "group":
return s.client.CreateGoGroupRepository(req)
default:
return fmt.Errorf("go format only supports proxy and group types")
}
case "raw":
switch repoType {
case "hosted":
return s.client.CreateRawHostedRepository(req)
case "proxy":
return s.client.CreateRawProxyRepository(req)
case "group":
return s.client.CreateRawGroupRepository(req)
}
default:
return fmt.Errorf("unsupported repository format: %s", repo.Format)
return fmt.Errorf("unsupported repository format: %s", format)
}

return fmt.Errorf("unsupported repository type: %s for format: %s", repo.Type, repo.Format)
return fmt.Errorf("unsupported repository type: %s for format: %s", repoType, format)
}

// applyUsers 应用用户配置
Expand Down
Loading