feat: exclude keyworlds in title before detecting

replace keyworlds with empty string

re #14
This commit is contained in:
bubkoo 2020-12-08 10:26:24 +08:00
parent 4e8f2cdc74
commit 6f12b76bf4
5 changed files with 22 additions and 2 deletions

View File

@ -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'.

View File

@ -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

View File

@ -1,7 +1,7 @@
{
"name": "potential-duplicates",
"description": "A Github Action to search for potential issue duplicates using DamerauLevenshtein algorithm.",
"version": "1.0.3",
"version": "1.0.4",
"main": "dist/index.js",
"repository": "https://github.com/bubkoo/potential-duplicates",
"author": "bubkoo <bubkoo.wy@gmail.com>",

View File

@ -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(

View File

@ -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
}
}