From 42bf3d93936a56ea6b4803b0ee389d5928e1a158 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Mon, 22 Nov 2021 09:14:11 +0100 Subject: [PATCH] Add response type as otherwise the select has no use --- generic_packages.go | 47 +++++++++++++++++++++++++++++++++++----- generic_packages_test.go | 2 +- types.go | 14 ++++++------ 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/generic_packages.go b/generic_packages.go index f4317a8b6..a2db4b154 100644 --- a/generic_packages.go +++ b/generic_packages.go @@ -21,6 +21,7 @@ import ( "fmt" "io" "net/http" + "time" ) // GenericPackagesService handles communication with the packages related @@ -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"` @@ -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", @@ -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. diff --git a/generic_packages_test.go b/generic_packages_test.go index be64a9260..e227f268f 100644 --- a/generic_packages_test.go +++ b/generic_packages_test.go @@ -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) } diff --git a/types.go b/types.go index eaa3217b7..679cb9ef1 100644 --- a/types.go +++ b/types.go @@ -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. @@ -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