Skip to content

Commit

Permalink
Merge pull request #17 from datadrivers/v0.8.1
Browse files Browse the repository at this point in the history
Fix maven repository format issue and add more repository format constants
  • Loading branch information
Nosmoht authored May 8, 2020
2 parents 45d97d1 + e196a79 commit 7b58341
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"
)

const (
repositoryAPIEndpoint = "service/rest/beta/repositories"

RepositoryFormatApt = "apt"
RepositoryFormatBower = "bower"
RepositoryFormatConan = "conan"
RepositoryFormatDocker = "docker"
RepositoryFormatMaven2 = "maven"
RepositoryFormatHelm = "helm"
RepositoryFormatMaven2 = "maven2"
RepositoryFormatNPM = "npm"
RepositoryFormatNuget = "nuget"
RepositoryFormatPyPI = "pypi"
RepositoryFormatYum = "yum"

RepositoryTypeHosted = "hosted"
RepositoryTypeGroup = "group"
Expand Down Expand Up @@ -159,13 +166,19 @@ func jsonUnmarshalRepositories(data []byte) ([]Repository, error) {
return repositories, nil
}

// Currently only used to replace repository format 'maven2' to 'maven' as API
// returns a format of 'maven2' but requires to send to requests using 'maven'.
func fixRepositoryFormat(s string) string {
return strings.Replace(s, RepositoryFormatMaven2, "maven", 1)
}

func (c client) RepositoryCreate(repo Repository) error {
data, err := jsonMarshalInterfaceToIOReader(repo)
if err != nil {
return err
}

body, resp, err := c.Post(fmt.Sprintf("%s/%s/%s", repositoryAPIEndpoint, repo.Format, repo.Type), data)
body, resp, err := c.Post(fmt.Sprintf("%s/%s/%s", repositoryAPIEndpoint, fixRepositoryFormat(repo.Format), repo.Type), data)
if err != nil {
return err
}
Expand Down Expand Up @@ -206,7 +219,7 @@ func (c client) RepositoryUpdate(id string, repo Repository) error {
return err
}

body, resp, err := c.Put(fmt.Sprintf("%s/%s/%s/%s", repositoryAPIEndpoint, repo.Format, repo.Type, id), data)
body, resp, err := c.Put(fmt.Sprintf("%s/%s/%s/%s", repositoryAPIEndpoint, fixRepositoryFormat(repo.Format), repo.Type, id), data)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestJSONUnmarshalRepositories(t *testing.T) {
func testJSONUnmarshalRepositories() string {
return fmt.Sprintf(`[
{
"format": "maven",
"format": "maven2",
"name": "maven-central",
"online": true,
"type": "proxy",
Expand Down

0 comments on commit 7b58341

Please sign in to comment.