Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated integrations/scm_repo_link structs and urls #126

Merged
merged 3 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 0 additions & 104 deletions integrations.go

This file was deleted.

108 changes: 108 additions & 0 deletions scm_integrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package scalingo

import (
"gopkg.in/errgo.v1"

"github.com/Scalingo/go-scalingo/http"
)

type SCMType string

// Type of SCM integrations
const (
SCMGithubType SCMType = "github" // GitHub
SCMGithubEnterpriseType SCMType = "github-enterprise" // GitHub Enterprise (private instance)
SCMGitlabType SCMType = "gitlab" // GitLab.com
SCMGitlabSelfHostedType SCMType = "gitlab-self-hosted" // GitLab self-hosted (private instance)
)

func (t SCMType) Str() string {
return string(t)
}

type SCMIntegrationsService interface {
SCMIntegrationsList() ([]SCMIntegration, error)
SCMIntegrationsCreate(scmType SCMType, url string, accessToken string) (*SCMIntegration, error)
SCMIntegrationsDestroy(id string) error
}

var _ SCMIntegrationsService = (*Client)(nil)

type SCMIntegration struct {
ID string `json:"id,omitempty"`
brandon-welsch marked this conversation as resolved.
Show resolved Hide resolved
SCMType SCMType `json:"scm_type"`
Url string `json:"url"`
brandon-welsch marked this conversation as resolved.
Show resolved Hide resolved
AccessToken string `json:"access_token"`
Uid string `json:"uid,omitempty"`
EtienneM marked this conversation as resolved.
Show resolved Hide resolved
Username string `json:"username,omitempty"`
Email string `json:"email,omitempty"`
AvatarUrl string `json:"avatar_url,omitempty"`
brandon-welsch marked this conversation as resolved.
Show resolved Hide resolved
ProfileUrl string `json:"profile_url,omitempty"`
brandon-welsch marked this conversation as resolved.
Show resolved Hide resolved
}

type SCMIntegrationRes struct {
SCMIntegration SCMIntegration `json:"scm_integration"`
}

type SCMIntegrationsRes struct {
SCMIntegrations []SCMIntegration `json:"scm_integrations"`
}

func (c *Client) SCMIntegrationsList() ([]SCMIntegration, error) {
var res SCMIntegrationsRes

err := c.AuthAPI().ResourceList("scm_integrations", nil, &res)
if err != nil {
return nil, errgo.Mask(err)
brandon-welsch marked this conversation as resolved.
Show resolved Hide resolved
}
return res.SCMIntegrations, nil
}

func (c *Client) SCMIntegrationsShow(id string) (*SCMIntegration, error) {
var res SCMIntegrationRes

err := c.AuthAPI().ResourceGet("scm_integrations", id, nil, &res)
if err != nil {
return nil, errgo.Mask(err)
}
return &res.SCMIntegration, nil
}

func (c *Client) SCMIntegrationsCreate(scmType SCMType, url string, accessToken string) (*SCMIntegration, error) {
payload := SCMIntegrationRes{SCMIntegration{
SCMType: scmType,
Url: url,
AccessToken: accessToken,
}}
var res SCMIntegrationRes

err := c.AuthAPI().ResourceAdd("scm_integrations", payload, &res)
if err != nil {
return nil, errgo.Mask(err)
}

return &res.SCMIntegration, nil
}

func (c *Client) SCMIntegrationsDestroy(id string) error {
err := c.AuthAPI().ResourceDelete("scm_integrations", id)
if err != nil {
return errgo.Mask(err)
}
return nil
}

func (c *Client) SCMIntegrationsImportKeys(id string) ([]Key, error) {
var res KeysRes

var err = c.AuthAPI().DoRequest(&http.APIRequest{
Method: "POST",
Endpoint: "/scm_integrations/" + id + "/import_keys",
Params: nil,
Expected: http.Statuses{201},
}, &res)
if err != nil {
return nil, errgo.Mask(err)
}
return res.Keys, nil
}
68 changes: 34 additions & 34 deletions scm_repo_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import (
"github.com/Scalingo/go-scalingo/http"
)

type ScmRepoLinkService interface {
ScmRepoLinkShow(app string) (*ScmRepoLink, error)
ScmRepoLinkCreate(app string, params ScmRepoLinkParams) (*ScmRepoLink, error)
ScmRepoLinkUpdate(app string, params ScmRepoLinkParams) (*ScmRepoLink, error)
ScmRepoLinkDelete(app string) error

ScmRepoLinkManualDeploy(app, branch string) error
ScmRepoLinkManualReviewApp(app, pullRequestId string) error
ScmRepoLinkDeployments(app string) ([]*Deployment, error)
ScmRepoLinkReviewApps(app string) ([]*ReviewApp, error)
type SCMRepoLinkService interface {
SCMRepoLinkShow(app string) (*SCMRepoLink, error)
SCMRepoLinkCreate(app string, params SCMRepoLinkParams) (*SCMRepoLink, error)
SCMRepoLinkUpdate(app string, params SCMRepoLinkParams) (*SCMRepoLink, error)
SCMRepoLinkDelete(app string) error

SCMRepoLinkManualDeploy(app, branch string) error
SCMRepoLinkManualReviewApp(app, pullRequestId string) error
SCMRepoLinkDeployments(app string) ([]*Deployment, error)
SCMRepoLinkReviewApps(app string) ([]*ReviewApp, error)
}

type ScmRepoLinkParams struct {
type SCMRepoLinkParams struct {
Source *string `json:"source,omitempty"`
Branch *string `json:"branch,omitempty"`
AuthIntegrationID *string `json:"auth_integration_id,omitempty"`
AuthIntegrationUUID *string `json:"auth_integration_uuid,omitempty"`
ScmIntegrationUUID *string `json:"scm_integration_uuid,omitempty"`
AutoDeployEnabled *bool `json:"auto_deploy_enabled,omitempty"`
DeployReviewAppsEnabled *bool `json:"deploy_review_apps_enabled,omitempty"`
Expand All @@ -31,10 +31,10 @@ type ScmRepoLinkParams struct {
HoursBeforeDeleteStale *uint `json:"hours_before_delete_stale,omitempty"`
}

type ScmRepoLink struct {
type SCMRepoLink struct {
ID string `json:"id"`
AppID string `json:"app_id"`
Linker ScmRepoLinkLinker `json:"linker"`
Linker SCMRepoLinkLinker `json:"linker"`
Owner string `json:"owner"`
Repo string `json:"repo"`
Branch string `json:"branch"`
Expand All @@ -51,27 +51,27 @@ type ScmRepoLink struct {
LastAutoDeployAt time.Time `json:"last_auto_deploy_at"`
}

type ScmRepoLinkLinker struct {
type SCMRepoLinkLinker struct {
Username string `json:"username"`
Email string `json:"email"`
ID string `json:"id"`
}

type ScmRepoLinkResponse struct {
ScmRepoLink *ScmRepoLink `json:"scm_repo_link"`
SCMRepoLink *SCMRepoLink `json:"scm_repo_link"`
}

type ScmRepoLinkDeploymentsResponse struct {
type SCMRepoLinkDeploymentsResponse struct {
Deployments []*Deployment `json:"deployments"`
}

type ScmRepoLinkReviewAppsResponse struct {
type SCMRepoLinkReviewAppsResponse struct {
ReviewApps []*ReviewApp `json:"review_apps"`
}

var _ ScmRepoLinkService = (*Client)(nil)
var _ SCMRepoLinkService = (*Client)(nil)

func (c *Client) ScmRepoLinkShow(app string) (*ScmRepoLink, error) {
func (c *Client) SCMRepoLinkShow(app string) (*SCMRepoLink, error) {
var res ScmRepoLinkResponse
err := c.ScalingoAPI().DoRequest(&http.APIRequest{
Method: "GET",
Expand All @@ -81,40 +81,40 @@ func (c *Client) ScmRepoLinkShow(app string) (*ScmRepoLink, error) {
if err != nil {
return nil, err
}
return res.ScmRepoLink, nil
return res.SCMRepoLink, nil
}

func (c *Client) ScmRepoLinkCreate(app string, params ScmRepoLinkParams) (*ScmRepoLink, error) {
func (c *Client) SCMRepoLinkCreate(app string, params SCMRepoLinkParams) (*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]SCMRepoLinkParams{"scm_repo_link": params},
}, &res)
if err != nil {
return nil, err
}

return res.ScmRepoLink, nil
return res.SCMRepoLink, nil
}

func (c *Client) ScmRepoLinkUpdate(app string, params ScmRepoLinkParams) (*ScmRepoLink, error) {
func (c *Client) SCMRepoLinkUpdate(app string, params SCMRepoLinkParams) (*SCMRepoLink, error) {
var res ScmRepoLinkResponse
err := c.ScalingoAPI().DoRequest(&http.APIRequest{
Method: "UPDATE",
Endpoint: "/apps/" + app + "/scm_repo_link",
Expected: http.Statuses{200},
Params: map[string]ScmRepoLinkParams{"scm_repo_link": params},
Params: map[string]SCMRepoLinkParams{"scm_repo_link": params},
}, &res)
if err != nil {
return nil, err
}

return res.ScmRepoLink, nil
return res.SCMRepoLink, nil
}

func (c *Client) ScmRepoLinkDelete(app string) error {
func (c *Client) SCMRepoLinkDelete(app string) error {
_, err := c.ScalingoAPI().Do(&http.APIRequest{
Method: "DELETE",
Endpoint: "/apps/" + app + "/scm_repo_link",
Expand All @@ -123,7 +123,7 @@ func (c *Client) ScmRepoLinkDelete(app string) error {
return err
}

func (c *Client) ScmRepoLinkManualDeploy(app, branch string) error {
func (c *Client) SCMRepoLinkManualDeploy(app, branch string) error {
_, err := c.ScalingoAPI().Do(&http.APIRequest{
Method: "POST",
Endpoint: "/apps/" + app + "/scm_repo_link/manual_deploy",
Expand All @@ -133,7 +133,7 @@ func (c *Client) ScmRepoLinkManualDeploy(app, branch string) error {
return err
}

func (c *Client) ScmRepoLinkManualReviewApp(app, pullRequestId string) error {
func (c *Client) SCMRepoLinkManualReviewApp(app, pullRequestId string) error {
_, err := c.ScalingoAPI().Do(&http.APIRequest{
Method: "POST",
Endpoint: "/apps/" + app + "/scm_repo_link/manual_review_app",
Expand All @@ -143,8 +143,8 @@ func (c *Client) ScmRepoLinkManualReviewApp(app, pullRequestId string) error {
return err
}

func (c *Client) ScmRepoLinkDeployments(app string) ([]*Deployment, error) {
var res ScmRepoLinkDeploymentsResponse
func (c *Client) SCMRepoLinkDeployments(app string) ([]*Deployment, error) {
var res SCMRepoLinkDeploymentsResponse

err := c.ScalingoAPI().DoRequest(&http.APIRequest{
Method: "GET",
Expand All @@ -157,8 +157,8 @@ func (c *Client) ScmRepoLinkDeployments(app string) ([]*Deployment, error) {
return res.Deployments, nil
}

func (c *Client) ScmRepoLinkReviewApps(app string) ([]*ReviewApp, error) {
var res ScmRepoLinkReviewAppsResponse
func (c *Client) SCMRepoLinkReviewApps(app string) ([]*ReviewApp, error) {
var res SCMRepoLinkReviewAppsResponse

err := c.ScalingoAPI().DoRequest(&http.APIRequest{
Method: "GET",
Expand Down