Skip to content

Commit

Permalink
Add response type as otherwise the select has no use
Browse files Browse the repository at this point in the history
  • Loading branch information
svanharmelen committed Nov 22, 2021
1 parent 15d4f08 commit 42bf3d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
47 changes: 41 additions & 6 deletions generic_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"net/http"
"time"
)

// GenericPackagesService handles communication with the packages related
Expand All @@ -32,11 +33,39 @@ type GenericPackagesService struct {
client *Client
}

// GenericPackagesFile represents a GitLab generic package file.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#publish-a-package-file
type GenericPackagesFile struct {
ID int `json:"id"`
PackageID int `json:"package_id"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
Size int `json:"size"`
FileStore int `json:"file_store"`
FileMD5 string `json:"file_md5"`
FileSHA1 string `json:"file_sha1"`
FileName string `json:"file_name"`
File struct {
URL string `json:"url"`
} `json:"file"`
FileSHA256 string `json:"file_sha256"`
VerificationRetryAt *time.Time `json:"verification_retry_at"`
VerifiedAt *time.Time `json:"verified_at"`
VerificationFailure bool `json:"verification_failure"`
VerificationRetryCount int `json:"verification_retry_count"`
VerificationChecksum string `json:"verification_checksum"`
VerificationState int `json:"verification_state"`
VerificationStartedAt *time.Time `json:"verification_started_at"`
NewFilePath string `json:"new_file_path"`
}

// PublishPackageFileOptions represents the available PublishPackageFile()
// options.
//
// GitLab docs:
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#download-package-file
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#publish-a-package-file
type PublishPackageFileOptions struct {
Status *GenericPackageStatusValue `url:"status,omitempty" json:"status,omitempty"`
Select *GenericPackageSelectValue `url:"select,omitempty" json:"select,omitempty"`
Expand All @@ -45,11 +74,11 @@ type PublishPackageFileOptions struct {
// PublishPackageFile uploads a file to a project's package registry.
//
// GitLab docs:
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#download-package-file
func (s *GenericPackagesService) PublishPackageFile(pid interface{}, packageName, packageVersion, fileName string, content io.Reader, opt *PublishPackageFileOptions, options ...RequestOptionFunc) (*Response, error) {
// https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#publish-a-package-file
func (s *GenericPackagesService) PublishPackageFile(pid interface{}, packageName, packageVersion, fileName string, content io.Reader, opt *PublishPackageFileOptions, options ...RequestOptionFunc) (*GenericPackagesFile, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
return nil, nil, err
}
u := fmt.Sprintf(
"projects/%s/packages/generic/%s/%s/%s",
Expand All @@ -64,14 +93,20 @@ func (s *GenericPackagesService) PublishPackageFile(pid interface{}, packageName
// the method and the body.
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, err
return nil, nil, err
}

// Overwrite the method and body.
req.Method = http.MethodPut
req.SetBody(content)

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

return f, resp, err
}

// DownloadPackageFile allows you to download the package file.
Expand Down
2 changes: 1 addition & 1 deletion generic_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestPublishPackageFile(t *testing.T) {
`)
})

_, err := client.GenericPackages.PublishPackageFile(1234, "foo", "0.1.2", "bar-baz.txt", strings.NewReader("bar = baz"), &PublishPackageFileOptions{})
_, _, err := client.GenericPackages.PublishPackageFile(1234, "foo", "0.1.2", "bar-baz.txt", strings.NewReader("bar = baz"), &PublishPackageFileOptions{})
if err != nil {
t.Errorf("GenericPackages.PublishPackageFile returned error: %v", err)
}
Expand Down
14 changes: 7 additions & 7 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,23 @@ func FileAction(v FileActionValue) *FileActionValue {
return p
}

// GenericPackageSelectValue represents a GitLab Package Status.
// GenericPackageSelectValue represents a generic package select value.
type GenericPackageSelectValue string

// The available generic package statuses.
// The available generic package select values.
const (
SelectPackageFile GenericPackageSelectValue = "package_file"
)

// GenericPackageStatus is a helper routine that allocates a new GenericPackageStatusValue
// value to store v and returns a pointer to it.
// GenericPackageSelect is a helper routine that allocates a new
// GenericPackageSelectValue value to store v and returns a pointer to it.
func GenericPackageSelect(v GenericPackageSelectValue) *GenericPackageSelectValue {
p := new(GenericPackageSelectValue)
*p = v
return p
}

// GenericPackageStatusValue represents a GitLab Package Status.
// GenericPackageStatusValue represents a generic package status.
type GenericPackageStatusValue string

// The available generic package statuses.
Expand All @@ -224,8 +224,8 @@ const (
PackageHidden GenericPackageStatusValue = "hidden"
)

// GenericPackageStatus is a helper routine that allocates a new GenericPackageStatusValue
// value to store v and returns a pointer to it.
// GenericPackageStatus is a helper routine that allocates a new
// GenericPackageStatusValue value to store v and returns a pointer to it.
func GenericPackageStatus(v GenericPackageStatusValue) *GenericPackageStatusValue {
p := new(GenericPackageStatusValue)
*p = v
Expand Down

0 comments on commit 42bf3d9

Please sign in to comment.