Created
October 17, 2018 10:56
-
-
Save taktran/fe910e93f1cf3b254c4b43a709dc057e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const GITHUB_TEAM_API_URL_PREFIX = 'https://api.github.com/repos/SOME_TEAM'; | |
const githubArchiveUrl = ({ repoName, branch }) => | |
`${GITHUB_TEAM_API_URL_PREFIX}/${repoName}/tarball/${branch}`; | |
const getGithubArchiveRedirectUrl = ({ repoName, branch, githubToken }) => { | |
const url = githubArchiveUrl({ repoName, branch }); | |
return fetch(url, { | |
headers: { | |
Authorization: `token ${githubToken}` | |
}, | |
redirect: 'manual' // Don't follow redirect, just want the URL | |
}).then(res => { | |
if (res.status !== 302) { | |
throw new Error(`Unexpected response for ${url} (${status})`); | |
} | |
const { headers: { _headers: { location } } } = res; | |
const [ redirectUrl ] = location || []; | |
return redirectUrl; | |
}); | |
}; | |
// To call | |
await getGithubArchiveRedirectUrl({ repoName, branch, githubToken }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment