MCPcopy Create free account
hub / github.com/ddev/ddev / GetGitHubHeaders

Function GetGitHubHeaders

pkg/github/github.go:109–120  ·  view source on GitHub ↗

GetGitHubHeaders returns headers to be used in GitHub REST API requests if the URL is for GitHub. See https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api

(requestURL string)

Source from the content-addressed store, hash-verified

107// GetGitHubHeaders returns headers to be used in GitHub REST API requests if the URL is for GitHub.
108// See https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api
109func GetGitHubHeaders(requestURL string) map[string]string {
110 headers := map[string]string{}
111 if !isGitHubURL(requestURL) {
112 return headers
113 }
114 if githubToken, _ := GetGitHubToken(); githubToken != "" {
115 headers["Authorization"] = "Bearer " + githubToken
116 // Use the same header as in vendor/github.com/google/go-github/v81/github/github.go
117 headers["X-Github-Api-Version"] = "2022-11-28"
118 }
119 return headers
120}
121
122// isGitHubURL checks if the given URL is for GitHub or any subdomain of GitHub
123func isGitHubURL(requestURL string) bool {

Callers 2

TestGetGitHubHeadersFunction · 0.92
DownloadFileExtendedFunction · 0.92

Calls 2

isGitHubURLFunction · 0.85
GetGitHubTokenFunction · 0.85

Tested by 1

TestGetGitHubHeadersFunction · 0.74