refactor(params): ♻️ Simplify ForgeURL logic by removing redundant switch case
Some checks failed
CodeQL / Analyze (push) Failing after 2s
Go Tests / Linters (push) Successful in 3m26s
Go Tests / go-tests (push) Successful in 6m41s

Streamlines the ForgeURL method by removing an unnecessary nested switch case
on ForgeType, consolidating the logic to rely solely on EntityType. This change
reduces complexity and improves code readability without altering functionality.
This commit is contained in:
Daniel Sy 2025-08-27 16:04:56 +02:00
parent 29f2e2a2b9
commit 6608d0aa8c
Signed by: Daniel.Sy
GPG key ID: 1F39A8BBCD2EE3D3

View file

@ -1170,18 +1170,13 @@ func (g ForgeEntity) GetForgeType() (EndpointType, error) {
} }
func (g ForgeEntity) ForgeURL() string { func (g ForgeEntity) ForgeURL() string {
switch g.Credentials.ForgeType { switch g.EntityType {
case GiteaEndpointType: case ForgeEntityTypeRepository:
return g.Credentials.Endpoint.APIBaseURL return fmt.Sprintf("%s/%s/%s", g.Credentials.BaseURL, g.Owner, g.Name)
default: case ForgeEntityTypeOrganization:
switch g.EntityType { return fmt.Sprintf("%s/%s", g.Credentials.BaseURL, g.Owner)
case ForgeEntityTypeRepository: case ForgeEntityTypeEnterprise:
return fmt.Sprintf("%s/%s/%s", g.Credentials.BaseURL, g.Owner, g.Name) return fmt.Sprintf("%s/enterprises/%s", g.Credentials.BaseURL, g.Owner)
case ForgeEntityTypeOrganization:
return fmt.Sprintf("%s/%s", g.Credentials.BaseURL, g.Owner)
case ForgeEntityTypeEnterprise:
return fmt.Sprintf("%s/enterprises/%s", g.Credentials.BaseURL, g.Owner)
}
} }
return "" return ""
} }