mirror of
https://github.com/actions/stale.git
synced 2025-12-20 06:42:15 +00:00
feat(exempt): add new options to exempt the milestones (#279)
* feat(exempt): add new options to exempt the milestones closes #270 * test(milestones): add coverage * test(issue): add coverage * chore(rebase): fix all errors due to the rebase also made some changes regarding the change I made with the lint scripts and prettier. I did not saw that some scripts were already here and I created to more to keep the old ones as well * test(milestone): add coverage * chore(index): update index * fix(checks): remove checks over optional number options the code was actually handling the case where the values are NaN so it's fine
This commit is contained in:
committed by
GitHub
parent
1b9f13b607
commit
f71123a6f7
@@ -1,4 +1,4 @@
|
||||
import {Issue} from '../IssueProcessor';
|
||||
import {Issue} from '../classes/issue';
|
||||
import {isLabeled} from './is-labeled';
|
||||
|
||||
describe('isLabeled()', (): void => {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import deburr from 'lodash.deburr';
|
||||
import {Issue, Label} from '../IssueProcessor';
|
||||
import {Issue} from '../classes/issue';
|
||||
import {Label} from '../IssueProcessor';
|
||||
import {CleanLabel} from '../types/clean-label';
|
||||
|
||||
/**
|
||||
* @description
|
||||
* Check if the label is listed as a label of the issue
|
||||
* Check if the given label is listed as a label of the given 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
|
||||
* @return {boolean} Return true when the given label is also in the given issue labels
|
||||
*/
|
||||
export function isLabeled(
|
||||
issue: Readonly<Issue>,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Issue} from '../IssueProcessor';
|
||||
import {Issue} from '../classes/issue';
|
||||
import {isPullRequest} from './is-pull-request';
|
||||
|
||||
describe('isPullRequest()', (): void => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Issue} from '../IssueProcessor';
|
||||
import {Issue} from '../classes/issue';
|
||||
|
||||
export function isPullRequest(issue: Readonly<Issue>): boolean {
|
||||
return !!issue.pull_request;
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
import {labelsToList} from './labels-to-list';
|
||||
|
||||
describe('labelsToList()', (): void => {
|
||||
let labels: string;
|
||||
|
||||
describe('when the given labels is empty', (): void => {
|
||||
beforeEach((): void => {
|
||||
labels = '';
|
||||
});
|
||||
|
||||
it('should return an empty list of labels', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = labelsToList(labels);
|
||||
|
||||
expect(result).toStrictEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given labels is a simple label', (): void => {
|
||||
beforeEach((): void => {
|
||||
labels = 'label';
|
||||
});
|
||||
|
||||
it('should return a list of one label', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = labelsToList(labels);
|
||||
|
||||
expect(result).toStrictEqual(['label']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given labels is a label with extra spaces before and after', (): void => {
|
||||
beforeEach((): void => {
|
||||
labels = ' label ';
|
||||
});
|
||||
|
||||
it('should return a list of one label and remove all spaces before and after', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = labelsToList(labels);
|
||||
|
||||
expect(result).toStrictEqual(['label']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given labels is a kebab case label', (): void => {
|
||||
beforeEach((): void => {
|
||||
labels = 'kebab-case-label';
|
||||
});
|
||||
|
||||
it('should return a list of one label', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = labelsToList(labels);
|
||||
|
||||
expect(result).toStrictEqual(['kebab-case-label']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given labels is two kebab case labels separated with a comma', (): void => {
|
||||
beforeEach((): void => {
|
||||
labels = 'kebab-case-label-1,kebab-case-label-2';
|
||||
});
|
||||
|
||||
it('should return a list of two labels', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = labelsToList(labels);
|
||||
|
||||
expect(result).toStrictEqual([
|
||||
'kebab-case-label-1',
|
||||
'kebab-case-label-2'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given labels is a multiple word label', (): void => {
|
||||
beforeEach((): void => {
|
||||
labels = 'label like a sentence';
|
||||
});
|
||||
|
||||
it('should return a list of one label', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = labelsToList(labels);
|
||||
|
||||
expect(result).toStrictEqual(['label like a sentence']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given labels is two multiple word labels separated with a comma', (): void => {
|
||||
beforeEach((): void => {
|
||||
labels = 'label like a sentence, another label like a sentence';
|
||||
});
|
||||
|
||||
it('should return a list of two labels', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = labelsToList(labels);
|
||||
|
||||
expect(result).toStrictEqual([
|
||||
'label like a sentence',
|
||||
'another label like a sentence'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given labels is a multiple word label with %20 spaces', (): void => {
|
||||
beforeEach((): void => {
|
||||
labels = 'label%20like%20a%20sentence';
|
||||
});
|
||||
|
||||
it('should return a list of one label', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = labelsToList(labels);
|
||||
|
||||
expect(result).toStrictEqual(['label%20like%20a%20sentence']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given labels is two multiple word labels with %20 spaces separated with a comma', (): void => {
|
||||
beforeEach((): void => {
|
||||
labels =
|
||||
'label%20like%20a%20sentence,another%20label%20like%20a%20sentence';
|
||||
});
|
||||
|
||||
it('should return a list of two labels', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = labelsToList(labels);
|
||||
|
||||
expect(result).toStrictEqual([
|
||||
'label%20like%20a%20sentence',
|
||||
'another%20label%20like%20a%20sentence'
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,23 +0,0 @@
|
||||
/**
|
||||
* @description
|
||||
* Transform a string of comma separated labels
|
||||
* to an array of labels
|
||||
*
|
||||
* @example
|
||||
* labelsToList('label') => ['label']
|
||||
* labelsToList('label,label') => ['label', 'label']
|
||||
* labelsToList('kebab-label') => ['kebab-label']
|
||||
* labelsToList('kebab%20label') => ['kebab%20label']
|
||||
* labelsToList('label with words') => ['label with words']
|
||||
*
|
||||
* @param {Readonly<string>} labels A string of comma separated labels
|
||||
*
|
||||
* @return {string[]} A list of labels
|
||||
*/
|
||||
export function labelsToList(labels: Readonly<string>): string[] {
|
||||
if (!labels.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return labels.split(',').map(l => l.trim());
|
||||
}
|
||||
137
src/functions/words-to-list.spec.ts
Normal file
137
src/functions/words-to-list.spec.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
import {wordsToList} from './words-to-list';
|
||||
|
||||
describe('wordsToList()', (): void => {
|
||||
let words: string;
|
||||
|
||||
describe('when the given words is empty', (): void => {
|
||||
beforeEach((): void => {
|
||||
words = '';
|
||||
});
|
||||
|
||||
it('should return an empty list of words', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = wordsToList(words);
|
||||
|
||||
expect(result).toStrictEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given words is a simple word', (): void => {
|
||||
beforeEach((): void => {
|
||||
words = 'word';
|
||||
});
|
||||
|
||||
it('should return a list of one word', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = wordsToList(words);
|
||||
|
||||
expect(result).toStrictEqual(['word']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given words is a word with extra spaces before and after', (): void => {
|
||||
beforeEach((): void => {
|
||||
words = ' word ';
|
||||
});
|
||||
|
||||
it('should return a list of one word and remove all spaces before and after', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = wordsToList(words);
|
||||
|
||||
expect(result).toStrictEqual(['word']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given words is a kebab case word', (): void => {
|
||||
beforeEach((): void => {
|
||||
words = 'kebab-case-word';
|
||||
});
|
||||
|
||||
it('should return a list of one word', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = wordsToList(words);
|
||||
|
||||
expect(result).toStrictEqual(['kebab-case-word']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given words is two kebab case words separated with a comma', (): void => {
|
||||
beforeEach((): void => {
|
||||
words = 'kebab-case-word-1,kebab-case-word-2';
|
||||
});
|
||||
|
||||
it('should return a list of two words', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = wordsToList(words);
|
||||
|
||||
expect(result).toStrictEqual(['kebab-case-word-1', 'kebab-case-word-2']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given words is a multiple word word', (): void => {
|
||||
beforeEach((): void => {
|
||||
words = 'word like a sentence';
|
||||
});
|
||||
|
||||
it('should return a list of one word', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = wordsToList(words);
|
||||
|
||||
expect(result).toStrictEqual(['word like a sentence']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given words is two multiple word words separated with a comma', (): void => {
|
||||
beforeEach((): void => {
|
||||
words = 'word like a sentence, another word like a sentence';
|
||||
});
|
||||
|
||||
it('should return a list of two words', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = wordsToList(words);
|
||||
|
||||
expect(result).toStrictEqual([
|
||||
'word like a sentence',
|
||||
'another word like a sentence'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given words is a multiple word word with %20 spaces', (): void => {
|
||||
beforeEach((): void => {
|
||||
words = 'word%20like%20a%20sentence';
|
||||
});
|
||||
|
||||
it('should return a list of one word', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = wordsToList(words);
|
||||
|
||||
expect(result).toStrictEqual(['word%20like%20a%20sentence']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given words is two multiple word words with %20 spaces separated with a comma', (): void => {
|
||||
beforeEach((): void => {
|
||||
words = 'word%20like%20a%20sentence,another%20word%20like%20a%20sentence';
|
||||
});
|
||||
|
||||
it('should return a list of two words', (): void => {
|
||||
expect.assertions(1);
|
||||
|
||||
const result = wordsToList(words);
|
||||
|
||||
expect(result).toStrictEqual([
|
||||
'word%20like%20a%20sentence',
|
||||
'another%20word%20like%20a%20sentence'
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
23
src/functions/words-to-list.ts
Normal file
23
src/functions/words-to-list.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @description
|
||||
* Transform a string of comma separated words
|
||||
* to an array of words
|
||||
*
|
||||
* @example
|
||||
* wordsToList('label') => ['label']
|
||||
* wordsToList('label,label') => ['label', 'label']
|
||||
* wordsToList('kebab-label') => ['kebab-label']
|
||||
* wordsToList('kebab%20label') => ['kebab%20label']
|
||||
* wordsToList('label with words') => ['label with words']
|
||||
*
|
||||
* @param {Readonly<string>} words A string of comma separated words
|
||||
*
|
||||
* @return {string[]} A list of words
|
||||
*/
|
||||
export function wordsToList(words: Readonly<string>): string[] {
|
||||
if (!words.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return words.split(',').map((word: Readonly<string>): string => word.trim());
|
||||
}
|
||||
Reference in New Issue
Block a user