2016-08-14 11:32:53 +01:00
|
|
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
2020-01-03 06:22:50 +00:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2016-08-14 11:32:53 +01:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2016-11-07 01:57:49 +00:00
|
|
|
package gitea
|
2016-08-14 11:32:53 +01:00
|
|
|
|
|
|
|
import (
|
2016-10-11 20:52:07 +01:00
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-01-16 03:52:26 +00:00
|
|
|
"net/url"
|
2020-06-09 11:47:55 +01:00
|
|
|
"strings"
|
2019-10-13 02:34:01 +01:00
|
|
|
"time"
|
2022-01-04 16:31:31 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/go-version"
|
2019-05-11 16:38:52 +01:00
|
|
|
)
|
2016-10-11 20:52:07 +01:00
|
|
|
|
2019-10-13 02:34:01 +01:00
|
|
|
// PRBranchInfo information about a branch
|
|
|
|
type PRBranchInfo struct {
|
|
|
|
Name string `json:"label"`
|
|
|
|
Ref string `json:"ref"`
|
|
|
|
Sha string `json:"sha"`
|
|
|
|
RepoID int64 `json:"repo_id"`
|
|
|
|
Repository *Repository `json:"repo"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PullRequest represents a pull request
|
|
|
|
type PullRequest struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
URL string `json:"url"`
|
|
|
|
Index int64 `json:"number"`
|
|
|
|
Poster *User `json:"user"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Body string `json:"body"`
|
|
|
|
Labels []*Label `json:"labels"`
|
|
|
|
Milestone *Milestone `json:"milestone"`
|
|
|
|
Assignee *User `json:"assignee"`
|
|
|
|
Assignees []*User `json:"assignees"`
|
|
|
|
State StateType `json:"state"`
|
2020-06-04 02:01:13 +01:00
|
|
|
IsLocked bool `json:"is_locked"`
|
2019-10-13 02:34:01 +01:00
|
|
|
Comments int `json:"comments"`
|
|
|
|
|
|
|
|
HTMLURL string `json:"html_url"`
|
|
|
|
DiffURL string `json:"diff_url"`
|
|
|
|
PatchURL string `json:"patch_url"`
|
|
|
|
|
|
|
|
Mergeable bool `json:"mergeable"`
|
|
|
|
HasMerged bool `json:"merged"`
|
|
|
|
Merged *time.Time `json:"merged_at"`
|
|
|
|
MergedCommitID *string `json:"merge_commit_sha"`
|
|
|
|
MergedBy *User `json:"merged_by"`
|
|
|
|
|
|
|
|
Base *PRBranchInfo `json:"base"`
|
|
|
|
Head *PRBranchInfo `json:"head"`
|
|
|
|
MergeBase string `json:"merge_base"`
|
|
|
|
|
|
|
|
Deadline *time.Time `json:"due_date"`
|
|
|
|
Created *time.Time `json:"created_at"`
|
|
|
|
Updated *time.Time `json:"updated_at"`
|
|
|
|
Closed *time.Time `json:"closed_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListPullRequestsOptions options for listing pull requests
|
|
|
|
type ListPullRequestsOptions struct {
|
2020-02-05 07:59:55 +00:00
|
|
|
ListOptions
|
2020-02-04 07:58:46 +00:00
|
|
|
State StateType `json:"state"`
|
2020-01-13 17:58:39 +00:00
|
|
|
// oldest, recentupdate, leastupdate, mostcomment, leastcomment, priority
|
2020-02-05 07:59:55 +00:00
|
|
|
Sort string
|
|
|
|
Milestone int64
|
2019-10-13 02:34:01 +01:00
|
|
|
}
|
2016-10-11 20:52:07 +01:00
|
|
|
|
2020-05-20 23:41:21 +01:00
|
|
|
// MergeStyle is used specify how a pull is merged
|
|
|
|
type MergeStyle string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// MergeStyleMerge merge pull as usual
|
|
|
|
MergeStyleMerge MergeStyle = "merge"
|
|
|
|
// MergeStyleRebase rebase pull
|
|
|
|
MergeStyleRebase MergeStyle = "rebase"
|
|
|
|
// MergeStyleRebaseMerge rebase and merge pull
|
|
|
|
MergeStyleRebaseMerge MergeStyle = "rebase-merge"
|
|
|
|
// MergeStyleSquash squash and merge pull
|
|
|
|
MergeStyleSquash MergeStyle = "squash"
|
|
|
|
)
|
|
|
|
|
2020-02-05 07:59:55 +00:00
|
|
|
// QueryEncode turns options into querystring argument
|
|
|
|
func (opt *ListPullRequestsOptions) QueryEncode() string {
|
|
|
|
query := opt.getURLQuery()
|
2020-01-16 03:52:26 +00:00
|
|
|
if len(opt.State) > 0 {
|
2020-02-04 07:58:46 +00:00
|
|
|
query.Add("state", string(opt.State))
|
2020-01-16 03:52:26 +00:00
|
|
|
}
|
|
|
|
if len(opt.Sort) > 0 {
|
|
|
|
query.Add("sort", opt.Sort)
|
|
|
|
}
|
|
|
|
if opt.Milestone > 0 {
|
|
|
|
query.Add("milestone", fmt.Sprintf("%d", opt.Milestone))
|
|
|
|
}
|
2020-02-05 07:59:55 +00:00
|
|
|
return query.Encode()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListRepoPullRequests list PRs of one repository
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, *Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2020-02-05 07:59:55 +00:00
|
|
|
opt.setDefaults()
|
|
|
|
prs := make([]*PullRequest, 0, opt.PageSize)
|
|
|
|
|
|
|
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/pulls", owner, repo))
|
|
|
|
link.RawQuery = opt.QueryEncode()
|
2020-09-14 03:37:09 +01:00
|
|
|
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &prs)
|
2021-03-08 21:15:42 +00:00
|
|
|
if c.checkServerVersionGreaterThanOrEqual(version1_14_0) != nil {
|
|
|
|
for i := range prs {
|
|
|
|
if err := fixPullHeadSha(c, prs[i]); err != nil {
|
|
|
|
return prs, resp, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-14 03:37:09 +01:00
|
|
|
return prs, resp, err
|
2016-10-11 20:52:07 +01:00
|
|
|
}
|
|
|
|
|
2016-11-10 09:44:00 +00:00
|
|
|
// GetPullRequest get information of one PR
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest, *Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2016-10-11 20:52:07 +01:00
|
|
|
pr := new(PullRequest)
|
2020-09-14 03:37:09 +01:00
|
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index), nil, nil, pr)
|
2021-03-08 21:15:42 +00:00
|
|
|
if c.checkServerVersionGreaterThanOrEqual(version1_14_0) != nil {
|
|
|
|
if err := fixPullHeadSha(c, pr); err != nil {
|
|
|
|
return pr, resp, err
|
|
|
|
}
|
|
|
|
}
|
2020-09-14 03:37:09 +01:00
|
|
|
return pr, resp, err
|
2016-10-11 20:52:07 +01:00
|
|
|
}
|
|
|
|
|
2019-10-13 02:34:01 +01:00
|
|
|
// CreatePullRequestOption options when creating a pull request
|
|
|
|
type CreatePullRequestOption struct {
|
|
|
|
Head string `json:"head"`
|
|
|
|
Base string `json:"base"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Body string `json:"body"`
|
|
|
|
Assignee string `json:"assignee"`
|
|
|
|
Assignees []string `json:"assignees"`
|
|
|
|
Milestone int64 `json:"milestone"`
|
|
|
|
Labels []int64 `json:"labels"`
|
|
|
|
Deadline *time.Time `json:"due_date"`
|
|
|
|
}
|
|
|
|
|
2016-11-10 09:44:00 +00:00
|
|
|
// CreatePullRequest create pull request with options
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOption) (*PullRequest, *Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2016-10-11 20:52:07 +01:00
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
return nil, nil, err
|
2016-10-11 20:52:07 +01:00
|
|
|
}
|
|
|
|
pr := new(PullRequest)
|
2020-09-14 03:37:09 +01:00
|
|
|
resp, err := c.getParsedResponse("POST",
|
|
|
|
fmt.Sprintf("/repos/%s/%s/pulls", owner, repo),
|
2016-10-11 20:52:07 +01:00
|
|
|
jsonHeader, bytes.NewReader(body), pr)
|
2020-09-14 03:37:09 +01:00
|
|
|
return pr, resp, err
|
2016-10-11 20:52:07 +01:00
|
|
|
}
|
|
|
|
|
2019-10-13 02:34:01 +01:00
|
|
|
// EditPullRequestOption options when modify pull request
|
|
|
|
type EditPullRequestOption struct {
|
|
|
|
Title string `json:"title"`
|
|
|
|
Body string `json:"body"`
|
2020-06-03 18:54:19 +01:00
|
|
|
Base string `json:"base"`
|
2019-10-13 02:34:01 +01:00
|
|
|
Assignee string `json:"assignee"`
|
|
|
|
Assignees []string `json:"assignees"`
|
|
|
|
Milestone int64 `json:"milestone"`
|
|
|
|
Labels []int64 `json:"labels"`
|
2020-02-04 07:58:46 +00:00
|
|
|
State *StateType `json:"state"`
|
2019-10-13 02:34:01 +01:00
|
|
|
Deadline *time.Time `json:"due_date"`
|
|
|
|
}
|
|
|
|
|
2020-06-09 11:47:55 +01:00
|
|
|
// Validate the EditPullRequestOption struct
|
|
|
|
func (opt EditPullRequestOption) Validate(c *Client) error {
|
|
|
|
if len(opt.Title) != 0 && len(strings.TrimSpace(opt.Title)) == 0 {
|
|
|
|
return fmt.Errorf("title is empty")
|
|
|
|
}
|
|
|
|
if len(opt.Base) != 0 {
|
2020-11-12 20:59:04 +00:00
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil {
|
2020-06-09 11:47:55 +01:00
|
|
|
return fmt.Errorf("can not change base gitea to old")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-11-10 09:44:00 +00:00
|
|
|
// EditPullRequest modify pull request with PR id and options
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRequestOption) (*PullRequest, *Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2020-06-09 11:47:55 +01:00
|
|
|
if err := opt.Validate(c); err != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
return nil, nil, err
|
2020-06-09 11:47:55 +01:00
|
|
|
}
|
2016-10-11 20:52:07 +01:00
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
return nil, nil, err
|
2016-10-11 20:52:07 +01:00
|
|
|
}
|
|
|
|
pr := new(PullRequest)
|
2020-09-14 03:37:09 +01:00
|
|
|
resp, err := c.getParsedResponse("PATCH",
|
|
|
|
fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index),
|
2016-10-11 20:52:07 +01:00
|
|
|
jsonHeader, bytes.NewReader(body), pr)
|
2020-09-14 03:37:09 +01:00
|
|
|
return pr, resp, err
|
2016-10-11 20:52:07 +01:00
|
|
|
}
|
|
|
|
|
2020-01-03 06:22:50 +00:00
|
|
|
// MergePullRequestOption options when merging a pull request
|
|
|
|
type MergePullRequestOption struct {
|
2021-11-12 12:57:44 +00:00
|
|
|
Style MergeStyle `json:"Do"`
|
|
|
|
MergeCommitID string `json:"MergeCommitID"`
|
|
|
|
Title string `json:"MergeTitleField"`
|
|
|
|
Message string `json:"MergeMessageField"`
|
|
|
|
DeleteBranchAfterMerge bool `json:"delete_branch_after_merge"`
|
|
|
|
ForceMerge bool `json:"force_merge"`
|
2020-01-03 06:22:50 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 16:31:31 +00:00
|
|
|
var version1_11_5, _ = version.NewVersion("1.11.5")
|
|
|
|
|
2020-06-09 11:47:55 +01:00
|
|
|
// Validate the MergePullRequestOption struct
|
|
|
|
func (opt MergePullRequestOption) Validate(c *Client) error {
|
2020-05-20 23:41:21 +01:00
|
|
|
if opt.Style == MergeStyleSquash {
|
2022-01-04 16:31:31 +00:00
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_5); err != nil {
|
2020-06-09 11:47:55 +01:00
|
|
|
return err
|
2020-05-20 14:01:06 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-09 11:47:55 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MergePullRequest merge a PR to repository by PR id
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) MergePullRequest(owner, repo string, index int64, opt MergePullRequestOption) (bool, *Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return false, nil, err
|
|
|
|
}
|
2020-06-09 11:47:55 +01:00
|
|
|
if err := opt.Validate(c); err != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
return false, nil, err
|
2020-06-09 11:47:55 +01:00
|
|
|
}
|
2020-01-03 06:22:50 +00:00
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
return false, nil, err
|
2020-04-23 13:51:36 +01:00
|
|
|
}
|
2020-09-14 03:37:09 +01:00
|
|
|
status, resp, err := c.getStatusCode("POST", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), jsonHeader, bytes.NewReader(body))
|
2020-04-23 13:51:36 +01:00
|
|
|
if err != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
return false, resp, err
|
2020-01-03 06:22:50 +00:00
|
|
|
}
|
2020-09-14 03:37:09 +01:00
|
|
|
return status == 200, resp, nil
|
2016-10-11 20:52:07 +01:00
|
|
|
}
|
|
|
|
|
2016-11-10 09:44:00 +00:00
|
|
|
// IsPullRequestMerged test if one PR is merged to one repository
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, *Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return false, nil, err
|
|
|
|
}
|
2020-09-14 03:37:09 +01:00
|
|
|
status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
|
2016-10-11 20:52:07 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
return false, resp, err
|
2016-10-11 20:52:07 +01:00
|
|
|
}
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
return status == 204, resp, nil
|
2016-08-14 11:32:53 +01:00
|
|
|
}
|
2020-09-04 20:21:05 +01:00
|
|
|
|
2022-01-13 17:30:39 +00:00
|
|
|
// PullRequestDiffOptions options for GET /repos/<owner>/<repo>/pulls/<idx>.[diff|patch]
|
|
|
|
type PullRequestDiffOptions struct {
|
|
|
|
// Include binary file changes when requesting a .diff
|
|
|
|
Binary bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryEncode converts the options to a query string
|
|
|
|
func (o PullRequestDiffOptions) QueryEncode() string {
|
|
|
|
query := make(url.Values)
|
|
|
|
query.Add("binary", fmt.Sprintf("%v", o.Binary))
|
|
|
|
return query.Encode()
|
|
|
|
}
|
|
|
|
|
|
|
|
type pullRequestDiffType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
pullRequestDiffTypeDiff pullRequestDiffType = "diff"
|
|
|
|
pullRequestDiffTypePatch pullRequestDiffType = "patch"
|
|
|
|
)
|
|
|
|
|
2020-09-07 04:17:54 +01:00
|
|
|
// getPullRequestDiffOrPatch gets the patch or diff file as bytes for a PR
|
2022-01-13 17:30:39 +00:00
|
|
|
func (c *Client) getPullRequestDiffOrPatch(owner, repo string, kind pullRequestDiffType, index int64, opts PullRequestDiffOptions) ([]byte, *Response, error) {
|
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
2021-03-21 20:20:32 +00:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
2020-11-12 20:59:04 +00:00
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_13_0); err != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
r, _, err2 := c.GetRepo(owner, repo)
|
2020-09-07 04:17:54 +01:00
|
|
|
if err2 != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
return nil, nil, err
|
2020-09-07 04:17:54 +01:00
|
|
|
}
|
|
|
|
if r.Private {
|
2020-09-14 03:37:09 +01:00
|
|
|
return nil, nil, err
|
2020-09-07 04:17:54 +01:00
|
|
|
}
|
2022-01-13 17:30:39 +00:00
|
|
|
url := fmt.Sprintf("/%s/%s/pulls/%d.%s?%s", owner, repo, index, kind, opts.QueryEncode())
|
|
|
|
return c.getWebResponse("GET", url, nil)
|
2020-09-07 04:17:54 +01:00
|
|
|
}
|
|
|
|
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d.%s", owner, repo, index, kind), nil, nil)
|
|
|
|
}
|
|
|
|
|
2022-01-13 17:30:39 +00:00
|
|
|
// GetPullRequestPatch gets the git patchset of a PR
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) GetPullRequestPatch(owner, repo string, index int64) ([]byte, *Response, error) {
|
2022-01-13 17:30:39 +00:00
|
|
|
return c.getPullRequestDiffOrPatch(owner, repo, pullRequestDiffTypePatch, index, PullRequestDiffOptions{})
|
2020-09-04 20:21:05 +01:00
|
|
|
}
|
|
|
|
|
2022-01-13 17:30:39 +00:00
|
|
|
// GetPullRequestDiff gets the diff of a PR. For Gitea >= 1.16, you must set includeBinary to get an applicable diff
|
|
|
|
func (c *Client) GetPullRequestDiff(owner, repo string, index int64, opts PullRequestDiffOptions) ([]byte, *Response, error) {
|
|
|
|
return c.getPullRequestDiffOrPatch(owner, repo, pullRequestDiffTypeDiff, index, opts)
|
2020-09-04 20:21:05 +01:00
|
|
|
}
|
2021-03-08 21:15:42 +00:00
|
|
|
|
2021-07-03 13:29:50 +01:00
|
|
|
// ListPullRequestCommitsOptions options for listing pull requests
|
|
|
|
type ListPullRequestCommitsOptions struct {
|
|
|
|
ListOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListPullRequestCommits list commits for a pull request
|
|
|
|
func (c *Client) ListPullRequestCommits(owner, repo string, index int64, opt ListPullRequestCommitsOptions) ([]*Commit, *Response, error) {
|
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/pulls/%d/commits", owner, repo, index))
|
|
|
|
opt.setDefaults()
|
|
|
|
commits := make([]*Commit, 0, opt.PageSize)
|
|
|
|
link.RawQuery = opt.getURLQuery().Encode()
|
|
|
|
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &commits)
|
|
|
|
return commits, resp, err
|
|
|
|
}
|
|
|
|
|
2021-03-08 21:15:42 +00:00
|
|
|
// fixPullHeadSha is a workaround for https://github.com/go-gitea/gitea/issues/12675
|
|
|
|
// When no head sha is available, this is because the branch got deleted in the base repo.
|
|
|
|
// pr.Head.Ref points in this case not to the head repo branch name, but the base repo ref,
|
|
|
|
// which stays available to resolve the commit sha. This is fixed for gitea >= 1.14.0
|
|
|
|
func fixPullHeadSha(client *Client, pr *PullRequest) error {
|
|
|
|
if pr.Base != nil && pr.Base.Repository != nil && pr.Base.Repository.Owner != nil &&
|
|
|
|
pr.Head != nil && pr.Head.Ref != "" && pr.Head.Sha == "" {
|
|
|
|
owner := pr.Base.Repository.Owner.UserName
|
|
|
|
repo := pr.Base.Repository.Name
|
|
|
|
refs, _, err := client.GetRepoRefs(owner, repo, pr.Head.Ref)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if len(refs) == 0 {
|
|
|
|
return fmt.Errorf("unable to resolve PR ref '%s'", pr.Head.Ref)
|
|
|
|
}
|
|
|
|
pr.Head.Sha = refs[0].Object.SHA
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|