mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
fix: create Pr if prNotPending hours exceeded for branch automerge
This commit is contained in:
parent
6478f3c53d
commit
b1da837da1
2 changed files with 24 additions and 0 deletions
|
@ -30,6 +30,19 @@ async function ensurePr(prConfig) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`Branch is configured for branch automerge, branchStatus is: ${branchStatus}`
|
`Branch is configured for branch automerge, branchStatus is: ${branchStatus}`
|
||||||
);
|
);
|
||||||
|
if (branchStatus === 'pending' || branchStatus === 'running') {
|
||||||
|
logger.debug('Checking how long this branch has been pending');
|
||||||
|
const lastCommitTime = await platform.getBranchLastCommitTime(branchName);
|
||||||
|
const currentTime = new Date();
|
||||||
|
const millisecondsPerHour = 1000 * 60 * 60;
|
||||||
|
const elapsedHours = Math.round(
|
||||||
|
(currentTime.getTime() - lastCommitTime.getTime()) / millisecondsPerHour
|
||||||
|
);
|
||||||
|
if (elapsedHours >= config.prNotPendingHours) {
|
||||||
|
logger.info('Branch exceeds prNotPending hours - forcing PR creation');
|
||||||
|
config.forcePr = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (config.forcePr || branchStatus === 'failure') {
|
if (config.forcePr || branchStatus === 'failure') {
|
||||||
logger.debug(`Branch tests failed, so will create PR`);
|
logger.debug(`Branch tests failed, so will create PR`);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -300,9 +300,20 @@ describe('workers/pr', () => {
|
||||||
config.automerge = true;
|
config.automerge = true;
|
||||||
config.automergeType = 'branch-push';
|
config.automergeType = 'branch-push';
|
||||||
platform.getBranchStatus.mockReturnValueOnce('pending');
|
platform.getBranchStatus.mockReturnValueOnce('pending');
|
||||||
|
platform.getBranchLastCommitTime.mockReturnValueOnce(new Date());
|
||||||
const pr = await prWorker.ensurePr(config);
|
const pr = await prWorker.ensurePr(config);
|
||||||
expect(pr).toBe(null);
|
expect(pr).toBe(null);
|
||||||
});
|
});
|
||||||
|
it('should not return null if branch automerging taking too long', async () => {
|
||||||
|
config.automerge = true;
|
||||||
|
config.automergeType = 'branch-push';
|
||||||
|
platform.getBranchStatus.mockReturnValueOnce('pending');
|
||||||
|
platform.getBranchLastCommitTime.mockReturnValueOnce(
|
||||||
|
new Date('2018-01-01')
|
||||||
|
);
|
||||||
|
const pr = await prWorker.ensurePr(config);
|
||||||
|
expect(pr).not.toBe(null);
|
||||||
|
});
|
||||||
it('handles duplicate upgrades', async () => {
|
it('handles duplicate upgrades', async () => {
|
||||||
config.upgrades.push(config.upgrades[0]);
|
config.upgrades.push(config.upgrades[0]);
|
||||||
const pr = await prWorker.ensurePr(config);
|
const pr = await prWorker.ensurePr(config);
|
||||||
|
|
Loading…
Reference in a new issue