-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renovate support of Gitlab/Github OnPrem (#281)
* Renovate support of Gitlab/Github OnPrem
- Loading branch information
1 parent
f834c1b
commit 6f1cd04
Showing
11 changed files
with
156 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package git | ||
|
||
import "fmt" | ||
|
||
// APIEndpoint interface defines the method to get the API endpoint url for | ||
// the source code providers. | ||
type APIEndpoint interface { | ||
APIEndpoint(host string) string | ||
} | ||
|
||
// GithubAPIEndpoint represents an API endpoint for GitHub. | ||
type GithubAPIEndpoint struct { | ||
} | ||
|
||
// APIEndpoint returns the GitHub API endpoint. | ||
func (g *GithubAPIEndpoint) APIEndpoint(host string) string { | ||
return fmt.Sprintf("https://api.%s/", host) | ||
} | ||
|
||
// GitlabAPIEndpoint represents an API endpoint for GitLab. | ||
type GitlabAPIEndpoint struct { | ||
} | ||
|
||
// APIEndpoint returns the API GitLab endpoint. | ||
func (g *GitlabAPIEndpoint) APIEndpoint(host string) string { | ||
return fmt.Sprintf("https://%s/api/v4/", host) | ||
} | ||
|
||
// UnknownAPIEndpoint represents an endpoint for unknown or non existed provider. It returns empty string for api endpoint. | ||
type UnknownAPIEndpoint struct { | ||
} | ||
|
||
// APIEndpoint returns the GitLab endpoint. | ||
func (g *UnknownAPIEndpoint) APIEndpoint(host string) string { | ||
return "" | ||
} | ||
|
||
// BuildAPIEndpoint constructs and returns an endpoint object based on the type provided type. | ||
func BuildAPIEndpoint(endpointType string) APIEndpoint { | ||
switch endpointType { | ||
case "github": | ||
return &GithubAPIEndpoint{} | ||
case "gitlab": | ||
return &GitlabAPIEndpoint{} | ||
default: | ||
return &UnknownAPIEndpoint{} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package git | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestBuildEndpoint(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
endpointType string | ||
host string | ||
wantEndpoint string | ||
}{ | ||
{ | ||
name: "Github SAAS", | ||
endpointType: "github", | ||
host: "github.com", | ||
wantEndpoint: "https://api.github.com/", | ||
}, | ||
{ | ||
name: "Github On-Prem", | ||
endpointType: "github", | ||
host: "github.umbrella.com", | ||
wantEndpoint: "https://api.github.umbrella.com/", | ||
}, | ||
{ | ||
name: "Gitlab SAAS", | ||
endpointType: "gitlab", | ||
host: "gitlab.com", | ||
wantEndpoint: "https://gitlab.com/api/v4/", | ||
}, | ||
{ | ||
name: "Gitlab On-Prem", | ||
endpointType: "gitlab", | ||
host: "gitlab.umbrella.com", | ||
wantEndpoint: "https://gitlab.umbrella.com/api/v4/", | ||
}, | ||
{ | ||
name: "Unknown provider", | ||
endpointType: "bibi", | ||
host: "bibi.umbrella.com", | ||
wantEndpoint: "", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := BuildAPIEndpoint(tt.endpointType).APIEndpoint(tt.host); got != tt.wantEndpoint { | ||
t.Errorf("BuildAPIEndpoint() = %v, want %v", got, tt.wantEndpoint) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.