forked from actions/stale
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(label): allow to use spaces inside the labels (actions#199)
* chore(git): ignore .idea folder to avoid adding WebStorm files * test(jest): find all spec files as well * refactor(labels): create a dedicated function to parse the labels at first I thought that the parseCommaSeparatedString method was causing the issue so I move it to a dedicated file to test it since it was private also because I think that this repo could have more clean code and code splitting anyway this was not the root of the actions#98 issue :/ * fix(label): allow to use spaces inside the labels * docs(isLabeled): add JSDoc * chore(npm): add lint:fix script
- Loading branch information
Showing
9 changed files
with
407 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
node_modules/ | ||
lib/ | ||
__tests__/runner/* | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
import {Issue} from '../IssueProcessor'; | ||
import {isLabeled} from './is-labeled'; | ||
|
||
describe('isLabeled()', (): void => { | ||
let issue: Issue; | ||
let label: string; | ||
|
||
describe('when the given issue contains no label', (): void => { | ||
beforeEach((): void => { | ||
issue = ({ | ||
labels: [] | ||
} as unknown) as Issue; | ||
}); | ||
|
||
describe('when the given label is a simple label', (): void => { | ||
beforeEach((): void => { | ||
label = 'label'; | ||
}); | ||
|
||
it('should return false', (): void => { | ||
expect.assertions(1); | ||
|
||
const result = isLabeled(issue, label); | ||
|
||
expect(result).toStrictEqual(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the given issue contains a simple label', (): void => { | ||
beforeEach((): void => { | ||
issue = { | ||
labels: [ | ||
{ | ||
name: 'label' | ||
} | ||
] | ||
} as Issue; | ||
}); | ||
|
||
describe('when the given label is a simple label', (): void => { | ||
beforeEach((): void => { | ||
label = 'label'; | ||
}); | ||
|
||
it('should return true', (): void => { | ||
expect.assertions(1); | ||
|
||
const result = isLabeled(issue, label); | ||
|
||
expect(result).toStrictEqual(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the given issue contains a kebab case label', (): void => { | ||
beforeEach((): void => { | ||
issue = { | ||
labels: [ | ||
{ | ||
name: 'kebab-case-label' | ||
} | ||
] | ||
} as Issue; | ||
}); | ||
|
||
describe('when the given label is a kebab case label', (): void => { | ||
beforeEach((): void => { | ||
label = 'kebab-case-label'; | ||
}); | ||
|
||
it('should return true', (): void => { | ||
expect.assertions(1); | ||
|
||
const result = isLabeled(issue, label); | ||
|
||
expect(result).toStrictEqual(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the given issue contains a multiple word label', (): void => { | ||
beforeEach((): void => { | ||
issue = { | ||
labels: [ | ||
{ | ||
name: 'label like a sentence' | ||
} | ||
] | ||
} as Issue; | ||
}); | ||
|
||
describe('when the given label is a multiple word label', (): void => { | ||
beforeEach((): void => { | ||
label = 'label like a sentence'; | ||
}); | ||
|
||
it('should return true', (): void => { | ||
expect.assertions(1); | ||
|
||
const result = isLabeled(issue, label); | ||
|
||
expect(result).toStrictEqual(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the given issue contains a multiple word label with %20 spaces', (): void => { | ||
beforeEach((): void => { | ||
issue = { | ||
labels: [ | ||
{ | ||
name: 'label%20like%20a%20sentence' | ||
} | ||
] | ||
} as Issue; | ||
}); | ||
|
||
describe('when the given label is a multiple word label with %20 spaces', (): void => { | ||
beforeEach((): void => { | ||
label = 'label%20like%20a%20sentence'; | ||
}); | ||
|
||
it('should return true', (): void => { | ||
expect.assertions(1); | ||
|
||
const result = isLabeled(issue, label); | ||
|
||
expect(result).toStrictEqual(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the given issue contains a label wih diacritical marks', (): void => { | ||
beforeEach((): void => { | ||
issue = { | ||
labels: [ | ||
{ | ||
name: 'déjà vu' | ||
} | ||
] | ||
} as Issue; | ||
}); | ||
|
||
describe('when the given issue contains a label', (): void => { | ||
beforeEach((): void => { | ||
label = 'deja vu'; | ||
}); | ||
|
||
it('should return true', (): void => { | ||
expect.assertions(1); | ||
|
||
const result = isLabeled(issue, label); | ||
|
||
expect(result).toStrictEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when the given issue contains an uppercase label', (): void => { | ||
beforeEach((): void => { | ||
label = 'DEJA VU'; | ||
}); | ||
|
||
it('should return true', (): void => { | ||
expect.assertions(1); | ||
|
||
const result = isLabeled(issue, label); | ||
|
||
expect(result).toStrictEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when the given issue contains a label wih diacritical marks', (): void => { | ||
beforeEach((): void => { | ||
label = 'déjà vu'; | ||
}); | ||
|
||
it('should return true', (): void => { | ||
expect.assertions(1); | ||
|
||
const result = isLabeled(issue, label); | ||
|
||
expect(result).toStrictEqual(true); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import deburr from 'lodash.deburr'; | ||
import {Issue, Label} from '../IssueProcessor'; | ||
|
||
/** | ||
* @description | ||
* Check if the label is listed as a label of the issue | ||
* | ||
* @param {Readonly<Issue>} issue A GitHub issue containing some labels | ||
* @param {Readonly<string>} label The label to check the presence with | ||
* | ||
* @return {boolean} Return true when the given label is also in the issue labels | ||
*/ | ||
export function isLabeled( | ||
issue: Readonly<Issue>, | ||
label: Readonly<string> | ||
): boolean { | ||
return !!issue.labels.find((issueLabel: Readonly<Label>): boolean => { | ||
return cleanLabel(label) === cleanLabel(issueLabel.name); | ||
}); | ||
} | ||
|
||
function cleanLabel(label: Readonly<string>): string { | ||
return deburr(label.toLowerCase()); | ||
} |
Oops, something went wrong.