Skip to content

Commit

Permalink
Add packages within group and package status
Browse files Browse the repository at this point in the history
Packages within group introduced in Gitlab 12.5.
Package status introduced in Gitlab 13.9.

https://docs.gitlab.com/ee/api/packages.html
  • Loading branch information
breml authored and svanharmelen committed Feb 10, 2022
1 parent b347d31 commit 7a5b4df
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages.go
Expand Up @@ -38,8 +38,19 @@ type Package struct {
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"`
}

// GroupPackage represents a GitLab single package with project reference.
//
// 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 Package) String() string {
Expand Down Expand Up @@ -85,6 +96,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,6 +124,46 @@ func (s *PackagesService) ListProjectPackages(pid interface{}, opt *ListProjectP
return ps, resp, err
}

// ListGroupPackagesOptions are the parameters available in a ListGroupPackages() Operation.
//
// 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.
//
Expand Down

0 comments on commit 7a5b4df

Please sign in to comment.