1
2
3
4
5
6 package github
7
8 import (
9 "bytes"
10 "context"
11 "encoding/json"
12 "fmt"
13 )
14
15
16
17 type IssueImportService service
18
19
20
21
22 type IssueImportRequest struct {
23 IssueImport IssueImport `json:"issue"`
24 Comments []*Comment `json:"comments,omitempty"`
25 }
26
27
28 type IssueImport struct {
29 Title string `json:"title"`
30 Body string `json:"body"`
31 CreatedAt *Timestamp `json:"created_at,omitempty"`
32 ClosedAt *Timestamp `json:"closed_at,omitempty"`
33 UpdatedAt *Timestamp `json:"updated_at,omitempty"`
34 Assignee *string `json:"assignee,omitempty"`
35 Milestone *int `json:"milestone,omitempty"`
36 Closed *bool `json:"closed,omitempty"`
37 Labels []string `json:"labels,omitempty"`
38 }
39
40
41 type Comment struct {
42 CreatedAt *Timestamp `json:"created_at,omitempty"`
43 Body string `json:"body"`
44 }
45
46
47
48
49 type IssueImportResponse struct {
50 ID *int `json:"id,omitempty"`
51 Status *string `json:"status,omitempty"`
52 URL *string `json:"url,omitempty"`
53 ImportIssuesURL *string `json:"import_issues_url,omitempty"`
54 RepositoryURL *string `json:"repository_url,omitempty"`
55 CreatedAt *Timestamp `json:"created_at,omitempty"`
56 UpdatedAt *Timestamp `json:"updated_at,omitempty"`
57 Message *string `json:"message,omitempty"`
58 DocumentationURL *string `json:"documentation_url,omitempty"`
59 Errors []*IssueImportError `json:"errors,omitempty"`
60 }
61
62
63 type IssueImportError struct {
64 Location *string `json:"location,omitempty"`
65 Resource *string `json:"resource,omitempty"`
66 Field *string `json:"field,omitempty"`
67 Value *string `json:"value,omitempty"`
68 Code *string `json:"code,omitempty"`
69 }
70
71
72
73
74 func (s *IssueImportService) Create(ctx context.Context, owner, repo string, issue *IssueImportRequest) (*IssueImportResponse, *Response, error) {
75 u := fmt.Sprintf("repos/%v/%v/import/issues", owner, repo)
76 req, err := s.client.NewRequest("POST", u, issue)
77 if err != nil {
78 return nil, nil, err
79 }
80
81
82 req.Header.Set("Accept", mediaTypeIssueImportAPI)
83
84 i := new(IssueImportResponse)
85 resp, err := s.client.Do(ctx, req, i)
86 if err != nil {
87 aerr, ok := err.(*AcceptedError)
88 if ok {
89 if err := json.Unmarshal(aerr.Raw, i); err != nil {
90 return i, resp, err
91 }
92 return i, resp, err
93 }
94 return nil, resp, err
95 }
96
97 return i, resp, nil
98 }
99
100
101
102
103 func (s *IssueImportService) CheckStatus(ctx context.Context, owner, repo string, issueID int64) (*IssueImportResponse, *Response, error) {
104 u := fmt.Sprintf("repos/%v/%v/import/issues/%v", owner, repo, issueID)
105 req, err := s.client.NewRequest("GET", u, nil)
106 if err != nil {
107 return nil, nil, err
108 }
109
110
111 req.Header.Set("Accept", mediaTypeIssueImportAPI)
112
113 i := new(IssueImportResponse)
114 resp, err := s.client.Do(ctx, req, i)
115 if err != nil {
116 return nil, resp, err
117 }
118
119 return i, resp, nil
120 }
121
122
123
124
125 func (s *IssueImportService) CheckStatusSince(ctx context.Context, owner, repo string, since Timestamp) ([]*IssueImportResponse, *Response, error) {
126 u := fmt.Sprintf("repos/%v/%v/import/issues?since=%v", owner, repo, since.Format("2006-01-02"))
127 req, err := s.client.NewRequest("GET", u, nil)
128 if err != nil {
129 return nil, nil, err
130 }
131
132
133 req.Header.Set("Accept", mediaTypeIssueImportAPI)
134
135 var b bytes.Buffer
136 resp, err := s.client.Do(ctx, req, &b)
137 if err != nil {
138 return nil, resp, err
139 }
140
141 var i []*IssueImportResponse
142 err = json.Unmarshal(b.Bytes(), &i)
143 if err != nil {
144 return nil, resp, err
145 }
146
147 return i, resp, nil
148 }
149
View as plain text