Skip to content

Commit 6ce8e94

Browse files
committed
Use more precise match when searching for duplicate issues
This fixes migration issues when GitHub repository already has an issue with similar but different title.
1 parent 7e056e2 commit 6ce8e94

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,12 @@ async function transferMergeRequests() {
524524
i => i.title.trim() === mr.title.trim()
525525
);
526526
let githubIssue = githubIssues.find(
527-
// allow for issues titled "Original Issue Name [merged]"
528-
i => i.title.trim().includes(mr.title.trim())
527+
// allow for issues titled "Original Issue Name - [merged|closed]"
528+
i => {
529+
// regex needs escaping in case merge request title contains special characters
530+
const regex = new RegExp(escapeRegExp(mr.title.trim()) + ' - \\[(merged|closed)\\]');
531+
return regex.test(i.title.trim());
532+
}
529533
);
530534
if (!githubRequest && !githubIssue) {
531535
if (settings.skipMergeRequestStates.includes(mr.state)) {
@@ -679,3 +683,7 @@ function inform(msg: string) {
679683
console.log(msg);
680684
console.log('==================================');
681685
}
686+
687+
function escapeRegExp(string) {
688+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
689+
}

0 commit comments

Comments
 (0)