123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- package github
- import (
- "context"
- "fmt"
- "strings"
- "time"
- )
- type IssuesService service
- type Issue struct {
- ID *int64 `json:"id,omitempty"`
- Number *int `json:"number,omitempty"`
- State *string `json:"state,omitempty"`
- Locked *bool `json:"locked,omitempty"`
- Title *string `json:"title,omitempty"`
- Body *string `json:"body,omitempty"`
- User *User `json:"user,omitempty"`
- Labels []Label `json:"labels,omitempty"`
- Assignee *User `json:"assignee,omitempty"`
- Comments *int `json:"comments,omitempty"`
- ClosedAt *time.Time `json:"closed_at,omitempty"`
- CreatedAt *time.Time `json:"created_at,omitempty"`
- UpdatedAt *time.Time `json:"updated_at,omitempty"`
- ClosedBy *User `json:"closed_by,omitempty"`
- URL *string `json:"url,omitempty"`
- HTMLURL *string `json:"html_url,omitempty"`
- CommentsURL *string `json:"comments_url,omitempty"`
- EventsURL *string `json:"events_url,omitempty"`
- LabelsURL *string `json:"labels_url,omitempty"`
- RepositoryURL *string `json:"repository_url,omitempty"`
- Milestone *Milestone `json:"milestone,omitempty"`
- PullRequestLinks *PullRequestLinks `json:"pull_request,omitempty"`
- Repository *Repository `json:"repository,omitempty"`
- Reactions *Reactions `json:"reactions,omitempty"`
- Assignees []*User `json:"assignees,omitempty"`
- NodeID *string `json:"node_id,omitempty"`
-
-
- TextMatches []TextMatch `json:"text_matches,omitempty"`
- }
- func (i Issue) String() string {
- return Stringify(i)
- }
- func (i Issue) IsPullRequest() bool {
- return i.PullRequestLinks != nil
- }
- type IssueRequest struct {
- Title *string `json:"title,omitempty"`
- Body *string `json:"body,omitempty"`
- Labels *[]string `json:"labels,omitempty"`
- Assignee *string `json:"assignee,omitempty"`
- State *string `json:"state,omitempty"`
- Milestone *int `json:"milestone,omitempty"`
- Assignees *[]string `json:"assignees,omitempty"`
- }
- type IssueListOptions struct {
-
-
- Filter string `url:"filter,omitempty"`
-
-
- State string `url:"state,omitempty"`
-
- Labels []string `url:"labels,comma,omitempty"`
-
-
- Sort string `url:"sort,omitempty"`
-
-
- Direction string `url:"direction,omitempty"`
-
- Since time.Time `url:"since,omitempty"`
- ListOptions
- }
- type PullRequestLinks struct {
- URL *string `json:"url,omitempty"`
- HTMLURL *string `json:"html_url,omitempty"`
- DiffURL *string `json:"diff_url,omitempty"`
- PatchURL *string `json:"patch_url,omitempty"`
- }
- func (s *IssuesService) List(ctx context.Context, all bool, opt *IssueListOptions) ([]*Issue, *Response, error) {
- var u string
- if all {
- u = "issues"
- } else {
- u = "user/issues"
- }
- return s.listIssues(ctx, u, opt)
- }
- func (s *IssuesService) ListByOrg(ctx context.Context, org string, opt *IssueListOptions) ([]*Issue, *Response, error) {
- u := fmt.Sprintf("orgs/%v/issues", org)
- return s.listIssues(ctx, u, opt)
- }
- func (s *IssuesService) listIssues(ctx context.Context, u string, opt *IssueListOptions) ([]*Issue, *Response, error) {
- u, err := addOptions(u, opt)
- if err != nil {
- return nil, nil, err
- }
- req, err := s.client.NewRequest("GET", u, nil)
- if err != nil {
- return nil, nil, err
- }
-
- acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeGraphQLNodeIDPreview, mediaTypeLabelDescriptionSearchPreview}
- req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
- var issues []*Issue
- resp, err := s.client.Do(ctx, req, &issues)
- if err != nil {
- return nil, resp, err
- }
- return issues, resp, nil
- }
- type IssueListByRepoOptions struct {
-
-
-
- Milestone string `url:"milestone,omitempty"`
-
-
- State string `url:"state,omitempty"`
-
-
-
- Assignee string `url:"assignee,omitempty"`
-
- Creator string `url:"creator,omitempty"`
-
- Mentioned string `url:"mentioned,omitempty"`
-
- Labels []string `url:"labels,omitempty,comma"`
-
-
- Sort string `url:"sort,omitempty"`
-
-
- Direction string `url:"direction,omitempty"`
-
- Since time.Time `url:"since,omitempty"`
- ListOptions
- }
- func (s *IssuesService) ListByRepo(ctx context.Context, owner string, repo string, opt *IssueListByRepoOptions) ([]*Issue, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues", owner, repo)
- u, err := addOptions(u, opt)
- if err != nil {
- return nil, nil, err
- }
- req, err := s.client.NewRequest("GET", u, nil)
- if err != nil {
- return nil, nil, err
- }
-
- acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeGraphQLNodeIDPreview, mediaTypeLabelDescriptionSearchPreview}
- req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
- var issues []*Issue
- resp, err := s.client.Do(ctx, req, &issues)
- if err != nil {
- return nil, resp, err
- }
- return issues, resp, nil
- }
- func (s *IssuesService) Get(ctx context.Context, owner string, repo string, number int) (*Issue, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
- req, err := s.client.NewRequest("GET", u, nil)
- if err != nil {
- return nil, nil, err
- }
-
- acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeGraphQLNodeIDPreview, mediaTypeLabelDescriptionSearchPreview}
- req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
- issue := new(Issue)
- resp, err := s.client.Do(ctx, req, issue)
- if err != nil {
- return nil, resp, err
- }
- return issue, resp, nil
- }
- func (s *IssuesService) Create(ctx context.Context, owner string, repo string, issue *IssueRequest) (*Issue, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues", owner, repo)
- req, err := s.client.NewRequest("POST", u, issue)
- if err != nil {
- return nil, nil, err
- }
-
- acceptHeaders := []string{mediaTypeGraphQLNodeIDPreview, mediaTypeLabelDescriptionSearchPreview}
- req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
- i := new(Issue)
- resp, err := s.client.Do(ctx, req, i)
- if err != nil {
- return nil, resp, err
- }
- return i, resp, nil
- }
- func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, number int, issue *IssueRequest) (*Issue, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
- req, err := s.client.NewRequest("PATCH", u, issue)
- if err != nil {
- return nil, nil, err
- }
-
- acceptHeaders := []string{mediaTypeGraphQLNodeIDPreview, mediaTypeLabelDescriptionSearchPreview}
- req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
- i := new(Issue)
- resp, err := s.client.Do(ctx, req, i)
- if err != nil {
- return nil, resp, err
- }
- return i, resp, nil
- }
- func (s *IssuesService) Lock(ctx context.Context, owner string, repo string, number int) (*Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
- req, err := s.client.NewRequest("PUT", u, nil)
- if err != nil {
- return nil, err
- }
- return s.client.Do(ctx, req, nil)
- }
- func (s *IssuesService) Unlock(ctx context.Context, owner string, repo string, number int) (*Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
- req, err := s.client.NewRequest("DELETE", u, nil)
- if err != nil {
- return nil, err
- }
- return s.client.Do(ctx, req, nil)
- }
|