renovate/lib/workers/pr/changelog.js
2017-07-19 08:46:00 +02:00

53 lines
1.4 KiB
JavaScript

const changelog = require('changelog');
module.exports = {
getChangeLogJSON,
getMarkdown,
getChangeLog,
};
async function getChangeLogJSON(depName, fromVersion, newVersion, logger) {
logger.debug(`getChangeLogJSON(${depName}, ${fromVersion}, ${newVersion})`);
if (!fromVersion || fromVersion === newVersion) {
return null;
}
const semverString = `>${fromVersion} <=${newVersion}`;
logger.debug(`semverString: ${semverString}`);
try {
return await changelog.generate(depName, semverString);
} catch (err) {
if (
err.message &&
(err.message.indexOf('did not specify the repository url') !== -1 ||
err.message.indexOf('Unknown Github Repo') !== -1)
) {
logger.debug({ err }, `getChangeLogJSON error`);
} else {
logger.warn({ err }, `getChangeLogJSON error`);
}
return null;
}
}
function getMarkdown(changelogJSON) {
if (!changelogJSON) {
return 'No changelog available';
}
let markdownLog = changelog.markdown(changelogJSON);
markdownLog = `### Changelog\n\n${markdownLog}`;
// Fix up the markdown formatting of changelog
// This is needed for GitLab in particular
markdownLog = markdownLog.replace(/(.*?)\n[=]{10,}/g, '#### $1');
return markdownLog;
}
// Get Changelog
async function getChangeLog(depName, fromVersion, newVersion, logger) {
const logJSON = await getChangeLogJSON(
depName,
fromVersion,
newVersion,
logger
);
return getMarkdown(logJSON);
}