MCPcopy Create free account
hub / github.com/github/gh-aw / attachImportAuthHeader

Function attachImportAuthHeader

pkg/cli/import_url_fetcher.go:211–242  ·  view source on GitHub ↗
(req *http.Request, rawURL string)

Source from the content-addressed store, hash-verified

209)
210
211func attachImportAuthHeader(req *http.Request, rawURL string) {
212 parsed, err := url.Parse(rawURL)
213 if err != nil || parsed.Host == "" {
214 return
215 }
216
217 // Never send credentials over plaintext HTTP — HTTPS is required.
218 if !strings.EqualFold(parsed.Scheme, "https") {
219 importURLFetcherLog.Printf("Skipping auth header for non-HTTPS URL: scheme=%s", parsed.Scheme)
220 return
221 }
222
223 host := strings.ToLower(parsed.Hostname())
224
225 // Authoritative GitHub hosts to which the token may be sent.
226 if _, ok := defaultImportAuthHosts[host]; !ok && host != importAuthGHHost() {
227 importURLFetcherLog.Printf("Skipping auth header for non-GitHub host: %s", host)
228 return
229 }
230
231 token, err := parser.GetGitHubToken()
232 if err != nil {
233 importURLFetcherLog.Printf("No GitHub token available: %v", err)
234 return
235 }
236
237 importURLFetcherLog.Printf("Attaching auth header for host: %s", host)
238 req.Header.Set("Authorization", "Bearer "+token)
239 if isCopilotAutomationImportURL(parsed) {
240 req.Header.Set("Copilot-Integration-Id", copilotIntegrationHeaderValue)
241 }
242}
243
244// isCopilotAutomationImportURL reports whether u targets a Copilot automation API route
245// with exactly six path segments: /agents/repos/{owner}/{repo}/automations/{id}.

Calls 6

GetGitHubTokenFunction · 0.92
importAuthGHHostFunction · 0.85
ToLowerMethod · 0.80
PrintfMethod · 0.45
SetMethod · 0.45