1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "bytes"
21 "fmt"
22 "io"
23 "net/http"
24 "time"
25 )
26
27
28
29
30
31
32 type ProjectImportExportService struct {
33 client *Client
34 }
35
36
37
38
39
40 type ImportStatus struct {
41 ID int `json:"id"`
42 Description string `json:"description"`
43 Name string `json:"name"`
44 NameWithNamespace string `json:"name_with_namespace"`
45 Path string `json:"path"`
46 PathWithNamespace string `json:"path_with_namespace"`
47 CreateAt *time.Time `json:"create_at"`
48 ImportStatus string `json:"import_status"`
49 ImportType string `json:"import_type"`
50 CorrelationID string `json:"correlation_id"`
51 ImportError string `json:"import_error"`
52 }
53
54 func (s ImportStatus) String() string {
55 return Stringify(s)
56 }
57
58
59
60
61
62 type ExportStatus struct {
63 ID int `json:"id"`
64 Description string `json:"description"`
65 Name string `json:"name"`
66 NameWithNamespace string `json:"name_with_namespace"`
67 Path string `json:"path"`
68 PathWithNamespace string `json:"path_with_namespace"`
69 CreatedAt *time.Time `json:"created_at"`
70 ExportStatus string `json:"export_status"`
71 Message string `json:"message"`
72 Links struct {
73 APIURL string `json:"api_url"`
74 WebURL string `json:"web_url"`
75 } `json:"_links"`
76 }
77
78 func (s ExportStatus) String() string {
79 return Stringify(s)
80 }
81
82
83
84
85
86 type ScheduleExportOptions struct {
87 Description *string `url:"description,omitempty" json:"description,omitempty"`
88 Upload struct {
89 URL *string `url:"url,omitempty" json:"url,omitempty"`
90 HTTPMethod *string `url:"http_method,omitempty" json:"http_method,omitempty"`
91 } `url:"upload,omitempty" json:"upload,omitempty"`
92 }
93
94
95
96
97
98 func (s *ProjectImportExportService) ScheduleExport(pid interface{}, opt *ScheduleExportOptions, options ...RequestOptionFunc) (*Response, error) {
99 project, err := parseID(pid)
100 if err != nil {
101 return nil, err
102 }
103 u := fmt.Sprintf("projects/%s/export", PathEscape(project))
104
105 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
106 if err != nil {
107 return nil, err
108 }
109
110 return s.client.Do(req, nil)
111 }
112
113
114
115
116
117 func (s *ProjectImportExportService) ExportStatus(pid interface{}, options ...RequestOptionFunc) (*ExportStatus, *Response, error) {
118 project, err := parseID(pid)
119 if err != nil {
120 return nil, nil, err
121 }
122 u := fmt.Sprintf("projects/%s/export", PathEscape(project))
123
124 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
125 if err != nil {
126 return nil, nil, err
127 }
128
129 es := new(ExportStatus)
130 resp, err := s.client.Do(req, es)
131 if err != nil {
132 return nil, resp, err
133 }
134
135 return es, resp, nil
136 }
137
138
139
140
141
142 func (s *ProjectImportExportService) ExportDownload(pid interface{}, options ...RequestOptionFunc) ([]byte, *Response, error) {
143 project, err := parseID(pid)
144 if err != nil {
145 return nil, nil, err
146 }
147 u := fmt.Sprintf("projects/%s/export/download", PathEscape(project))
148
149 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
150 if err != nil {
151 return nil, nil, err
152 }
153
154 var b bytes.Buffer
155 resp, err := s.client.Do(req, &b)
156 if err != nil {
157 return nil, resp, err
158 }
159
160 return b.Bytes(), resp, err
161 }
162
163
164
165
166
167 type ImportFileOptions struct {
168 Namespace *string `url:"namespace,omitempty" json:"namespace,omitempty"`
169 Name *string `url:"name,omitempty" json:"name,omitempty"`
170 Path *string `url:"path,omitempty" json:"path,omitempty"`
171 Overwrite *bool `url:"overwrite,omitempty" json:"overwrite,omitempty"`
172 OverrideParams *CreateProjectOptions `url:"override_params,omitempty" json:"override_params,omitempty"`
173 }
174
175
176
177
178
179 func (s *ProjectImportExportService) ImportFromFile(archive io.Reader, opt *ImportFileOptions, options ...RequestOptionFunc) (*ImportStatus, *Response, error) {
180 req, err := s.client.UploadRequest(
181 http.MethodPost,
182 "projects/import",
183 archive,
184 "archive.tar.gz",
185 UploadFile,
186 opt,
187 options,
188 )
189 if err != nil {
190 return nil, nil, err
191 }
192
193 is := new(ImportStatus)
194 resp, err := s.client.Do(req, is)
195 if err != nil {
196 return nil, resp, err
197 }
198
199 return is, resp, nil
200 }
201
202
203
204
205
206 func (s *ProjectImportExportService) ImportStatus(pid interface{}, options ...RequestOptionFunc) (*ImportStatus, *Response, error) {
207 project, err := parseID(pid)
208 if err != nil {
209 return nil, nil, err
210 }
211 u := fmt.Sprintf("projects/%s/import", PathEscape(project))
212
213 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
214 if err != nil {
215 return nil, nil, err
216 }
217
218 is := new(ImportStatus)
219 resp, err := s.client.Do(req, is)
220 if err != nil {
221 return nil, resp, err
222 }
223
224 return is, resp, nil
225 }
226
View as plain text