Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/automations/release/utils/duplicate-pr-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
*/
const duplicateChecker = async ( context, octokit, title ) => {
const search = await octokit.search.issuesAndPullRequests( {
q: `${ title } in:title type:pr state:open repo:${ context.payload.repository.full_name }`,
q: `${ title } in:title type:pr repo:${ context.payload.repository.full_name }`,
per_page: 50,
} );

if ( search.data.total_count !== 0 ) {
const existingPr = search.data.items.find(
( pr ) => pr.title === title
);
const existingPr = search.data.items.find( ( pr ) => {
if (
pr.title !== title ||
( pr.merged === true && pr.state === 'closed' )
) {
return false;
}
return true;
} );
return existingPr;
}
};
Expand Down
36 changes: 36 additions & 0 deletions lib/automations/release/utils/test/duplicate-pr-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,40 @@ describe( 'check-for-duplicate-pull', () => {
const actual = await duplicateChecker( context, octokit, 'hello' );
expect( actual ).toBe( mock.data.items[ 0 ] );
} );
it( 'returns the pull request if the pr is closed, matches the title and is not merged', async () => {
// mocked pull
const mock = {
data: {
total_count: 1,
items: [
{
title: 'hello',
merged: false,
state: 'closed',
},
],
},
};
octokit.search.issuesAndPullRequests.mockReturnValueOnce( mock );
const actual = await duplicateChecker( context, octokit, 'hello' );
expect( actual ).toBe( mock.data.items[ 0 ] );
} );
it( 'returns undefined if the pr is closed, matches the title, and is merged', async () => {
// mocked pull
const mock = {
data: {
total_count: 1,
items: [
{
title: 'hello',
merged: true,
state: 'closed',
},
],
},
};
octokit.search.issuesAndPullRequests.mockReturnValueOnce( mock );
const actual = await duplicateChecker( context, octokit, 'hello' );
expect( actual ).toBe( undefined );
} );
} );