Skip to content

Commit

Permalink
support comma in project name
Browse files Browse the repository at this point in the history
  • Loading branch information
miryamfoiferCX committed Sep 25, 2024
1 parent f20c040 commit d33966f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions internal/services/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func FindProject(
}

func GetProjectsCollectionByProjectName(projectName string, projectsWrapper wrappers.ProjectsWrapper) (*wrappers.ProjectsCollectionResponseModel, error) {
params := make(map[string]string)
params["names"] = projectName
params := make(map[string][]string)
params["names"] = []string{projectName}
resp, _, err := projectsWrapper.Get(params)

if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/wrappers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,21 @@ func SendHTTPRequestPasswordAuth(method string, body io.Reader, timeout uint, us
}

func SendPrivateHTTPRequestWithQueryParams(
method, path string, params map[string]string,
method, path string, params map[string][]string,
body io.Reader, timeout uint,
) (*http.Response, error) {
return HTTPRequestWithQueryParams(method, path, params, body, timeout, false)
}

func SendHTTPRequestWithQueryParams(
method, path string, params map[string]string,
method, path string, params map[string][]string,
body io.Reader, timeout uint,
) (*http.Response, error) {
return HTTPRequestWithQueryParams(method, path, params, body, timeout, true)
}

func HTTPRequestWithQueryParams(
method, path string, params map[string]string,
method, path string, params map[string][]string,
body io.Reader, timeout uint, printBody bool,
) (*http.Response, error) {
u, accessToken, err := getURLAndAccessToken(path)
Expand All @@ -297,7 +297,7 @@ func HTTPRequestWithQueryParams(
}
q := req.URL.Query()
for k, v := range params {
q.Add(k, v)
q.Add(k, v[0])
}
req.URL.RawQuery = q.Encode()
enrichWithOath2Credentials(req, accessToken, bearerFormat)
Expand Down
16 changes: 8 additions & 8 deletions internal/wrappers/projects-http.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (p *ProjectsHTTPWrapper) UpdateConfiguration(projectID string, configuratio
return nil, err
}

params := map[string]string{
commonParams.ProjectIDFlag: projectID,
params := map[string][]string{
commonParams.ProjectIDFlag: {projectID},
}

resp, err := SendHTTPRequestWithQueryParams(http.MethodPatch, "api/configuration/project", params, bytes.NewBuffer(jsonBytes), clientTimeout)
Expand All @@ -91,13 +91,13 @@ func (p *ProjectsHTTPWrapper) UpdateConfiguration(projectID string, configuratio
return handleProjectResponseWithNoBody(resp, err, http.StatusNoContent)
}

func (p *ProjectsHTTPWrapper) Get(params map[string]string) (
func (p *ProjectsHTTPWrapper) Get(params map[string][]string) (
*ProjectsCollectionResponseModel,
*ErrorModel, error) {
clientTimeout := viper.GetUint(commonParams.ClientTimeoutKey)

if _, ok := params[limit]; !ok {
params[limit] = limitValue
params[limit] = []string{limitValue}
}

resp, err := SendHTTPRequestWithQueryParams(http.MethodGet, p.path, params, nil, clientTimeout)
Expand Down Expand Up @@ -153,8 +153,8 @@ func (p *ProjectsHTTPWrapper) GetByName(name string) (
*ProjectResponseModel,
*ErrorModel,
error) {
params := make(map[string]string)
params["name"] = name
params := make(map[string][]string)
params["name"] = []string{name}
resp, _, err := p.Get(params)
if err != nil {
return nil, nil, err
Expand All @@ -174,12 +174,12 @@ func (p *ProjectsHTTPWrapper) GetByName(name string) (
return nil, nil, errors.Errorf(errorConstants.ProjectNotExists)
}

func (p *ProjectsHTTPWrapper) GetBranchesByID(projectID string, params map[string]string) ([]string, *ErrorModel, error) {
func (p *ProjectsHTTPWrapper) GetBranchesByID(projectID string, params map[string][]string) ([]string, *ErrorModel, error) {
clientTimeout := viper.GetUint(commonParams.ClientTimeoutKey)

var request = "/branches?project-id=" + projectID

params["limit"] = limitValue
params["limit"] = []string{limitValue}
resp, err := SendHTTPRequestWithQueryParams(http.MethodGet, p.path+request, params, nil, clientTimeout)
if err != nil {
return nil, nil, err
Expand Down
5 changes: 3 additions & 2 deletions internal/wrappers/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ type ProjectConfiguration struct {
type ProjectsWrapper interface {
Create(model *Project) (*ProjectResponseModel, *ErrorModel, error)
Update(projectID string, model *Project) error
Get(params map[string]string) (*ProjectsCollectionResponseModel, *ErrorModel, error)
Get(params map[string][]string) (*ProjectsCollectionResponseModel, *ErrorModel, error)
//Get(params map[string][]string) (*ProjectsCollectionResponseModel, *ErrorModel, error)
GetByID(projectID string) (*ProjectResponseModel, *ErrorModel, error)
GetByName(name string) (*ProjectResponseModel, *ErrorModel, error)
GetBranchesByID(projectID string, params map[string]string) ([]string, *ErrorModel, error)
GetBranchesByID(projectID string, params map[string][]string) ([]string, *ErrorModel, error)
Delete(projectID string) (*ErrorModel, error)
Tags() (map[string][]string, *ErrorModel, error)
UpdateConfiguration(projectID string, configuration []ProjectConfiguration) (*ErrorModel, error)
Expand Down

0 comments on commit d33966f

Please sign in to comment.