Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add packages within group and package status #1154

Merged
merged 2 commits into from Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 62 additions & 4 deletions packages.go
Expand Up @@ -30,22 +30,37 @@ type PackagesService struct {
client *Client
}

// Package represents a GitLab single package.
// Package represents a GitLab package.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/packages.html
type Package struct {
ID int `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
PackageType string `json:"package_type"`
Status string `json:"status"`
Links *PackageLinks `json:"_links"`
CreatedAt *time.Time `json:"created_at"`
Tags []string `json:"tags"`
}

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

// GroupPackage represents a GitLab group package.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/packages.html
type GroupPackage struct {
Package
ProjectID int `json:"project_id"`
ProjectPath string `json:"project_path"`
}

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

// PackageLinks holds links for itself and deleting.
type PackageLinks struct {
WebPath string `json:"web_path"`
Expand Down Expand Up @@ -74,7 +89,8 @@ func (s PackageFile) String() string {
return Stringify(s)
}

// ListProjectPackagesOptions are the parameters available in a ListProjectPackages() Operation.
// ListProjectPackagesOptions represents the available ListProjectPackages()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/packages.html#within-a-project
Expand All @@ -85,6 +101,7 @@ type ListProjectPackagesOptions struct {
PackageType *string `url:"package_type,omitempty" json:"package_type,omitempty"`
PackageName *string `url:"package_name,omitempty" json:"package_name,omitempty"`
IncludeVersionless *bool `url:"include_versionless,omitempty" json:"include_versionless,omitempty"`
Status *string `url:"status,omitempty" json:"status,omitempty"`
}

// ListProjectPackages gets a list of packages in a project.
Expand Down Expand Up @@ -112,8 +129,49 @@ func (s *PackagesService) ListProjectPackages(pid interface{}, opt *ListProjectP
return ps, resp, err
}

// ListPackageFilesOptions represents the available
// ListPackageFiles() options.
// ListGroupPackagesOptions represents the available ListGroupPackages()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/packages.html#within-a-group
type ListGroupPackagesOptions struct {
ListOptions
ExcludeSubgroups *bool `url:"exclude_subgroups,omitempty" json:"exclude_subgroups,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
PackageType *string `url:"package_type,omitempty" json:"package_type,omitempty"`
PackageName *string `url:"package_name,omitempty" json:"package_name,omitempty"`
IncludeVersionless *bool `url:"include_versionless,omitempty" json:"include_versionless,omitempty"`
Status *string `url:"status,omitempty" json:"status,omitempty"`
}

// ListGroupPackages gets a list of packages in a group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/packages.html#within-a-group
func (s *PackagesService) ListGroupPackages(gid interface{}, opt *ListGroupPackagesOptions, options ...RequestOptionFunc) ([]*GroupPackage, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/packages", PathEscape(group))

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

var ps []*GroupPackage
resp, err := s.client.Do(req, &ps)
if err != nil {
return nil, resp, err
}

return ps, resp, err
}

// ListPackageFilesOptions represents the available ListPackageFiles()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/packages.html#list-package-files
Expand Down
1 change: 1 addition & 0 deletions packages_test.go
Expand Up @@ -41,6 +41,7 @@ func TestPackagesService_ListProjectPackages(t *testing.T) {
WebPath: "/foo/bar/-/packages/3",
DeleteAPIPath: "https://gitlab.example.com/api/v4/projects/1/packages/3",
},
Tags: []string{},
}}

ps, resp, err := client.Packages.ListProjectPackages(3, nil)
Expand Down