github.com/crosbymichael/octokat@v0.0.0-20160826194511-076a32289ed5/pull_requests.go (about)

     1  package octokat
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  )
     7  
     8  type PullRequest struct {
     9  	URL               string     `json:"url,omitempty"`
    10  	ID                int        `json:"id,omitempty"`
    11  	HTMLURL           string     `json:"html_url,omitempty"`
    12  	DiffURL           string     `json:"diff_url,omitempty"`
    13  	PatchURL          string     `json:"patch_url,omitempty"`
    14  	IssueURL          string     `json:"issue_url,omitempty"`
    15  	Number            int        `json:"number,omitempty"`
    16  	State             string     `json:"state,omitempty"`
    17  	Title             string     `json:"title,omitempty"`
    18  	User              User       `json:"user,omitempty"`
    19  	Body              string     `json:"body,omitempty"`
    20  	CreatedAt         time.Time  `json:"created_at,omitempty"`
    21  	UpdatedAt         time.Time  `json:"updated_at,omitempty"`
    22  	ClosedAt          *time.Time `json:"closed_at,omitempty"`
    23  	MergedAt          *time.Time `json:"merged_at,omitempty"`
    24  	MergeCommitSha    string     `json:"merge_commit_sha,omitempty"`
    25  	Assignee          *User      `json:"assignee,omitempty"`
    26  	CommitsURL        string     `json:"commits_url,omitempty"`
    27  	ReviewCommentsURL string     `json:"review_comments_url,omitempty"`
    28  	ReviewCommentURL  string     `json:"review_comment_url,omitempty"`
    29  	CommentsURL       string     `json:"comments_url,omitempty"`
    30  	Head              Commit     `json:"head,omitempty"`
    31  	Base              Commit     `json:"base,omitempty"`
    32  	Merged            bool       `json:"merged,omitempty"`
    33  	MergedBy          User       `json:"merged_by,omitempty"`
    34  	Comments          int        `json:"comments,omitempty"`
    35  	ReviewComments    int        `json:"review_comments,omitempty"`
    36  	Commits           int        `json:"commits,omitempty"`
    37  	Additions         int        `json:"additions,omitempty"`
    38  	Deletions         int        `json:"deletions,omitempty"`
    39  	ChangedFiles      int        `json:"changed_files,omitempty"`
    40  	Mergeable         *bool      `json:"mergeable,omitempty"`
    41  	CommentsBody      []Comment  `json:"-"`
    42  }
    43  
    44  type PullRequestFile struct {
    45  	FileName    string `json:"filename,omitempty"`
    46  	Sha         string `json:"sha,omitempty"`
    47  	Status      string `json:"status,omitempty"`
    48  	Additions   int    `json:"additions,omitempty"`
    49  	Deletions   int    `json:"deletions,omitempty"`
    50  	Changes     int    `json:"changes,omitempty"`
    51  	BlobUrl     string `json:"blob_url,omitempty"`
    52  	RawUrl      string `json:"raw_url,omitempty"`
    53  	ContentsUrl string `json:"contents_url,omitempty"`
    54  	Patch       string `json:"patch,omitempty"`
    55  }
    56  
    57  // Get a pull request
    58  //
    59  // See http://developer.github.com/v3/pulls/#get-a-single-pull-request
    60  func (c *Client) PullRequest(repo Repo, number string, options *Options) (pr *PullRequest, err error) {
    61  	path := fmt.Sprintf("repos/%s/pulls/%s", repo, number)
    62  	err = c.jsonGet(path, options, &pr)
    63  	return
    64  }
    65  
    66  // Get all pull requests
    67  //
    68  // See http://developer.github.com/v3/pulls/#list-pull-requests
    69  func (c *Client) PullRequests(repo Repo, options *Options) (prs []*PullRequest, err error) {
    70  	path := fmt.Sprintf("repos/%s/pulls", repo)
    71  	err = c.jsonGet(path, options, &prs)
    72  	return
    73  }
    74  
    75  // Get all pull request files
    76  //
    77  // See http://developer.github.com/v3/pulls/#list-pull-requests-files
    78  func (c *Client) PullRequestFiles(repo Repo, number string, options *Options) (prfs []*PullRequestFile, err error) {
    79  	path := fmt.Sprintf("repos/%s/pulls/%s/files", repo, number)
    80  	err = c.jsonGet(path, options, &prfs)
    81  	return
    82  }
    83  
    84  type PullRequestParams struct {
    85  	Base  string `json:"base,omitempty"`
    86  	Head  string `json:"head,omitempty"`
    87  	Title string `json:"title,omitempty"`
    88  	Body  string `json:"body,omitempty"`
    89  }
    90  
    91  type PullRequestForIssueParams struct {
    92  	Base  string `json:"base,omitempty"`
    93  	Head  string `json:"head,omitempty"`
    94  	Issue string `json:"issue,omitempty"`
    95  }
    96  
    97  // Create a pull request
    98  //
    99  // See http://developer.github.com/v3/pulls/#create-a-pull-request
   100  // See http://developer.github.com/v3/pulls/#alternative-input
   101  func (c *Client) CreatePullRequest(repo Repo, options *Options) (pr *PullRequest, err error) {
   102  	path := fmt.Sprintf("repos/%s/pulls", repo)
   103  	err = c.jsonPost(path, options, &pr)
   104  	return
   105  }