mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
feat: ignore mistakenly closed PRs and recreated closed (#951)
This commit is contained in:
parent
ee44d1c3ba
commit
7c410c1283
2 changed files with 33 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
prAlreadyExisted,
|
prAlreadyExisted,
|
||||||
};
|
};
|
||||||
|
@ -14,6 +16,29 @@ async function prAlreadyExisted(config) {
|
||||||
// Check for current PR title format
|
// Check for current PR title format
|
||||||
if (await config.api.checkForClosedPr(config.branchName, config.prTitle)) {
|
if (await config.api.checkForClosedPr(config.branchName, config.prTitle)) {
|
||||||
logger.debug('Found closed PR with current title');
|
logger.debug('Found closed PR with current title');
|
||||||
|
// this code exists to ignore mistakenly closed PRs which occurred due to a bug
|
||||||
|
// TODO: Remove this by end of October 2017 or in v10
|
||||||
|
const pr = await config.api.findPr(
|
||||||
|
config.branchName,
|
||||||
|
config.prTitle,
|
||||||
|
'closed'
|
||||||
|
);
|
||||||
|
if (pr) {
|
||||||
|
const closedAt = moment(pr.closed_at);
|
||||||
|
const problemStart = moment('2017-10-15T20:00:00Z');
|
||||||
|
const problemStopped = moment('2017-10-16T06:00:00Z');
|
||||||
|
logger.info({ closedAt, problemStart, problemStopped }, 'times');
|
||||||
|
if (
|
||||||
|
problemStart.isBefore(closedAt) &&
|
||||||
|
closedAt.isBefore(problemStopped)
|
||||||
|
) {
|
||||||
|
logger.info(
|
||||||
|
{ closedAt, problemStart, problemStopped },
|
||||||
|
'Ignoring mistakenly closed PR'
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Check for legacy PR title format
|
// Check for legacy PR title format
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe('workers/branch/check-existing', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
config = {
|
config = {
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
api: { checkForClosedPr: jest.fn() },
|
api: { checkForClosedPr: jest.fn(), findPr: jest.fn() },
|
||||||
logger,
|
logger,
|
||||||
branchName: 'some-branch',
|
branchName: 'some-branch',
|
||||||
prTitle: 'some-title',
|
prTitle: 'some-title',
|
||||||
|
@ -37,5 +37,12 @@ describe('workers/branch/check-existing', () => {
|
||||||
expect(await prAlreadyExisted(config)).toBe(true);
|
expect(await prAlreadyExisted(config)).toBe(true);
|
||||||
expect(config.api.checkForClosedPr.mock.calls.length).toBe(2);
|
expect(config.api.checkForClosedPr.mock.calls.length).toBe(2);
|
||||||
});
|
});
|
||||||
|
it('returns false if mistaken', async () => {
|
||||||
|
config.api.checkForClosedPr.mockReturnValueOnce(true);
|
||||||
|
config.api.findPr.mockReturnValueOnce({
|
||||||
|
closed_at: '2017-10-15T21:28:07.000Z',
|
||||||
|
});
|
||||||
|
expect(await prAlreadyExisted(config)).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue