renovate/lib/workers/branch/status-checks.js
2019-08-26 08:57:52 +02:00

39 lines
1.1 KiB
JavaScript

const { logger } = require('../../logger');
const { appSlug, urls } = require('../../config/app-strings');
module.exports = {
setUnpublishable,
};
async function setStatusCheck(branchName, context, description, state) {
const existingState = await platform.getBranchStatusCheck(
branchName,
context
);
// Check if state needs setting
if (existingState === state) {
logger.debug(`Status check ${context} is already up-to-date`);
} else {
logger.debug(`Updating ${context} status check state to ${state}`);
await platform.setBranchStatus(
branchName,
context,
description,
state,
urls.documentation
);
}
}
async function setUnpublishable(config) {
if (!config.unpublishSafe) {
return;
}
const context = `${appSlug}/unpublish-safe`;
// Set canBeUnpublished status check
const state = config.canBeUnpublished ? 'pending' : 'success';
const description = config.canBeUnpublished
? 'Packages < 24 hours old can be unpublished'
: 'Packages cannot be unpublished';
await setStatusCheck(config.branchName, context, description, state);
}