This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #528 from Financial-Times/rationalise
[WIP DO NOT MERGE] Simplify nht for the proposed new Heroku build and deployment process
- Loading branch information
Showing
40 changed files
with
1,415 additions
and
1,668 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
getGithubArchiveRedirectUrl: jest.fn(() => { | ||
return Promise.resolve('https://github.com/some-tarball-link'); | ||
}) | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const HEROKU_AUTH_TOKEN = 'herokuToken123'; | ||
module.exports = () => Promise.resolve(HEROKU_AUTH_TOKEN); |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const getGithubArchiveUrl = ({ repoName, branch }) => `https://api.github.com/repos/Financial-Times/${repoName}/tarball/${branch}`; | ||
|
||
const getGithubArchiveRedirectUrl = ({ repoName, branch, githubToken }) => { | ||
const url = getGithubArchiveUrl({ repoName, branch }); | ||
|
||
return fetch(url, { | ||
headers: { | ||
Authorization: `token ${githubToken}` | ||
}, | ||
redirect: 'manual' // Don't follow redirect, just want the URL | ||
}).then(async res => { | ||
const { status } = res; | ||
if (status !== 302) { | ||
const error = await res.json(); | ||
throw new Error(`Unexpected response for ${url} (${status}): ${JSON.stringify(error)}`); | ||
} | ||
|
||
const { headers: { _headers: { location } } } = res; | ||
const [ redirectUrl ] = location || []; | ||
|
||
return redirectUrl; | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
getGithubArchiveRedirectUrl | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require('isomorphic-fetch'); | ||
const nock = require('nock'); | ||
const herokuApi = require('./heroku-api'); | ||
|
||
describe('heroku-api', () => { | ||
let nockScope; | ||
beforeAll(() => { | ||
nockScope = nock('https://api.heroku.com'); | ||
}); | ||
|
||
afterEach(() => { | ||
nock.cleanAll(); | ||
}); | ||
|
||
it('calls the endpoint', async () => { | ||
const endpoint = '/something'; | ||
nockScope.get(endpoint) | ||
.reply(200, { | ||
something: 'yes' | ||
}); | ||
const output = await herokuApi({ endpoint }); | ||
|
||
expect(output).toEqual({ | ||
something: 'yes' | ||
}); | ||
}); | ||
|
||
it('uses the auth token', async () => { | ||
const endpoint = '/'; | ||
const authToken = 'some123'; | ||
nockScope.get(endpoint) | ||
.reply(200, function () { | ||
const { headers } = this.req; | ||
return { | ||
headers | ||
}; | ||
}); | ||
const { headers: { authorization } } = await herokuApi({ endpoint, authToken }); | ||
const [ bearerToken ] = authorization; | ||
expect(bearerToken).toEqual(`Bearer ${authToken}`); | ||
}); | ||
|
||
it('throws an error on failure', async () => { | ||
const endpoint = '/'; | ||
const authToken = 'some123'; | ||
nockScope.get(endpoint) | ||
.reply(400, {}); | ||
|
||
try { | ||
await herokuApi({ endpoint, authToken }); | ||
} catch (error) { | ||
const { name, status } = error; | ||
expect(name).toEqual('BAD_RESPONSE'); | ||
expect(status).toEqual(400); | ||
}; | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
'use strict'; | ||
|
||
let shellpromise = require('shellpromise'); | ||
let authToken; | ||
|
||
module.exports = function () { | ||
const getAuthFromCli = () => { | ||
return shellpromise('heroku auth:whoami 2>/dev/null') | ||
.then(function () { | ||
return shellpromise('heroku auth:token 2>/dev/null'); | ||
}) | ||
.then(function (token) { | ||
return token.trim(); | ||
}) | ||
.catch(function (err) { | ||
console.error(err); // eslint-disable-line no-console | ||
throw new Error('Please make sure the Heroku CLI is authenticated by running `heroku auth:token`'); | ||
}); | ||
}; | ||
|
||
module.exports = async function () { | ||
if (process.env.HEROKU_AUTH_TOKEN) { | ||
|
||
return Promise.resolve(process.env.HEROKU_AUTH_TOKEN); | ||
|
||
} else { | ||
return shellpromise('heroku auth:whoami 2>/dev/null') | ||
.then(function () { | ||
return shellpromise('heroku auth:token 2>/dev/null'); | ||
}) | ||
.then(function (token) { | ||
return token.trim(); | ||
}) | ||
.catch(function (err) { | ||
console.error(err); // eslint-disable-line no-console | ||
throw new Error('Please make sure the Heroku CLI is authenticated by running `heroku auth:token`'); | ||
}); | ||
|
||
if (authToken) { | ||
return authToken; | ||
} else { | ||
authToken = await getAuthFromCli(); | ||
return authToken; | ||
} | ||
|
||
} | ||
}; |
Oops, something went wrong.