Treat .ghe.com domain as hosted environment (#2480)

Co-authored-by: Nikola Jokic <jokicnikola07@gmail.com>
This commit is contained in:
Tingluo Huang
2023-04-04 14:43:45 -04:00
committed by GitHub
parent a804bf8b00
commit 8fa4520376
2 changed files with 63 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ package actions_test
import (
"errors"
"net/url"
"os"
"strings"
"testing"
@@ -117,6 +118,16 @@ func TestGitHubConfig(t *testing.T) {
IsHosted: false,
},
},
{
configURL: "https://my-ghes.ghe.com/org/",
expected: &actions.GitHubConfig{
Scope: actions.GitHubScopeOrganization,
Enterprise: "",
Organization: "org",
Repository: "",
IsHosted: true,
},
},
}
for _, test := range tests {
@@ -151,9 +162,35 @@ func TestGitHubConfig_GitHubAPIURL(t *testing.T) {
t.Run("when hosted", func(t *testing.T) {
config, err := actions.ParseGitHubConfigFromURL("https://github.com/org/repo")
require.NoError(t, err)
assert.True(t, config.IsHosted)
result := config.GitHubAPIURL("/some/path")
assert.Equal(t, "https://api.github.com/some/path", result.String())
})
t.Run("when not hosted", func(t *testing.T) {})
t.Run("when hosted with ghe.com", func(t *testing.T) {
config, err := actions.ParseGitHubConfigFromURL("https://github.ghe.com/org/repo")
require.NoError(t, err)
assert.True(t, config.IsHosted)
result := config.GitHubAPIURL("/some/path")
assert.Equal(t, "https://api.github.ghe.com/some/path", result.String())
})
t.Run("when not hosted", func(t *testing.T) {
config, err := actions.ParseGitHubConfigFromURL("https://ghes.com/org/repo")
require.NoError(t, err)
assert.False(t, config.IsHosted)
result := config.GitHubAPIURL("/some/path")
assert.Equal(t, "https://ghes.com/api/v3/some/path", result.String())
})
t.Run("when not hosted with ghe.com", func(t *testing.T) {
os.Setenv("GITHUB_ACTIONS_FORCE_GHES", "1")
defer os.Unsetenv("GITHUB_ACTIONS_FORCE_GHES")
config, err := actions.ParseGitHubConfigFromURL("https://test.ghe.com/org/repo")
require.NoError(t, err)
assert.False(t, config.IsHosted)
result := config.GitHubAPIURL("/some/path")
assert.Equal(t, "https://test.ghe.com/api/v3/some/path", result.String())
})
}