From 78a81b3ae196cbaf832e0a69716334a1dba73496 Mon Sep 17 00:00:00 2001 From: yohann-bacha <122296171+yohann-bacha@users.noreply.github.com> Date: Thu, 4 May 2023 14:42:56 +0200 Subject: [PATCH] feat: query data of a single pull request (#335) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add a way (baby don't hurt me) to query data of a single pull request * fix: wrong api path * fix: nitpicked Co-authored-by: Étienne M. * fix imports --------- Co-authored-by: Étienne M. --- scm_repo_link.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/scm_repo_link.go b/scm_repo_link.go index 094fd35a..9ddc50a4 100644 --- a/scm_repo_link.go +++ b/scm_repo_link.go @@ -2,6 +2,7 @@ package scalingo import ( "context" + "fmt" "time" "gopkg.in/errgo.v1" @@ -15,6 +16,7 @@ type SCMRepoLinkService interface { SCMRepoLinkCreate(ctx context.Context, app string, params SCMRepoLinkCreateParams) (*SCMRepoLink, error) SCMRepoLinkUpdate(ctx context.Context, app string, params SCMRepoLinkUpdateParams) (*SCMRepoLink, error) SCMRepoLinkDelete(ctx context.Context, app string) error + SCMRepoLinkPullRequest(ctx context.Context, app string, number int) (*RepoLinkPullRequest, error) SCMRepoLinkManualDeploy(ctx context.Context, app, branch string) (*Deployment, error) SCMRepoLinkManualReviewApp(ctx context.Context, app, pullRequestID string) error @@ -97,6 +99,20 @@ type SCMRepoLinkReviewAppsResponse struct { ReviewApps []*ReviewApp `json:"review_apps"` } +type SCMRepoLinkPullRequestResponse struct { + Pull RepoLinkPullRequest `json:"pull"` +} + +type RepoLinkPullRequest struct { + ID int `json:"id"` + Number int `json:"number"` + Title string `json:"title"` + HTMLURL string `json:"html_url"` + SourceRepoName string `json:"source_repo_name"` + SourceRepoHTMLURL string `json:"source_repo_html_url"` + OpenedFromAForkedRepo bool `json:"opened_from_a_forked_repo"` +} + var _ SCMRepoLinkService = (*Client)(nil) func (c *Client) SCMRepoLinkList(ctx context.Context, opts PaginationOpts) ([]*SCMRepoLink, PaginationMeta, error) { @@ -165,6 +181,19 @@ func (c *Client) SCMRepoLinkDelete(ctx context.Context, app string) error { return nil } +func (c *Client) SCMRepoLinkPullRequest(ctx context.Context, app string, number int) (*RepoLinkPullRequest, error) { + var res SCMRepoLinkPullRequestResponse + err := c.ScalingoAPI().DoRequest(ctx, &http.APIRequest{ + Method: "GET", + Endpoint: fmt.Sprintf("/apps/%s/scm_repo_link/pulls/%d", app, number), + Expected: http.Statuses{200}, + }, &res) + if err != nil { + return nil, errgo.Notef(err, "fail to get this SCM repo link") + } + return &res.Pull, nil +} + func (c *Client) SCMRepoLinkManualDeploy(ctx context.Context, app, branch string) (*Deployment, error) { var res SCMRepoLinkManualDeployResponse err := c.ScalingoAPI().DoRequest(ctx, &http.APIRequest{