Skip to content
Snippets Groups Projects
Commit 19116fc6 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

refactor: remove legacy closed PR check

parent 6d9ba068
No related branches found
No related tags found
No related merge requests found
...@@ -10,32 +10,11 @@ async function prAlreadyExisted(config) { ...@@ -10,32 +10,11 @@ async function prAlreadyExisted(config) {
} }
logger.debug('recreateClosed is false'); logger.debug('recreateClosed is false');
// Return if same PR already existed // Return if same PR already existed
// Check for current PR title format const pr = await platform.findPr(config.branchName, config.prTitle, '!open');
// See #1205 for why we check for !open or closed
const statusValue =
config.packageFiles && config.packageFiles.length === 1
? '!open'
: 'closed';
let pr = await platform.findPr(
config.branchName,
config.prTitle,
statusValue
);
if (pr) { if (pr) {
logger.debug('Found closed PR with current title'); logger.debug('Found closed PR with current title');
return pr; return pr;
} }
// Check for legacy PR title format
// TODO: remove this once not found anymore
const legacyPrTitle = config.prTitle
.replace(/to v(\d+)$/, 'to version $1.x') // Major
.replace(/to v(\d+)/, 'to version $1'); // Non-major
pr = await platform.findPr(config.branchName, legacyPrTitle, statusValue);
if (pr) {
logger.info({ pr }, 'Found closed PR with legacy title');
await platform.updatePr(pr.number, config.prTitle);
return pr;
}
logger.debug('prAlreadyExisted=false'); logger.debug('prAlreadyExisted=false');
return null; return null;
} }
...@@ -19,21 +19,15 @@ describe('workers/branch/check-existing', () => { ...@@ -19,21 +19,15 @@ describe('workers/branch/check-existing', () => {
expect(await prAlreadyExisted(config)).toBe(null); expect(await prAlreadyExisted(config)).toBe(null);
expect(platform.findPr.mock.calls.length).toBe(0); expect(platform.findPr.mock.calls.length).toBe(0);
}); });
it('returns false if both checks miss', async () => { it('returns false if check misses', async () => {
config.recreatedClosed = true; config.recreatedClosed = true;
expect(await prAlreadyExisted(config)).toBe(null); expect(await prAlreadyExisted(config)).toBe(null);
expect(platform.findPr.mock.calls.length).toBe(2); expect(platform.findPr.mock.calls.length).toBe(1);
}); });
it('returns true if first check hits', async () => { it('returns true if first check hits', async () => {
platform.findPr.mockReturnValueOnce({ number: 12 }); platform.findPr.mockReturnValueOnce({ number: 12 });
expect(await prAlreadyExisted(config)).toEqual({ number: 12 }); expect(await prAlreadyExisted(config)).toEqual({ number: 12 });
expect(platform.findPr.mock.calls.length).toBe(1); expect(platform.findPr.mock.calls.length).toBe(1);
}); });
it('returns true if second check hits', async () => {
platform.findPr.mockReturnValueOnce(null);
platform.findPr.mockReturnValueOnce({ number: 13 });
expect(await prAlreadyExisted(config)).toEqual({ number: 13 });
expect(platform.findPr.mock.calls.length).toBe(2);
});
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment