diff --git a/models.go b/models.go index c8bdffc..4115ed8 100644 --- a/models.go +++ b/models.go @@ -34,7 +34,7 @@ type RepositoryLink struct { type CreateProjectRequest struct { Name string `json:"name"` Framework string `json:"framework"` - GitRepository *GitRepositoryRequest `json:"gitRepository"` + GitRepository *GitRepositoryRequest `json:"gitRepository,omitempty"` } type GitRepositoryRequest struct { diff --git a/projects.go b/projects.go index e2fe435..b3f8057 100644 --- a/projects.go +++ b/projects.go @@ -22,24 +22,18 @@ func (p *ProjectApi) CreateProject(ctx context.Context, name string, framework s rel := &url.URL{Path: "/v6/projects"} u := p.baseUrl.ResolveReference(rel) - var body *CreateProjectRequest + body := &CreateProjectRequest{ + Name: name, + Framework: framework, + } + if repositoryType != "" && repositoryName != "" { - body = &CreateProjectRequest{ - Name: name, - Framework: framework, - GitRepository: &GitRepositoryRequest{ - Type: repositoryType, - Repo: repositoryName, - }, - } - } else { - body = &CreateProjectRequest{ - Name: name, - Framework: framework, + body.GitRepository = &GitRepositoryRequest{ + Type: repositoryType, + Repo: repositoryName, } } - payload, err := json.Marshal(body) if err != nil { return nil, err