mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +00:00
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:
parent
f4f1d8871d
commit
83bf162949
4 changed files with 17 additions and 16 deletions
|
@ -6,17 +6,14 @@ async function setUnpublishable(config) {
|
||||||
if (!config.unpublishSafe) {
|
if (!config.unpublishSafe) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const canBeUnpublished = config.upgrades.some(
|
|
||||||
upgrade => upgrade.canBeUnpublished
|
|
||||||
);
|
|
||||||
const context = 'renovate/unpublish-safe';
|
const context = 'renovate/unpublish-safe';
|
||||||
const existingState = await platform.getBranchStatusCheck(
|
const existingState = await platform.getBranchStatusCheck(
|
||||||
config.branchName,
|
config.branchName,
|
||||||
context
|
context
|
||||||
);
|
);
|
||||||
// Set canBeUnpublished status check
|
// Set canBeUnpublished status check
|
||||||
const state = canBeUnpublished ? 'pending' : 'success';
|
const state = config.canBeUnpublished ? 'pending' : 'success';
|
||||||
const description = canBeUnpublished
|
const description = config.canBeUnpublished
|
||||||
? 'Packages < 24 hours old can be unpublished'
|
? 'Packages < 24 hours old can be unpublished'
|
||||||
: 'Packages cannot be unpublished';
|
: 'Packages cannot be unpublished';
|
||||||
// Check if state needs setting
|
// Check if state needs setting
|
||||||
|
|
|
@ -6,7 +6,7 @@ const { DateTime } = require('luxon');
|
||||||
function generateBranchConfig(branchUpgrades) {
|
function generateBranchConfig(branchUpgrades) {
|
||||||
logger.debug(`generateBranchConfig(${branchUpgrades.length})`);
|
logger.debug(`generateBranchConfig(${branchUpgrades.length})`);
|
||||||
logger.trace({ config: branchUpgrades });
|
logger.trace({ config: branchUpgrades });
|
||||||
const config = {
|
let config = {
|
||||||
upgrades: [],
|
upgrades: [],
|
||||||
};
|
};
|
||||||
const hasGroupName = branchUpgrades[0].groupName !== null;
|
const hasGroupName = branchUpgrades[0].groupName !== null;
|
||||||
|
@ -136,7 +136,12 @@ function generateBranchConfig(branchUpgrades) {
|
||||||
config.hasTypes = true;
|
config.hasTypes = true;
|
||||||
}
|
}
|
||||||
// Now assign first upgrade's config as branch config
|
// 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 = {
|
module.exports = {
|
||||||
|
|
|
@ -9,7 +9,6 @@ describe('workers/branch/status-checks', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
config = {
|
config = {
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
upgrades: [],
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -26,21 +25,15 @@ describe('workers/branch/status-checks', () => {
|
||||||
expect(platform.setBranchStatus.mock.calls.length).toBe(1);
|
expect(platform.setBranchStatus.mock.calls.length).toBe(1);
|
||||||
});
|
});
|
||||||
it('finds canBeUnpublished false and sets status', async () => {
|
it('finds canBeUnpublished false and sets status', async () => {
|
||||||
|
config.canBeUnpublished = true;
|
||||||
config.unpublishSafe = true;
|
config.unpublishSafe = true;
|
||||||
config.upgrades = [
|
|
||||||
{ canBeUnpublished: true },
|
|
||||||
{ canBeUnpublished: false },
|
|
||||||
];
|
|
||||||
await setUnpublishable(config);
|
await setUnpublishable(config);
|
||||||
expect(platform.getBranchStatusCheck.mock.calls.length).toBe(1);
|
expect(platform.getBranchStatusCheck.mock.calls.length).toBe(1);
|
||||||
expect(platform.setBranchStatus.mock.calls.length).toBe(1);
|
expect(platform.setBranchStatus.mock.calls.length).toBe(1);
|
||||||
});
|
});
|
||||||
it('finds canBeUnpublished false and skips status', async () => {
|
it('finds canBeUnpublished false and skips status', async () => {
|
||||||
config.unpublishSafe = true;
|
config.unpublishSafe = true;
|
||||||
config.upgrades = [
|
config.canBeUnpublished = false;
|
||||||
{ canBeUnpublished: false },
|
|
||||||
{ canBeUnpublished: false },
|
|
||||||
];
|
|
||||||
platform.getBranchStatusCheck.mockReturnValueOnce('success');
|
platform.getBranchStatusCheck.mockReturnValueOnce('success');
|
||||||
await setUnpublishable(config);
|
await setUnpublishable(config);
|
||||||
expect(platform.getBranchStatusCheck.mock.calls.length).toBe(1);
|
expect(platform.getBranchStatusCheck.mock.calls.length).toBe(1);
|
||||||
|
|
|
@ -93,6 +93,8 @@ describe('workers/repository/updates/generate', () => {
|
||||||
foo: 2,
|
foo: 2,
|
||||||
},
|
},
|
||||||
releaseTimestamp: '2017-02-07T20:01:41+00:00',
|
releaseTimestamp: '2017-02-07T20:01:41+00:00',
|
||||||
|
canBeUnpublished: false,
|
||||||
|
automerge: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
depName: 'some-other-dep',
|
depName: 'some-other-dep',
|
||||||
|
@ -108,12 +110,16 @@ describe('workers/repository/updates/generate', () => {
|
||||||
foo: 2,
|
foo: 2,
|
||||||
},
|
},
|
||||||
releaseTimestamp: '2017-02-06T20:01:41+00:00',
|
releaseTimestamp: '2017-02-06T20:01:41+00:00',
|
||||||
|
canBeUnpublished: true,
|
||||||
|
automerge: false,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const res = generateBranchConfig(branch);
|
const res = generateBranchConfig(branch);
|
||||||
expect(res.foo).toBe(2);
|
expect(res.foo).toBe(2);
|
||||||
expect(res.groupName).toBeDefined();
|
expect(res.groupName).toBeDefined();
|
||||||
expect(res.releaseTimestamp).toEqual('2017-02-07T20:01:41+00:00');
|
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', () => {
|
it('groups multiple upgrades different version', () => {
|
||||||
const branch = [
|
const branch = [
|
||||||
|
|
Loading…
Reference in a new issue