mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-03 20:36:07 +01:00 
			
		
		
		
	Update gitea/sdk vendor
This commit is contained in:
		
							
								
								
									
										113
									
								
								vendor/code.gitea.io/sdk/gitea/pull.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										113
									
								
								vendor/code.gitea.io/sdk/gitea/pull.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -5,12 +5,14 @@
 | 
			
		||||
package gitea
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// PullRequest represents a pull reqesut API object.
 | 
			
		||||
// PullRequest represents a pull request API object.
 | 
			
		||||
type PullRequest struct {
 | 
			
		||||
	// Copied from issue.go
 | 
			
		||||
	ID        int64      `json:"id"`
 | 
			
		||||
	Index     int64      `json:"number"`
 | 
			
		||||
	Poster    *User      `json:"user"`
 | 
			
		||||
@@ -22,16 +24,109 @@ type PullRequest struct {
 | 
			
		||||
	State     StateType  `json:"state"`
 | 
			
		||||
	Comments  int        `json:"comments"`
 | 
			
		||||
 | 
			
		||||
	HeadBranch string      `json:"head_branch"`
 | 
			
		||||
	HeadRepo   *Repository `json:"head_repo"`
 | 
			
		||||
	BaseBranch string      `json:"base_branch"`
 | 
			
		||||
	BaseRepo   *Repository `json:"base_repo"`
 | 
			
		||||
	HTMLURL  string `json:"html_url"`
 | 
			
		||||
	DiffURL  string `json:"diff_url"`
 | 
			
		||||
	PatchURL string `json:"patch_url"`
 | 
			
		||||
 | 
			
		||||
	HTMLURL string `json:"html_url"`
 | 
			
		||||
 | 
			
		||||
	Mergeable      *bool      `json:"mergeable"`
 | 
			
		||||
	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"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PRBranchInfo base branch info when send a PR
 | 
			
		||||
type PRBranchInfo struct {
 | 
			
		||||
	Name       string      `json:"label"`
 | 
			
		||||
	Ref        string      `json:"ref"`
 | 
			
		||||
	Sha        string      `json:"sha"`
 | 
			
		||||
	RepoID     int64       `json:"repo_id"`
 | 
			
		||||
	Repository *Repository `json:"repo"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListPullRequestsOptions options when list PRs
 | 
			
		||||
type ListPullRequestsOptions struct {
 | 
			
		||||
	Page  int    `json:"page"`
 | 
			
		||||
	State string `json:"state"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListRepoPullRequests list PRs of one repository
 | 
			
		||||
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, error) {
 | 
			
		||||
	body, err := json.Marshal(&opt)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	prs := make([]*PullRequest, 0, 10)
 | 
			
		||||
	return prs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls", owner, repo), jsonHeader, bytes.NewReader(body), &prs)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetPullRequest get information of one PR
 | 
			
		||||
func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest, error) {
 | 
			
		||||
	pr := new(PullRequest)
 | 
			
		||||
	return pr, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index), nil, nil, pr)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CreatePullRequestOption options when creating a pull request
 | 
			
		||||
type CreatePullRequestOption struct {
 | 
			
		||||
	Head      string  `json:"head" binding:"Required"`
 | 
			
		||||
	Base      string  `json:"base" binding:"Required"`
 | 
			
		||||
	Title     string  `json:"title" binding:"Required"`
 | 
			
		||||
	Body      string  `json:"body"`
 | 
			
		||||
	Assignee  string  `json:"assignee"`
 | 
			
		||||
	Milestone int64   `json:"milestone"`
 | 
			
		||||
	Labels    []int64 `json:"labels"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CreatePullRequest create pull request with options
 | 
			
		||||
func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOption) (*PullRequest, error) {
 | 
			
		||||
	body, err := json.Marshal(&opt)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	pr := new(PullRequest)
 | 
			
		||||
	return pr, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls", owner, repo),
 | 
			
		||||
		jsonHeader, bytes.NewReader(body), pr)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EditPullRequestOption options when modify pull request
 | 
			
		||||
type EditPullRequestOption struct {
 | 
			
		||||
	Title     string  `json:"title"`
 | 
			
		||||
	Body      string  `json:"body"`
 | 
			
		||||
	Assignee  string  `json:"assignee"`
 | 
			
		||||
	Milestone int64   `json:"milestone"`
 | 
			
		||||
	Labels    []int64 `json:"labels"`
 | 
			
		||||
	State     *string `json:"state"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EditPullRequest modify pull request with PR id and options
 | 
			
		||||
func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRequestOption) (*PullRequest, error) {
 | 
			
		||||
	body, err := json.Marshal(&opt)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	pr := new(PullRequest)
 | 
			
		||||
	return pr, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
 | 
			
		||||
		jsonHeader, bytes.NewReader(body), pr)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// MergePullRequest merge a PR to repository by PR id
 | 
			
		||||
func (c *Client) MergePullRequest(owner, repo string, index int64) error {
 | 
			
		||||
	_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsPullRequestMerged test if one PR is merged to one repository
 | 
			
		||||
func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, error) {
 | 
			
		||||
	statusCode, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return false, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return statusCode == 204, nil
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user