Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #621 from alex-berger/feature/project-import-export
Browse files Browse the repository at this point in the history
Project Import/Export API
  • Loading branch information
svanharmelen authored May 25, 2019
2 parents 39fbdb2 + a37b347 commit 5847070
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Folders
_obj
_test
.idea

# Architecture specific extensions/prefixes
*.[568vq]
Expand All @@ -23,3 +22,7 @@ _testmain.go
*.exe
*.test
*.prof

# IDE specific files and folders
.idea
*.iml
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ to add new and/or missing endpoints. Currently the following services are suppor
- [ ] Epic Issues
- [ ] Epics
- [ ] Geo Nodes
- [ ] Project import/export
- [x] Award Emojis
- [x] Branches
- [x] Broadcast Messages
Expand All @@ -35,14 +34,14 @@ to add new and/or missing endpoints. Currently the following services are suppor
- [x] Deployments
- [x] Environments
- [x] Events
- [x] Feature flags
- [x] GitLab CI Config templates
- [x] Gitignores templates
- [x] Feature Flags
- [x] GitLab CI Config Templates
- [x] Gitignores Templates
- [x] Group Access Requests
- [x] Group Issue Boards
- [x] Group Members
- [x] Group Milestones
- [x] Group-level Variables
- [x] Group-Level Variables
- [x] Groups
- [x] Issue Boards
- [x] Issues
Expand All @@ -54,19 +53,20 @@ to add new and/or missing endpoints. Currently the following services are suppor
- [x] Merge Requests
- [x] Namespaces
- [x] Notes (comments)
- [x] Notification settings
- [x] Open source license templates
- [x] Notification Settings
- [x] Open Source License Templates
- [x] Pages Domains
- [x] Pipeline Schedules
- [x] Pipeline Triggers
- [x] Pipelines
- [x] Project Access Requests
- [x] Project Badges
- [x] Project Clusters
- [x] Project Import/export
- [x] Project Members
- [x] Project Milestones
- [x] Project Snippets
- [x] Project badges
- [x] Project-level Variables
- [x] Project-Level Variables
- [x] Projects (including setting Webhooks)
- [x] Protected Branches
- [x] Protected Tags
Expand All @@ -76,12 +76,12 @@ to add new and/or missing endpoints. Currently the following services are suppor
- [x] Search
- [x] Services
- [x] Settings
- [x] Sidekiq metrics
- [x] Sidekiq Metrics
- [x] System Hooks
- [x] Tags
- [x] Todos
- [x] Users
- [x] Validate CI configuration
- [x] Validate CI Configuration
- [x] Version
- [x] Wikis

Expand Down
2 changes: 2 additions & 0 deletions gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ type Client struct {
Pipelines *PipelinesService
ProjectBadges *ProjectBadgesService
ProjectCluster *ProjectClustersService
ProjectImportExport *ProjectImportExportService
ProjectMembers *ProjectMembersService
ProjectSnippets *ProjectSnippetsService
ProjectVariables *ProjectVariablesService
Expand Down Expand Up @@ -478,6 +479,7 @@ func newClient(httpClient *http.Client) *Client {
c.Pipelines = &PipelinesService{client: c}
c.ProjectBadges = &ProjectBadgesService{client: c}
c.ProjectCluster = &ProjectClustersService{client: c}
c.ProjectImportExport = &ProjectImportExportService{client: c}
c.ProjectMembers = &ProjectMembersService{client: c}
c.ProjectSnippets = &ProjectSnippetsService{client: c}
c.ProjectVariables = &ProjectVariablesService{client: c}
Expand Down
196 changes: 196 additions & 0 deletions project_import_export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package gitlab

import (
"bytes"
"fmt"
"time"
)

// ProjectImportExportService handles communication with the project
// import/export related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/user/project/settings/import_export.html
type ProjectImportExportService struct {
client *Client
}

// ImportStatus represents a project import status.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_import_export.html#import-status
type ImportStatus struct {
ID int `json:"id"`
Description string `json:"description"`
Name string `json:"name"`
NameWithNamespace string `json:"name_with_namespace"`
Path string `json:"path"`
PathWithNamespace string `json:"path_with_namespace"`
CreateAt *time.Time `json:"create_at"`
ImportStatus string `json:"import_status"`
}

func (s ImportStatus) String() string {
return Stringify(s)
}

// ExportStatus represents a project export status.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_import_export.html#export-status
type ExportStatus struct {
ID int `json:"id"`
Description string `json:"description"`
Name string `json:"name"`
NameWithNamespace string `json:"name_with_namespace"`
Path string `json:"path"`
PathWithNamespace string `json:"path_with_namespace"`
CreatedAt *time.Time `json:"created_at"`
ExportStatus string `json:"export_status"`
Message string `json:"message"`
Links struct {
APIURL string `json:"api_url"`
WebURL string `json:"web_url"`
} `json:"_links"`
}

func (s ExportStatus) String() string {
return Stringify(s)
}

// ScheduleExportOptions represents the available ScheduleExport() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_import_export.html#schedule-an-export
type ScheduleExportOptions struct {
Description *string `url:"description,omitempty" json:"description,omitempty"`
Upload struct {
URL *string `url:"url,omitempty" json:"url,omitempty"`
HTTPMethod *string `url:"http_method,omitempty" json:"http_method,omitempty"`
} `url:"upload,omitempty" json:"upload,omitempty"`
}

// ScheduleExport schedules a project export.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_import_export.html#schedule-an-export
func (s *ProjectImportExportService) ScheduleExport(pid interface{}, opt *ScheduleExportOptions, options ...OptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/export", pathEscape(project))

req, err := s.client.NewRequest("POST", u, opt, options)
if err != nil {
return nil, err
}

return s.client.Do(req, nil)
}

// ExportStatus get the status of export.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_import_export.html#export-status
func (s *ProjectImportExportService) ExportStatus(pid interface{}, options ...OptionFunc) (*ExportStatus, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/export", pathEscape(project))

req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
return nil, nil, err
}

es := new(ExportStatus)
resp, err := s.client.Do(req, es)
if err != nil {
return nil, resp, err
}

return es, resp, err
}

// ExportDownload download the finished export.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_import_export.html#export-download
func (s *ProjectImportExportService) ExportDownload(pid interface{}, options ...OptionFunc) ([]byte, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/export/download", pathEscape(project))

req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
return nil, nil, err
}

var b bytes.Buffer
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}

return b.Bytes(), resp, err
}

// ImportFileOptions represents the available ImportFile() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_import_export.html#import-a-file
type ImportFileOptions struct {
Namespace *string `url:"namespace,omitempty" json:"namespace,omitempty"`
File *string `url:"file,omitempty" json:"file,omitempty"`
Path *string `url:"path,omitempty" json:"path,omitempty"`
Overwrite *bool `url:"overwrite,omitempty" json:"overwrite,omitempty"`
OverrideParams *CreateProjectOptions `url:"override_params,omitempty" json:"override_params,omitempty"`
}

// ImportProject import the project.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_import_export.html#import-a-file
func (s *ProjectImportExportService) ImportProject(opt *ImportFileOptions, options ...OptionFunc) (*ImportStatus, *Response, error) {
req, err := s.client.NewRequest("POST", "/projects/import", opt, options)
if err != nil {
return nil, nil, err
}

is := new(ImportStatus)
resp, err := s.client.Do(req, is)
if err != nil {
return nil, resp, err
}

return is, resp, err
}

// ImportStatus get the status of an import.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_import_export.html#import-status
func (s *ProjectImportExportService) ImportStatus(pid interface{}, options ...OptionFunc) (*ImportStatus, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/import", pathEscape(project))

req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
return nil, nil, err
}

is := new(ImportStatus)
resp, err := s.client.Do(req, is)
if err != nil {
return nil, resp, err
}

return is, resp, err
}
10 changes: 5 additions & 5 deletions repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ func (s *RepositoriesService) Compare(pid interface{}, opt *CompareOptions, opti
//
// GitLab API docs: https://docs.gitlab.com/ce/api/repositories.html#contributors
type Contributor struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Commits int `json:"commits,omitempty"`
Additions int `json:"additions,omitempty"`
Deletions int `json:"deletions,omitempty"`
Name string `json:"name"`
Email string `json:"email"`
Commits int `json:"commits"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
}

func (c Contributor) String() string {
Expand Down

0 comments on commit 5847070

Please sign in to comment.