Skip to content

Commit 322ab01

Browse files
authored
Merge pull request #169 from ViliusS/fix-falsepossitive-duplicates
Use more precise match when searching for duplicate issues
2 parents a5d25ea + a8e9ea8 commit 322ab01

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/githubHelper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export class GithubHelper {
159159
owner: this.githubOwner,
160160
repo: this.githubRepo,
161161
state: 'all',
162+
labels: 'gitlab merge request',
162163
per_page: perPage,
163164
page: page,
164165
});

src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,12 @@ async function transferMergeRequests() {
561561
i => i.title.trim() === mr.title.trim()
562562
);
563563
let githubIssue = githubIssues.find(
564-
// allow for issues titled "Original Issue Name [merged]"
565-
i => i.title.trim().includes(mr.title.trim())
564+
// allow for issues titled "Original Issue Name - [merged|closed]"
565+
i => {
566+
// regex needs escaping in case merge request title contains special characters
567+
const regex = new RegExp(escapeRegExp(mr.title.trim()) + ' - \\[(merged|closed)\\]');
568+
return regex.test(i.title.trim());
569+
}
566570
);
567571
if (!githubRequest && !githubIssue) {
568572
if (settings.skipMergeRequestStates.includes(mr.state)) {
@@ -716,3 +720,7 @@ function inform(msg: string) {
716720
console.log(msg);
717721
console.log('==================================');
718722
}
723+
724+
function escapeRegExp(string) {
725+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
726+
}

0 commit comments

Comments
 (0)