* Discovers references from a remote Git repository. * * @param {Object} args * @param {HttpClient} args.http - The HTTP client to use for requests. * @param {ProgressCallback} [args.onProgress] - Callback for progress updates. * @param {AuthCallback} [args.onAuth] - Callback for prov
({
http,
onProgress,
onAuth,
onAuthSuccess,
onAuthFailure,
corsProxy,
service,
url: _origUrl,
headers,
protocolVersion,
})
| 75 | * @throws {UserCanceledError} - If the user cancels the operation. |
| 76 | */ |
| 77 | static async discover({ |
| 78 | http, |
| 79 | onProgress, |
| 80 | onAuth, |
| 81 | onAuthSuccess, |
| 82 | onAuthFailure, |
| 83 | corsProxy, |
| 84 | service, |
| 85 | url: _origUrl, |
| 86 | headers, |
| 87 | protocolVersion, |
| 88 | }) { |
| 89 | let { url, auth } = extractAuthFromUrl(_origUrl) |
| 90 | const proxifiedURL = corsProxy ? corsProxify(corsProxy, url) : url |
| 91 | if (auth.username || auth.password) { |
| 92 | headers.Authorization = calculateBasicAuthHeader(auth) |
| 93 | } |
| 94 | if (protocolVersion === 2) { |
| 95 | headers['Git-Protocol'] = 'version=2' |
| 96 | } |
| 97 | |
| 98 | let res |
| 99 | let tryAgain |
| 100 | let providedAuthBefore = false |
| 101 | do { |
| 102 | res = await http.request({ |
| 103 | onProgress, |
| 104 | method: 'GET', |
| 105 | url: `${proxifiedURL}/info/refs?service=${service}`, |
| 106 | headers, |
| 107 | }) |
| 108 | |
| 109 | // the default loop behavior |
| 110 | tryAgain = false |
| 111 | |
| 112 | // 401 is the "correct" response for access denied. 203 is Non-Authoritative Information and comes from Azure DevOps, which |
| 113 | // apparently doesn't realize this is a git request and is returning the HTML for the "Azure DevOps Services | Sign In" page. |
| 114 | if (res.statusCode === 401 || res.statusCode === 203) { |
| 115 | // On subsequent 401s, call `onAuthFailure` instead of `onAuth`. |
| 116 | // This is so that naive `onAuth` callbacks that return a fixed value don't create an infinite loop of retrying. |
| 117 | const getAuth = providedAuthBefore ? onAuthFailure : onAuth |
| 118 | if (getAuth) { |
| 119 | // Acquire credentials and try again |
| 120 | // TODO: read `useHttpPath` value from git config and pass along? |
| 121 | auth = await getAuth(url, { |
| 122 | ...auth, |
| 123 | headers: { ...headers }, |
| 124 | }) |
| 125 | if (auth && auth.cancel) { |
| 126 | throw new UserCanceledError() |
| 127 | } else if (auth) { |
| 128 | updateHeaders(headers, auth) |
| 129 | providedAuthBefore = true |
| 130 | tryAgain = true |
| 131 | } |
| 132 | } |
| 133 | } else if ( |
| 134 | res.statusCode === 200 && |
no test coverage detected