Skip to content

Commit

Permalink
Add ApiURI for gitlab provider (#27)
Browse files Browse the repository at this point in the history
* Add ApiURI for gitlab provider
it can let us using private server

* Increase code coverage for provider_gitlab.go

---------

Co-authored-by: Julien NOBLET <julien.noblet@gls-france.com>
  • Loading branch information
julien-noblet and JulienNoblet authored Feb 9, 2023
1 parent 9c4619a commit 9dba835
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/provider/provider_gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions pkg/provider/provider_gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
}
}

0 comments on commit 9dba835

Please sign in to comment.