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.
Merge pull request #1 from actions/main
- Loading branch information
Showing
10 changed files
with
1,118 additions
and
163 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 |
Large diffs are not rendered by default.
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
Large diffs are not rendered by default.
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.