fix: fortify get changelog to not error

Adds check for res before res.project and wraps in try/catch so that any future errors are ignored and don’t stop the PR.

Fixes #2023
This commit is contained in:
Rhys Arkins 2018-05-26 06:58:02 +02:00
parent dbb8fac31c
commit 941d06172d

View file

@ -79,6 +79,7 @@ async function getChangeLogJSON(args) {
if ( if (
isGHE && isGHE &&
res &&
res.project && res.project &&
res.project.githubBaseURL === gheBaseURL && res.project.githubBaseURL === gheBaseURL &&
process.env.GITHUB_ENDPOINT !== endpoint process.env.GITHUB_ENDPOINT !== endpoint
@ -93,6 +94,9 @@ async function getChangeLogJSON(args) {
const output = await addReleaseNotes(res); const output = await addReleaseNotes(res);
return output; return output;
} catch (err) /* istanbul ignore next */ {
logger.error({ err, message: err.message }, 'getChangeLogJSON error');
return null;
} finally { } finally {
// wrap everything in a try/finally to ensure process.env.GITHUB_TOKEN is restored no matter if // wrap everything in a try/finally to ensure process.env.GITHUB_TOKEN is restored no matter if
// getChangeLogJSON and addReleaseNotes succed or fails // getChangeLogJSON and addReleaseNotes succed or fails