forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.go
266 lines (236 loc) · 10.2 KB
/
import.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//
// Copyright 2021, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"net/http"
)
// ImportService handles communication with the import
// related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html
type ImportService struct {
client *Client
}
// GitHubImport represents the response from an import from GitHub.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-repository-from-github
type GitHubImport struct {
ID int `json:"id"`
Name string `json:"name"`
FullPath string `json:"full_path"`
FullName string `json:"full_name"`
RefsUrl string `json:"refs_url"`
ImportSource string `json:"import_source"`
ImportStatus string `json:"import_status"`
HumanImportStatusName string `json:"human_import_status_name"`
ProviderLink string `json:"provider_link"`
RelationType string `json:"relation_type"`
ImportWarning string `json:"import_warning"`
}
func (s GitHubImport) String() string {
return Stringify(s)
}
// ImportRepositoryFromGitHubOptions represents the available
// ImportRepositoryFromGitHub() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-repository-from-github
type ImportRepositoryFromGitHubOptions struct {
PersonalAccessToken *string `url:"personal_access_token,omitempty" json:"personal_access_token,omitempty"`
RepoID *int `url:"repo_id,omitempty" json:"repo_id,omitempty"`
NewName *string `url:"new_name,omitempty" json:"new_name,omitempty"`
TargetNamespace *string `url:"target_namespace,omitempty" json:"target_namespace,omitempty"`
GitHubHostname *string `url:"github_hostname,omitempty" json:"github_hostname,omitempty"`
OptionalStages struct {
SingleEndpointNotesImport *bool `url:"single_endpoint_notes_import,omitempty" json:"single_endpoint_notes_import,omitempty"`
AttachmentsImport *bool `url:"attachments_import,omitempty" json:"attachments_import,omitempty"`
CollaboratorsImport *bool `url:"collaborators_import,omitempty" json:"collaborators_import,omitempty"`
} `url:"optional_stages,omitempty" json:"optional_stages,omitempty"`
TimeoutStrategy *string `url:"timeout_strategy,omitempty" json:"timeout_strategy,omitempty"`
}
// Import a repository from GitHub.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-repository-from-github
func (s *ImportService) ImportRepositoryFromGitHub(opt *ImportRepositoryFromGitHubOptions, options ...RequestOptionFunc) (*GitHubImport, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "import/github", opt, options)
if err != nil {
return nil, nil, err
}
gi := new(GitHubImport)
resp, err := s.client.Do(req, gi)
if err != nil {
return nil, resp, err
}
return gi, resp, nil
}
// CancelledGitHubImport represents the response when canceling
// an import from GitHub.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#cancel-github-project-import
type CancelledGitHubImport struct {
ID int `json:"id"`
Name string `json:"name"`
FullPath string `json:"full_path"`
FullName string `json:"full_name"`
ImportSource string `json:"import_source"`
ImportStatus string `json:"import_status"`
HumanImportStatusName string `json:"human_import_status_name"`
ProviderLink string `json:"provider_link"`
}
func (s CancelledGitHubImport) String() string {
return Stringify(s)
}
// CancelGitHubProjectImportOptions represents the available
// CancelGitHubProjectImport() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#cancel-github-project-import
type CancelGitHubProjectImportOptions struct {
ProjectID *int `url:"project_id,omitempty" json:"project_id,omitempty"`
}
// Cancel an import of a repository from GitHub.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#cancel-github-project-import
func (s *ImportService) CancelGitHubProjectImport(opt *CancelGitHubProjectImportOptions, options ...RequestOptionFunc) (*CancelledGitHubImport, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "import/github/cancel", opt, options)
if err != nil {
return nil, nil, err
}
cgi := new(CancelledGitHubImport)
resp, err := s.client.Do(req, cgi)
if err != nil {
return nil, resp, err
}
return cgi, resp, nil
}
// ImportGitHubGistsIntoGitLabSnippetsOptions represents the available
// ImportGitHubGistsIntoGitLabSnippets() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-github-gists-into-gitlab-snippets
type ImportGitHubGistsIntoGitLabSnippetsOptions struct {
PersonalAccessToken *string `url:"personal_access_token,omitempty" json:"personal_access_token,omitempty"`
}
// Import personal GitHub Gists into personal GitLab Snippets.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-github-gists-into-gitlab-snippets
func (s *ImportService) ImportGitHubGistsIntoGitLabSnippets(opt *ImportGitHubGistsIntoGitLabSnippetsOptions, options ...RequestOptionFunc) (*Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "import/github/gists", opt, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// BitbucketServerImport represents the response from an import from Bitbucket
// Server.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-repository-from-bitbucket-server
type BitbucketServerImport struct {
ID int `json:"id"`
Name string `json:"name"`
FullPath string `json:"full_path"`
FullName string `json:"full_name"`
RefsUrl string `json:"refs_url"`
}
func (s BitbucketServerImport) String() string {
return Stringify(s)
}
// ImportRepositoryFromBitbucketServerOptions represents the available ImportRepositoryFromBitbucketServer() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-repository-from-bitbucket-server
type ImportRepositoryFromBitbucketServerOptions struct {
BitbucketServerUrl *string `url:"bitbucket_server_url,omitempty" json:"bitbucket_server_url,omitempty"`
BitbucketServerUsername *string `url:"bitbucket_server_username,omitempty" json:"bitbucket_server_username,omitempty"`
PersonalAccessToken *string `url:"personal_access_token,omitempty" json:"personal_access_token,omitempty"`
BitbucketServerProject *string `url:"bitbucket_server_project,omitempty" json:"bitbucket_server_project,omitempty"`
BitbucketServerRepo *string `url:"bitbucket_server_repo,omitempty" json:"bitbucket_server_repo,omitempty"`
NewName *string `url:"new_name,omitempty" json:"new_name,omitempty"`
NewNamespace *string `url:"new_namespace,omitempty" json:"new_namespace,omitempty"`
TimeoutStrategy *string `url:"timeout_strategy,omitempty" json:"timeout_strategy,omitempty"`
}
// Import a repository from Bitbucket Server.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-repository-from-bitbucket-server
func (s *ImportService) ImportRepositoryFromBitbucketServer(opt *ImportRepositoryFromBitbucketServerOptions, options ...RequestOptionFunc) (*BitbucketServerImport, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "import/bitbucket_server", opt, options)
if err != nil {
return nil, nil, err
}
bsi := new(BitbucketServerImport)
resp, err := s.client.Do(req, bsi)
if err != nil {
return nil, resp, err
}
return bsi, resp, nil
}
// BitbucketCloudImport represents the response from an import from Bitbucket
// Cloud.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-repository-from-bitbucket-cloud
type BitbucketCloudImport struct {
ID int `json:"id"`
Name string `json:"name"`
FullPath string `json:"full_path"`
FullName string `json:"full_name"`
RefsUrl string `json:"refs_url"`
ImportSource string `json:"import_source"`
ImportStatus string `json:"import_status"`
HumanImportStatusName string `json:"human_import_status_name"`
ProviderLink string `json:"provider_link"`
RelationType string `json:"relation_type"`
ImportWarning string `json:"import_warning"`
}
func (s BitbucketCloudImport) String() string {
return Stringify(s)
}
// ImportRepositoryFromBitbucketCloudOptions represents the available
// ImportRepositoryFromBitbucketCloud() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-repository-from-bitbucket-cloud
type ImportRepositoryFromBitbucketCloudOptions struct {
BitbucketUsername *string `url:"bitbucket_username,omitempty" json:"bitbucket_username,omitempty"`
BitbucketAppPassword *string `url:"bitbucket_app_password,omitempty" json:"bitbucket_app_password,omitempty"`
RepoPath *string `url:"repo_path,omitempty" json:"repo_path,omitempty"`
TargetNamespace *string `url:"target_namespace,omitempty" json:"target_namespace,omitempty"`
NewName *string `url:"new_name,omitempty" json:"new_name,omitempty"`
}
// Import a repository from Bitbucket Cloud.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/import.html#import-repository-from-bitbucket-cloud
func (s *ImportService) ImportRepositoryFromBitbucketCloud(opt *ImportRepositoryFromBitbucketCloudOptions, options ...RequestOptionFunc) (*BitbucketCloudImport, *Response, error) {
req, err := s.client.NewRequest(http.MethodPost, "import/bitbucket", opt, options)
if err != nil {
return nil, nil, err
}
bci := new(BitbucketCloudImport)
resp, err := s.client.Do(req, bci)
if err != nil {
return nil, resp, err
}
return bci, resp, nil
}