From 6f12b76bf4d1427f86cf3cd403bab843ea16d669 Mon Sep 17 00:00:00 2001 From: bubkoo Date: Tue, 8 Dec 2020 10:26:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20exclude=20keyworlds=20in=20?= =?UTF-8?q?title=20before=20detecting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit replace keyworlds with empty string re #14 --- README.md | 2 ++ action.yml | 3 +++ package.json | 2 +- src/action.ts | 5 ++++- src/util.ts | 12 ++++++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f6cc35..b54136b 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ jobs: # Any matched issue will stop detection immediately. # You can specify multi filters in each line. filter: '' + # Exclude keyworlds in title before detecting. + exclude: '' # Label to set, when potential duplicates are detected. label: potential-duplicate # Get issues with state to compare. Supported state: 'all', 'closed', 'open'. diff --git a/action.yml b/action.yml index 712cf44..e4988cf 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,9 @@ inputs: filter: description: Filter issues by title. required: false + exclude: + description: Exclude keyworlds in title before detecting. + required: false label: description: Label to set, when potential duplicates are detected. default: potential-duplicate diff --git a/package.json b/package.json index 7dc7094..b8c2065 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "potential-duplicates", "description": "A Github Action to search for potential issue duplicates using Damerau–Levenshtein algorithm.", - "version": "1.0.3", + "version": "1.0.4", "main": "dist/index.js", "repository": "https://github.com/bubkoo/potential-duplicates", "author": "bubkoo ", diff --git a/src/action.ts b/src/action.ts index cc770a1..61ace49 100644 --- a/src/action.ts +++ b/src/action.ts @@ -26,7 +26,10 @@ export namespace Action { const threshold = parseFloat(core.getInput('threshold')) for (const issue of issues) { - const accuracy = Algo.compare(issue.title, title) + const accuracy = Algo.compare( + Util.formatTitle(issue.title), + Util.formatTitle(title), + ) core.debug( `${issue.title} ~ ${title} = ${parseFloat( diff --git a/src/util.ts b/src/util.ts index ae5412f..42dbce0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -36,4 +36,16 @@ export namespace Util { } return true } + + export function formatTitle(title: string) { + const exclude = core.getInput('exclude') + if (exclude) { + return exclude + .split(/[\s\n]+/) + .map((keyworld) => keyworld.trim()) + .filter((keyworld) => keyworld.length > 0) + .reduce((memo, keyworld) => memo.replace(keyworld, ' '), title) + } + return title + } }