renovate/lib/workers/branch/status-checks.js
Rhys Arkins ea9ace2a76 feat: branch worker updates (#736)
This is a major refactor of branch code to prepare for Yarn workspaces plus creating PRs for branches with failing lockfiles. Marked as "feature" to cause a minor version bump due to the moderate chance of accidentally breaking something.
2017-08-26 16:10:18 +02:00

50 lines
1.6 KiB
JavaScript

module.exports = {
setUnpublishable,
};
async function setUnpublishable(config) {
let unpublishable;
for (const upgrade of config.upgrades) {
if (typeof upgrade.unpublishable !== 'undefined') {
if (typeof unpublishable !== 'undefined') {
unpublishable = unpublishable && upgrade.unpublishable;
} else {
unpublishable = upgrade.unpublishable;
}
}
}
if (typeof unpublishable === 'undefined') {
unpublishable = true;
}
const context = 'renovate/unpublish-safe';
const existingState = await config.api.getBranchStatusCheck(
config.branchName,
context
);
// If status check was enabled and then is disabled, any "pending" status check needs to be set to "success"
const removeStatusCheck =
existingState === 'pending' && !config.unpublishSafe;
if (
(config.unpublishSafe || removeStatusCheck) &&
typeof unpublishable !== 'undefined'
) {
// Set unpublishable status check
const state = unpublishable || removeStatusCheck ? 'success' : 'pending';
const description = unpublishable
? 'Packages are at least 24 hours old'
: 'Packages < 24 hours old can be unpublished';
// Check if state needs setting
if (existingState === state) {
config.logger.debug('Status check is already up-to-date');
} else {
config.logger.debug(`Updating status check state to ${state}`);
await config.api.setBranchStatus(
config.branchName,
context,
description,
state,
'https://github.com/singapore/renovate/blob/master/docs/status-checks.md#unpublish-safe'
);
}
}
}