Skip to content

Commit 8ea072e

Browse files
simplify building github root URL
1 parent b87ee19 commit 8ea072e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pkg/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ func LoadConfig(configFiles []string, deploymentId int) (*Config, error) {
441441
// the Semgrep AppSec Platform fetches repository contents using the git smart transfer protocol
442442
// which requests resources which don't have an api suffix, e.g. /api/v3/
443443
// see https://git-scm.com/book/be/v2/Git-Internals-Transfer-Protocols
444-
githubBaseUrlWithoutApiSuffix, err := url.Parse(strings.TrimSuffix(gitHub.BaseURL, "/api/v3"))
444+
githubRootUrl, err := url.Parse(gitHubBaseUrl.Scheme + "://" + gitHubBaseUrl.Host)
445445
if err != nil {
446-
return nil, fmt.Errorf("failed to parse github base URL without api suffix: %v", err)
446+
return nil, fmt.Errorf("failed to build github root URL: %v", err)
447447
}
448448

449449
var headers map[string]string
@@ -651,13 +651,13 @@ func LoadConfig(configFiles []string, deploymentId int) (*Config, error) {
651651
},
652652
// discover refs
653653
AllowlistItem{
654-
URL: githubBaseUrlWithoutApiSuffix.JoinPath("/:org/:repo/info/refs").String(),
654+
URL: githubRootUrl.JoinPath("/:org/:repo/info/refs").String(),
655655
Methods: ParseHttpMethods([]string{"GET"}),
656656
SetRequestHeaders: headers,
657657
},
658658
// download repo contents
659659
AllowlistItem{
660-
URL: githubBaseUrlWithoutApiSuffix.JoinPath("/:org/:repo/git-upload-pack").String(),
660+
URL: githubRootUrl.JoinPath("/:org/:repo/git-upload-pack").String(),
661661
Methods: ParseHttpMethods([]string{"POST"}),
662662
SetRequestHeaders: headers,
663663
},

0 commit comments

Comments
 (0)