mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 11:41:27 +00:00
Trim slash for configure URL. (#2381)
This commit is contained in:
@@ -29,7 +29,7 @@ type GitHubConfig struct {
|
||||
}
|
||||
|
||||
func ParseGitHubConfigFromURL(in string) (*GitHubConfig, error) {
|
||||
u, err := url.Parse(in)
|
||||
u, err := url.Parse(strings.Trim(in, "/"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func ParseGitHubConfigFromURL(in string) (*GitHubConfig, error) {
|
||||
|
||||
invalidURLError := fmt.Errorf("%q: %w", u.String(), ErrInvalidGitHubConfigURL)
|
||||
|
||||
pathParts := strings.Split(strings.TrimPrefix(u.Path, "/"), "/")
|
||||
pathParts := strings.Split(strings.Trim(u.Path, "/"), "/")
|
||||
|
||||
switch len(pathParts) {
|
||||
case 1: // Organization
|
||||
|
||||
@@ -3,6 +3,7 @@ package actions_test
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/actions/actions-runner-controller/github/actions"
|
||||
@@ -26,6 +27,16 @@ func TestGitHubConfig(t *testing.T) {
|
||||
IsHosted: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
configURL: "https://github.com/org/repo/",
|
||||
expected: &actions.GitHubConfig{
|
||||
Scope: actions.GitHubScopeRepository,
|
||||
Enterprise: "",
|
||||
Organization: "org",
|
||||
Repository: "repo",
|
||||
IsHosted: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
configURL: "https://github.com/org",
|
||||
expected: &actions.GitHubConfig{
|
||||
@@ -46,6 +57,16 @@ func TestGitHubConfig(t *testing.T) {
|
||||
IsHosted: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
configURL: "https://github.com/enterprises/my-enterprise/",
|
||||
expected: &actions.GitHubConfig{
|
||||
Scope: actions.GitHubScopeEnterprise,
|
||||
Enterprise: "my-enterprise",
|
||||
Organization: "",
|
||||
Repository: "",
|
||||
IsHosted: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
configURL: "https://www.github.com/org",
|
||||
expected: &actions.GitHubConfig{
|
||||
@@ -56,6 +77,16 @@ func TestGitHubConfig(t *testing.T) {
|
||||
IsHosted: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
configURL: "https://www.github.com/org/",
|
||||
expected: &actions.GitHubConfig{
|
||||
Scope: actions.GitHubScopeOrganization,
|
||||
Enterprise: "",
|
||||
Organization: "org",
|
||||
Repository: "",
|
||||
IsHosted: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
configURL: "https://github.localhost/org",
|
||||
expected: &actions.GitHubConfig{
|
||||
@@ -76,11 +107,21 @@ func TestGitHubConfig(t *testing.T) {
|
||||
IsHosted: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
configURL: "https://my-ghes.com/org/",
|
||||
expected: &actions.GitHubConfig{
|
||||
Scope: actions.GitHubScopeOrganization,
|
||||
Enterprise: "",
|
||||
Organization: "org",
|
||||
Repository: "",
|
||||
IsHosted: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.configURL, func(t *testing.T) {
|
||||
parsedURL, err := url.Parse(test.configURL)
|
||||
parsedURL, err := url.Parse(strings.Trim(test.configURL, "/"))
|
||||
require.NoError(t, err)
|
||||
test.expected.ConfigURL = parsedURL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user