Skip to content

Commit 5847070

Browse files
authored
Merge pull request xanzy#621 from alex-berger/feature/project-import-export
Project Import/Export API
2 parents 39fbdb2 + a37b347 commit 5847070

File tree

5 files changed

+218
-17
lines changed

5 files changed

+218
-17
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# Folders
77
_obj
88
_test
9-
.idea
109

1110
# Architecture specific extensions/prefixes
1211
*.[568vq]
@@ -23,3 +22,7 @@ _testmain.go
2322
*.exe
2423
*.test
2524
*.prof
25+
26+
# IDE specific files and folders
27+
.idea
28+
*.iml

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ to add new and/or missing endpoints. Currently the following services are suppor
2424
- [ ] Epic Issues
2525
- [ ] Epics
2626
- [ ] Geo Nodes
27-
- [ ] Project import/export
2827
- [x] Award Emojis
2928
- [x] Branches
3029
- [x] Broadcast Messages
@@ -35,14 +34,14 @@ to add new and/or missing endpoints. Currently the following services are suppor
3534
- [x] Deployments
3635
- [x] Environments
3736
- [x] Events
38-
- [x] Feature flags
39-
- [x] GitLab CI Config templates
40-
- [x] Gitignores templates
37+
- [x] Feature Flags
38+
- [x] GitLab CI Config Templates
39+
- [x] Gitignores Templates
4140
- [x] Group Access Requests
4241
- [x] Group Issue Boards
4342
- [x] Group Members
4443
- [x] Group Milestones
45-
- [x] Group-level Variables
44+
- [x] Group-Level Variables
4645
- [x] Groups
4746
- [x] Issue Boards
4847
- [x] Issues
@@ -54,19 +53,20 @@ to add new and/or missing endpoints. Currently the following services are suppor
5453
- [x] Merge Requests
5554
- [x] Namespaces
5655
- [x] Notes (comments)
57-
- [x] Notification settings
58-
- [x] Open source license templates
56+
- [x] Notification Settings
57+
- [x] Open Source License Templates
5958
- [x] Pages Domains
6059
- [x] Pipeline Schedules
6160
- [x] Pipeline Triggers
6261
- [x] Pipelines
6362
- [x] Project Access Requests
63+
- [x] Project Badges
6464
- [x] Project Clusters
65+
- [x] Project Import/export
6566
- [x] Project Members
6667
- [x] Project Milestones
6768
- [x] Project Snippets
68-
- [x] Project badges
69-
- [x] Project-level Variables
69+
- [x] Project-Level Variables
7070
- [x] Projects (including setting Webhooks)
7171
- [x] Protected Branches
7272
- [x] Protected Tags
@@ -76,12 +76,12 @@ to add new and/or missing endpoints. Currently the following services are suppor
7676
- [x] Search
7777
- [x] Services
7878
- [x] Settings
79-
- [x] Sidekiq metrics
79+
- [x] Sidekiq Metrics
8080
- [x] System Hooks
8181
- [x] Tags
8282
- [x] Todos
8383
- [x] Users
84-
- [x] Validate CI configuration
84+
- [x] Validate CI Configuration
8585
- [x] Version
8686
- [x] Wikis
8787

gitlab.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ type Client struct {
330330
Pipelines *PipelinesService
331331
ProjectBadges *ProjectBadgesService
332332
ProjectCluster *ProjectClustersService
333+
ProjectImportExport *ProjectImportExportService
333334
ProjectMembers *ProjectMembersService
334335
ProjectSnippets *ProjectSnippetsService
335336
ProjectVariables *ProjectVariablesService
@@ -478,6 +479,7 @@ func newClient(httpClient *http.Client) *Client {
478479
c.Pipelines = &PipelinesService{client: c}
479480
c.ProjectBadges = &ProjectBadgesService{client: c}
480481
c.ProjectCluster = &ProjectClustersService{client: c}
482+
c.ProjectImportExport = &ProjectImportExportService{client: c}
481483
c.ProjectMembers = &ProjectMembersService{client: c}
482484
c.ProjectSnippets = &ProjectSnippetsService{client: c}
483485
c.ProjectVariables = &ProjectVariablesService{client: c}

project_import_export.go

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
package gitlab
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"time"
7+
)
8+
9+
// ProjectImportExportService handles communication with the project
10+
// import/export related methods of the GitLab API.
11+
//
12+
// GitLab API docs:
13+
// https://docs.gitlab.com/ce/user/project/settings/import_export.html
14+
type ProjectImportExportService struct {
15+
client *Client
16+
}
17+
18+
// ImportStatus represents a project import status.
19+
//
20+
// GitLab API docs:
21+
// https://docs.gitlab.com/ce/api/project_import_export.html#import-status
22+
type ImportStatus struct {
23+
ID int `json:"id"`
24+
Description string `json:"description"`
25+
Name string `json:"name"`
26+
NameWithNamespace string `json:"name_with_namespace"`
27+
Path string `json:"path"`
28+
PathWithNamespace string `json:"path_with_namespace"`
29+
CreateAt *time.Time `json:"create_at"`
30+
ImportStatus string `json:"import_status"`
31+
}
32+
33+
func (s ImportStatus) String() string {
34+
return Stringify(s)
35+
}
36+
37+
// ExportStatus represents a project export status.
38+
//
39+
// GitLab API docs:
40+
// https://docs.gitlab.com/ce/api/project_import_export.html#export-status
41+
type ExportStatus struct {
42+
ID int `json:"id"`
43+
Description string `json:"description"`
44+
Name string `json:"name"`
45+
NameWithNamespace string `json:"name_with_namespace"`
46+
Path string `json:"path"`
47+
PathWithNamespace string `json:"path_with_namespace"`
48+
CreatedAt *time.Time `json:"created_at"`
49+
ExportStatus string `json:"export_status"`
50+
Message string `json:"message"`
51+
Links struct {
52+
APIURL string `json:"api_url"`
53+
WebURL string `json:"web_url"`
54+
} `json:"_links"`
55+
}
56+
57+
func (s ExportStatus) String() string {
58+
return Stringify(s)
59+
}
60+
61+
// ScheduleExportOptions represents the available ScheduleExport() options.
62+
//
63+
// GitLab API docs:
64+
// https://docs.gitlab.com/ce/api/project_import_export.html#schedule-an-export
65+
type ScheduleExportOptions struct {
66+
Description *string `url:"description,omitempty" json:"description,omitempty"`
67+
Upload struct {
68+
URL *string `url:"url,omitempty" json:"url,omitempty"`
69+
HTTPMethod *string `url:"http_method,omitempty" json:"http_method,omitempty"`
70+
} `url:"upload,omitempty" json:"upload,omitempty"`
71+
}
72+
73+
// ScheduleExport schedules a project export.
74+
//
75+
// GitLab API docs:
76+
// https://docs.gitlab.com/ce/api/project_import_export.html#schedule-an-export
77+
func (s *ProjectImportExportService) ScheduleExport(pid interface{}, opt *ScheduleExportOptions, options ...OptionFunc) (*Response, error) {
78+
project, err := parseID(pid)
79+
if err != nil {
80+
return nil, err
81+
}
82+
u := fmt.Sprintf("projects/%s/export", pathEscape(project))
83+
84+
req, err := s.client.NewRequest("POST", u, opt, options)
85+
if err != nil {
86+
return nil, err
87+
}
88+
89+
return s.client.Do(req, nil)
90+
}
91+
92+
// ExportStatus get the status of export.
93+
//
94+
// GitLab API docs:
95+
// https://docs.gitlab.com/ce/api/project_import_export.html#export-status
96+
func (s *ProjectImportExportService) ExportStatus(pid interface{}, options ...OptionFunc) (*ExportStatus, *Response, error) {
97+
project, err := parseID(pid)
98+
if err != nil {
99+
return nil, nil, err
100+
}
101+
u := fmt.Sprintf("projects/%s/export", pathEscape(project))
102+
103+
req, err := s.client.NewRequest("GET", u, nil, options)
104+
if err != nil {
105+
return nil, nil, err
106+
}
107+
108+
es := new(ExportStatus)
109+
resp, err := s.client.Do(req, es)
110+
if err != nil {
111+
return nil, resp, err
112+
}
113+
114+
return es, resp, err
115+
}
116+
117+
// ExportDownload download the finished export.
118+
//
119+
// GitLab API docs:
120+
// https://docs.gitlab.com/ce/api/project_import_export.html#export-download
121+
func (s *ProjectImportExportService) ExportDownload(pid interface{}, options ...OptionFunc) ([]byte, *Response, error) {
122+
project, err := parseID(pid)
123+
if err != nil {
124+
return nil, nil, err
125+
}
126+
u := fmt.Sprintf("projects/%s/export/download", pathEscape(project))
127+
128+
req, err := s.client.NewRequest("GET", u, nil, options)
129+
if err != nil {
130+
return nil, nil, err
131+
}
132+
133+
var b bytes.Buffer
134+
resp, err := s.client.Do(req, &b)
135+
if err != nil {
136+
return nil, resp, err
137+
}
138+
139+
return b.Bytes(), resp, err
140+
}
141+
142+
// ImportFileOptions represents the available ImportFile() options.
143+
//
144+
// GitLab API docs:
145+
// https://docs.gitlab.com/ce/api/project_import_export.html#import-a-file
146+
type ImportFileOptions struct {
147+
Namespace *string `url:"namespace,omitempty" json:"namespace,omitempty"`
148+
File *string `url:"file,omitempty" json:"file,omitempty"`
149+
Path *string `url:"path,omitempty" json:"path,omitempty"`
150+
Overwrite *bool `url:"overwrite,omitempty" json:"overwrite,omitempty"`
151+
OverrideParams *CreateProjectOptions `url:"override_params,omitempty" json:"override_params,omitempty"`
152+
}
153+
154+
// ImportProject import the project.
155+
//
156+
// GitLab API docs:
157+
// https://docs.gitlab.com/ce/api/project_import_export.html#import-a-file
158+
func (s *ProjectImportExportService) ImportProject(opt *ImportFileOptions, options ...OptionFunc) (*ImportStatus, *Response, error) {
159+
req, err := s.client.NewRequest("POST", "/projects/import", opt, options)
160+
if err != nil {
161+
return nil, nil, err
162+
}
163+
164+
is := new(ImportStatus)
165+
resp, err := s.client.Do(req, is)
166+
if err != nil {
167+
return nil, resp, err
168+
}
169+
170+
return is, resp, err
171+
}
172+
173+
// ImportStatus get the status of an import.
174+
//
175+
// GitLab API docs:
176+
// https://docs.gitlab.com/ce/api/project_import_export.html#import-status
177+
func (s *ProjectImportExportService) ImportStatus(pid interface{}, options ...OptionFunc) (*ImportStatus, *Response, error) {
178+
project, err := parseID(pid)
179+
if err != nil {
180+
return nil, nil, err
181+
}
182+
u := fmt.Sprintf("projects/%s/import", pathEscape(project))
183+
184+
req, err := s.client.NewRequest("GET", u, nil, options)
185+
if err != nil {
186+
return nil, nil, err
187+
}
188+
189+
is := new(ImportStatus)
190+
resp, err := s.client.Do(req, is)
191+
if err != nil {
192+
return nil, resp, err
193+
}
194+
195+
return is, resp, err
196+
}

repositories.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ func (s *RepositoriesService) Compare(pid interface{}, opt *CompareOptions, opti
251251
//
252252
// GitLab API docs: https://docs.gitlab.com/ce/api/repositories.html#contributors
253253
type Contributor struct {
254-
Name string `json:"name,omitempty"`
255-
Email string `json:"email,omitempty"`
256-
Commits int `json:"commits,omitempty"`
257-
Additions int `json:"additions,omitempty"`
258-
Deletions int `json:"deletions,omitempty"`
254+
Name string `json:"name"`
255+
Email string `json:"email"`
256+
Commits int `json:"commits"`
257+
Additions int `json:"additions"`
258+
Deletions int `json:"deletions"`
259259
}
260260

261261
func (c Contributor) String() string {

0 commit comments

Comments
 (0)