fix: automerge only if every upgrade in branch is automerge

When generating a branch’s config, iterate through all upgrades and set automerge=true for the branch only if all upgrades have automerge=true. Similarly, set canBeUnpublished=true if ANY upgrade can be unPublished.

Closes #1999
This commit is contained in:
Rhys Arkins 2018-07-02 07:43:21 +02:00
parent f4f1d8871d
commit 83bf162949
4 changed files with 17 additions and 16 deletions

View file

@ -6,17 +6,14 @@ async function setUnpublishable(config) {
if (!config.unpublishSafe) {
return;
}
const canBeUnpublished = config.upgrades.some(
upgrade => upgrade.canBeUnpublished
);
const context = 'renovate/unpublish-safe';
const existingState = await platform.getBranchStatusCheck(
config.branchName,
context
);
// Set canBeUnpublished status check
const state = canBeUnpublished ? 'pending' : 'success';
const description = canBeUnpublished
const state = config.canBeUnpublished ? 'pending' : 'success';
const description = config.canBeUnpublished
? 'Packages < 24 hours old can be unpublished'
: 'Packages cannot be unpublished';
// Check if state needs setting

View file

@ -6,7 +6,7 @@ const { DateTime } = require('luxon');
function generateBranchConfig(branchUpgrades) {
logger.debug(`generateBranchConfig(${branchUpgrades.length})`);
logger.trace({ config: branchUpgrades });
const config = {
let config = {
upgrades: [],
};
const hasGroupName = branchUpgrades[0].groupName !== null;
@ -136,7 +136,12 @@ function generateBranchConfig(branchUpgrades) {
config.hasTypes = true;
}
// Now assign first upgrade's config as branch config
return { ...config, ...config.upgrades[0], releaseTimestamp };
config = { ...config, ...config.upgrades[0], releaseTimestamp };
config.canBeUnpublished = config.upgrades.some(
upgrade => upgrade.canBeUnpublished
);
config.automerge = config.upgrades.every(upgrade => upgrade.automerge);
return config;
}
module.exports = {

View file

@ -9,7 +9,6 @@ describe('workers/branch/status-checks', () => {
beforeEach(() => {
config = {
...defaultConfig,
upgrades: [],
};
});
afterEach(() => {
@ -26,21 +25,15 @@ describe('workers/branch/status-checks', () => {
expect(platform.setBranchStatus.mock.calls.length).toBe(1);
});
it('finds canBeUnpublished false and sets status', async () => {
config.canBeUnpublished = true;
config.unpublishSafe = true;
config.upgrades = [
{ canBeUnpublished: true },
{ canBeUnpublished: false },
];
await setUnpublishable(config);
expect(platform.getBranchStatusCheck.mock.calls.length).toBe(1);
expect(platform.setBranchStatus.mock.calls.length).toBe(1);
});
it('finds canBeUnpublished false and skips status', async () => {
config.unpublishSafe = true;
config.upgrades = [
{ canBeUnpublished: false },
{ canBeUnpublished: false },
];
config.canBeUnpublished = false;
platform.getBranchStatusCheck.mockReturnValueOnce('success');
await setUnpublishable(config);
expect(platform.getBranchStatusCheck.mock.calls.length).toBe(1);

View file

@ -93,6 +93,8 @@ describe('workers/repository/updates/generate', () => {
foo: 2,
},
releaseTimestamp: '2017-02-07T20:01:41+00:00',
canBeUnpublished: false,
automerge: true,
},
{
depName: 'some-other-dep',
@ -108,12 +110,16 @@ describe('workers/repository/updates/generate', () => {
foo: 2,
},
releaseTimestamp: '2017-02-06T20:01:41+00:00',
canBeUnpublished: true,
automerge: false,
},
];
const res = generateBranchConfig(branch);
expect(res.foo).toBe(2);
expect(res.groupName).toBeDefined();
expect(res.releaseTimestamp).toEqual('2017-02-07T20:01:41+00:00');
expect(res.canBeUnpublished).toBe(true);
expect(res.automerge).toBe(false);
});
it('groups multiple upgrades different version', () => {
const branch = [