diff --git a/pkg/provider/provider_gitlab.go b/pkg/provider/provider_gitlab.go index 775b429..9b6d334 100644 --- a/pkg/provider/provider_gitlab.go +++ b/pkg/provider/provider_gitlab.go @@ -17,6 +17,7 @@ import ( type Gitlab struct { ProjectID int ArchiveName string // ArchiveName (the archive you upload for a release on gitlab), example: binaries.zip + ApiURI string // ApiURI (in case you're using a private gitlab server), example: gitlab.mydomain.tld/api/v4/projects/%d/releases to use gitlab.com let it blank tmpDir string // temporary directory this is used internally decompressProvider Provider // provider used to decompress the downloaded archive @@ -41,6 +42,12 @@ type gitlabReleaseLink struct { // getReleasesURL get the releases URL for the gitlab repository func (c *Gitlab) getReleasesURL() (string, error) { + if c.ApiURI != "" { + return fmt.Sprintf(c.ApiURI, + c.ProjectID, + ), nil + } + return fmt.Sprintf("https://gitlab.com/api/v4/projects/%d/releases", c.ProjectID, ), nil diff --git a/pkg/provider/provider_gitlab_test.go b/pkg/provider/provider_gitlab_test.go index 051e135..1107c50 100644 --- a/pkg/provider/provider_gitlab_test.go +++ b/pkg/provider/provider_gitlab_test.go @@ -24,6 +24,22 @@ func TestProviderGitlab(t *testing.T) { t.Fatal(err) } + pp := &provider.Gitlab{ + ProjectID: 24021648, + ArchiveName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS), + ApiURI: "https://gitlab.com/api/v4/projects/%d/releases", // same as original + } + + if err := pp.Open(); err != nil { + t.Fatal(err) + } + defer pp.Close() + + err = ProviderTestWalkAndRetrieve(pp) + if err != nil { + t.Fatal(err) + } + badProvider := &provider.Gitlab{ ProjectID: 424242424242424242, ArchiveName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS), @@ -32,4 +48,14 @@ func TestProviderGitlab(t *testing.T) { if err != nil { t.Fatal(err) } + + badProviderApi := &provider.Gitlab{ + ProjectID: 24021648, + ArchiveName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS), + ApiURI: "https://bad.url/api/%d/R", + } + err = ProviderTestUnavailable(badProviderApi) + if err != nil { + t.Fatal(err) + } }