Skip to content

Commit

Permalink
Merge pull request #137 from Scalingo/fix/133/remove_incorrect_fields
Browse files Browse the repository at this point in the history
Remove incorrect fields in SCMRepoLinkParams for PATCH update
  • Loading branch information
Soulou authored Sep 5, 2019
2 parents aab97e6 + b40724f commit 155f6ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## ToBeReleased

* Removed the `SCMRepoLinkParams` struct. You should use `SCMRepoLinkCreateParams` instead for creation call
* Added the `SCMRepoLinkUpdateParams` struct, you should use this for update call.

## v3.0.3

* Add support (again) for the new SCM events [#135](https://github.com/Scalingo/go-scalingo/pull/135)
Expand Down
24 changes: 17 additions & 7 deletions scm_repo_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

type SCMRepoLinkService interface {
SCMRepoLinkShow(app string) (*SCMRepoLink, error)
SCMRepoLinkCreate(app string, params SCMRepoLinkParams) (*SCMRepoLink, error)
SCMRepoLinkUpdate(app string, params SCMRepoLinkParams) (*SCMRepoLink, error)
SCMRepoLinkCreate(app string, params SCMRepoLinkCreateParams) (*SCMRepoLink, error)
SCMRepoLinkUpdate(app string, params SCMRepoLinkUpdateParams) (*SCMRepoLink, error)
SCMRepoLinkDelete(app string) error

SCMRepoLinkManualDeploy(app, branch string) error
Expand All @@ -20,7 +20,7 @@ type SCMRepoLinkService interface {
SCMRepoLinkReviewApps(app string) ([]*ReviewApp, error)
}

type SCMRepoLinkParams struct {
type SCMRepoLinkCreateParams struct {
Source *string `json:"source,omitempty"`
Branch *string `json:"branch,omitempty"`
AuthIntegrationUUID *string `json:"auth_integration_uuid,omitempty"`
Expand All @@ -33,6 +33,16 @@ type SCMRepoLinkParams struct {
HoursBeforeDeleteStale *uint `json:"hours_before_delete_stale,omitempty"`
}

type SCMRepoLinkUpdateParams struct {
Branch *string `json:"branch,omitempty"`
AutoDeployEnabled *bool `json:"auto_deploy_enabled,omitempty"`
DeployReviewAppsEnabled *bool `json:"deploy_review_apps_enabled,omitempty"`
DestroyOnCloseEnabled *bool `json:"delete_on_close_enabled,omitempty"`
HoursBeforeDeleteOnClose *uint `json:"hours_before_delete_on_close,omitempty"`
DestroyStaleEnabled *bool `json:"delete_stale_enabled,omitempty"`
HoursBeforeDeleteStale *uint `json:"hours_before_delete_stale,omitempty"`
}

type SCMRepoLink struct {
ID string `json:"id"`
AppID string `json:"app_id"`
Expand Down Expand Up @@ -86,13 +96,13 @@ func (c *Client) SCMRepoLinkShow(app string) (*SCMRepoLink, error) {
return res.SCMRepoLink, nil
}

func (c *Client) SCMRepoLinkCreate(app string, params SCMRepoLinkParams) (*SCMRepoLink, error) {
func (c *Client) SCMRepoLinkCreate(app string, params SCMRepoLinkCreateParams) (*SCMRepoLink, error) {
var res ScmRepoLinkResponse
err := c.ScalingoAPI().DoRequest(&http.APIRequest{
Method: "POST",
Endpoint: "/apps/" + app + "/scm_repo_link",
Expected: http.Statuses{201},
Params: map[string]SCMRepoLinkParams{"scm_repo_link": params},
Params: map[string]SCMRepoLinkCreateParams{"scm_repo_link": params},
}, &res)
if err != nil {
return nil, errgo.Notef(err, "fail to create the SCM repo link")
Expand All @@ -101,13 +111,13 @@ func (c *Client) SCMRepoLinkCreate(app string, params SCMRepoLinkParams) (*SCMRe
return res.SCMRepoLink, nil
}

func (c *Client) SCMRepoLinkUpdate(app string, params SCMRepoLinkParams) (*SCMRepoLink, error) {
func (c *Client) SCMRepoLinkUpdate(app string, params SCMRepoLinkUpdateParams) (*SCMRepoLink, error) {
var res ScmRepoLinkResponse
err := c.ScalingoAPI().DoRequest(&http.APIRequest{
Method: "PATCH",
Endpoint: "/apps/" + app + "/scm_repo_link",
Expected: http.Statuses{200},
Params: map[string]SCMRepoLinkParams{"scm_repo_link": params},
Params: map[string]SCMRepoLinkUpdateParams{"scm_repo_link": params},
}, &res)
if err != nil {
return nil, errgo.Notef(err, "fail to update this SCM repo link")
Expand Down

0 comments on commit 155f6ab

Please sign in to comment.