Skip to content

Commit

Permalink
Allow to use Regex for keyword (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Oct 15, 2023
1 parent 9285350 commit 550178e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ matchBody: true
# Determines if label matching is case sensitive (optional). Defaults to true.
caseSensitive: false

# By default, the labeler looks for a specific string phrase.
# Therefore, this can create false positives like "fix" being found in "fixture".
# You can use regex instead to reduce those false positives. Defaults to false.
useRegex: false

# Explicit keyword mappings to labels. Form of match:label. Required.
labelMappings:
"[WIP]": WIP
Expand Down
16 changes: 11 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = (app, { getRouter }) => {
const config = await context.config("keylabeler.yml", {
matchTitle: true,
matchBody: true,
caseSensitive: true
caseSensitive: true,
useRegex: false,
});

if (!config) {
Expand Down Expand Up @@ -40,10 +41,15 @@ module.exports = (app, { getRouter }) => {
tokenName = tokenName.toLowerCase();
}

if (
(config.matchTitle ? fetchedTitle.includes(tokenName) : false) ||
(config.matchBody ? fetchedBody.includes(tokenName) : false)
) {
if ((
config.matchTitle &&
(config.useRegex && fetchedTitle.match(tokenName)
|| !config.useRegex && fetchedTitle.includes(tokenName))
) || (
config.matchBody &&
(config.useRegex && fetchedBody.match(tokenName)
|| !config.useRegex && fetchedBody.includes(tokenName))
)) {
labelsToAdd.push(config.labelMappings[token]);
}
}
Expand Down

0 comments on commit 550178e

Please sign in to comment.