mirror of
https://github.com/actions/stale.git
synced 2025-12-31 04:18:19 +00:00
Compare commits
5 Commits
v3.0.14
...
hross-proc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcf19effbe | ||
|
|
2392a086f1 | ||
|
|
c52e87c95b | ||
|
|
990266dda6 | ||
|
|
5e528060cc |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,4 +2,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
lib/
|
lib/
|
||||||
__tests__/runner/*
|
__tests__/runner/*
|
||||||
.idea
|
|
||||||
|
|||||||
31
README.md
31
README.md
@@ -18,31 +18,6 @@ Run the tests :heavy_check_mark:
|
|||||||
```bash
|
```bash
|
||||||
$ npm test
|
$ npm test
|
||||||
```
|
```
|
||||||
### Arguments
|
|
||||||
|
|
||||||
| Input | Description | Usage |
|
|
||||||
| :---: | :---: | :---: |
|
|
||||||
| `repo-token` | PAT(Personal Access Token) for authorizing repository. | *Required* |
|
|
||||||
| `days-before-stale` | Idle number of days before marking an issue/pr as stale. *Defaults to **60*** | Optional
|
|
||||||
| `days-before-close` | Idle number of days before closing an stale issue/pr. *Defaults to **7*** | Optional
|
|
||||||
| `stale-issue-message` | Message to post on the stale issue. | Optional
|
|
||||||
| `stale-pr-message` | Message to post on the stale pr. | Optional
|
|
||||||
| `close-issue-message` | Message to post on the stale issue while closing it. | Optional
|
|
||||||
| `close-pr-message` | Message to post on the stale pr while closing it. | Optional
|
|
||||||
| `stale-issue-label` | Label to apply on the stale issue. *Defaults to **stale*** | Optional
|
|
||||||
| `close-issue-label` | Label to apply on closing issue. | Optional
|
|
||||||
| `stale-pr-label` | Label to apply on the stale pr. | Optional
|
|
||||||
| `close-pr-label` | Label to apply on the closing pr. | Optional
|
|
||||||
| `exempt-issue-labels` | Labels on an issue exempted from being marked as stale. | Optional
|
|
||||||
| `exempt-pr-labels` | Labels on the pr exempted from being marked as stale. | Optional
|
|
||||||
| `only-labels` | Only labels checked for stale issue/pr. | Optional
|
|
||||||
| `operations-per-run` | Maximum number of operations per run. *Defaults to **30*** | Optional
|
|
||||||
| `remove-stale-when-updated` | Remove stale label from issue/pr on updates or comments. *Defaults to **true*** | Optional
|
|
||||||
| `debug-only` | Dry-run on action. *Defaults to **false*** | Optional
|
|
||||||
| `ascending` | Order to get issues/pr. *Defaults to **false*** | Optional
|
|
||||||
| `skip-stale-issue-message` | Skip adding stale message on stale issue. *Defaults to **false*** | Optional
|
|
||||||
| `skip-stale-pr-message` | Skip adding stale message on stale pr. *Defaults to **false*** | Optional
|
|
||||||
|
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@@ -53,7 +28,7 @@ Basic:
|
|||||||
name: "Close stale issues"
|
name: "Close stale issues"
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "30 1 * * *"
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
@@ -71,7 +46,7 @@ Configure stale timeouts:
|
|||||||
name: "Close stale issues"
|
name: "Close stale issues"
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "30 1 * * *"
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
@@ -90,7 +65,7 @@ Configure labels:
|
|||||||
name: "Close stale issues"
|
name: "Close stale issues"
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "30 1 * * *"
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
|
|||||||
@@ -40,10 +40,8 @@ const DefaultProcessorOptions: IssueProcessorOptions = Object.freeze({
|
|||||||
daysBeforeStale: 1,
|
daysBeforeStale: 1,
|
||||||
daysBeforeClose: 30,
|
daysBeforeClose: 30,
|
||||||
staleIssueLabel: 'Stale',
|
staleIssueLabel: 'Stale',
|
||||||
closeIssueLabel: '',
|
|
||||||
exemptIssueLabels: '',
|
exemptIssueLabels: '',
|
||||||
stalePrLabel: 'Stale',
|
stalePrLabel: 'Stale',
|
||||||
closePrLabel: '',
|
|
||||||
exemptPrLabels: '',
|
exemptPrLabels: '',
|
||||||
onlyLabels: '',
|
onlyLabels: '',
|
||||||
operationsPerRun: 100,
|
operationsPerRun: 100,
|
||||||
|
|||||||
@@ -22,16 +22,12 @@ inputs:
|
|||||||
stale-issue-label:
|
stale-issue-label:
|
||||||
description: 'The label to apply when an issue is stale.'
|
description: 'The label to apply when an issue is stale.'
|
||||||
default: 'Stale'
|
default: 'Stale'
|
||||||
close-issue-label:
|
|
||||||
description: 'The label to apply when an issue is closed.'
|
|
||||||
exempt-issue-labels:
|
exempt-issue-labels:
|
||||||
description: 'The labels to apply when an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
description: 'The labels to apply when an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
||||||
default: ''
|
default: ''
|
||||||
stale-pr-label:
|
stale-pr-label:
|
||||||
description: 'The label to apply when a pull request is stale.'
|
description: 'The label to apply when a pull request is stale.'
|
||||||
default: 'Stale'
|
default: 'Stale'
|
||||||
close-pr-label:
|
|
||||||
description: 'The label to apply when a pull request is closed.'
|
|
||||||
exempt-pr-labels:
|
exempt-pr-labels:
|
||||||
description: 'The labels to apply when a pull request is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
description: 'The labels to apply when a pull request is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
||||||
default: ''
|
default: ''
|
||||||
@@ -56,6 +52,9 @@ inputs:
|
|||||||
skip-stale-issue-message:
|
skip-stale-issue-message:
|
||||||
description: 'Skip adding stale message when marking an issue as stale.'
|
description: 'Skip adding stale message when marking an issue as stale.'
|
||||||
default: false
|
default: false
|
||||||
|
process-drafts:
|
||||||
|
description: 'Should the draft PRs be marked stale? If set to true, draft PRs will be included in processing.'
|
||||||
|
default: false
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|||||||
6670
dist/index.js
vendored
6670
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -2,10 +2,10 @@ module.exports = {
|
|||||||
clearMocks: true,
|
clearMocks: true,
|
||||||
moduleFileExtensions: ['js', 'ts'],
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
testMatch: ['**/*.test.ts', '**/*.spec.ts'],
|
testMatch: ['**/*.test.ts'],
|
||||||
testRunner: 'jest-circus/runner',
|
testRunner: 'jest-circus/runner',
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.ts$': 'ts-jest'
|
'^.+\\.ts$': 'ts-jest'
|
||||||
},
|
},
|
||||||
verbose: true
|
verbose: true
|
||||||
};
|
}
|
||||||
1264
package-lock.json
generated
1264
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -9,7 +9,6 @@
|
|||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check **/*.ts",
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts",
|
||||||
"lint:fix": "eslint src/**/*.ts --fix",
|
|
||||||
"pack": "ncc build",
|
"pack": "ncc build",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
||||||
@@ -26,26 +25,24 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.4",
|
||||||
"@actions/github": "^4.0.0",
|
"@actions/github": "^4.0.0",
|
||||||
"@octokit/rest": "^18.0.9",
|
"@octokit/rest": "^18.0.4",
|
||||||
"lodash.deburr": "^4.1.0",
|
|
||||||
"semver": "^7.3.2"
|
"semver": "^7.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.15",
|
"@types/semver": "^7.3.1",
|
||||||
"@types/lodash.deburr": "^4.1.6",
|
"@types/jest": "^26.0.10",
|
||||||
"@types/node": "^14.10.0",
|
"@types/node": "^14.6.0",
|
||||||
"@types/semver": "^7.3.4",
|
"@typescript-eslint/parser": "^3.10.1",
|
||||||
"@typescript-eslint/parser": "^4.8.1",
|
"@vercel/ncc": "^0.23.0",
|
||||||
"@vercel/ncc": "^0.24.0",
|
|
||||||
"eslint": "^7.7.0",
|
"eslint": "^7.7.0",
|
||||||
"eslint-plugin-github": "^4.0.1",
|
"eslint-plugin-github": "^4.0.1",
|
||||||
"eslint-plugin-jest": "^24.1.3",
|
"eslint-plugin-jest": "^23.20.0",
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
"jest-circus": "^26.4.2",
|
"jest-circus": "^26.1.0",
|
||||||
"js-yaml": "^3.14.0",
|
"js-yaml": "^3.14.0",
|
||||||
"prettier": "^2.1.1",
|
"prettier": "^2.0.5",
|
||||||
"ts-jest": "^24.2.0",
|
"ts-jest": "^24.2.0",
|
||||||
"typescript": "^4.0.2"
|
"typescript": "^4.0.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {context, getOctokit} from '@actions/github';
|
import {context, getOctokit} from '@actions/github';
|
||||||
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
|
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
|
||||||
import {isLabeled} from './functions/is-labeled';
|
|
||||||
import {labelsToList} from './functions/labels-to-list';
|
|
||||||
|
|
||||||
export interface Issue {
|
export interface Issue {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -12,6 +10,7 @@ export interface Issue {
|
|||||||
pull_request: any;
|
pull_request: any;
|
||||||
state: string;
|
state: string;
|
||||||
locked: boolean;
|
locked: boolean;
|
||||||
|
draft: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
@@ -42,10 +41,8 @@ export interface IssueProcessorOptions {
|
|||||||
daysBeforeStale: number;
|
daysBeforeStale: number;
|
||||||
daysBeforeClose: number;
|
daysBeforeClose: number;
|
||||||
staleIssueLabel: string;
|
staleIssueLabel: string;
|
||||||
closeIssueLabel: string;
|
|
||||||
exemptIssueLabels: string;
|
exemptIssueLabels: string;
|
||||||
stalePrLabel: string;
|
stalePrLabel: string;
|
||||||
closePrLabel: string;
|
|
||||||
exemptPrLabels: string;
|
exemptPrLabels: string;
|
||||||
onlyLabels: string;
|
onlyLabels: string;
|
||||||
operationsPerRun: number;
|
operationsPerRun: number;
|
||||||
@@ -54,6 +51,7 @@ export interface IssueProcessorOptions {
|
|||||||
ascending: boolean;
|
ascending: boolean;
|
||||||
skipStaleIssueMessage: boolean;
|
skipStaleIssueMessage: boolean;
|
||||||
skipStalePrMessage: boolean;
|
skipStalePrMessage: boolean;
|
||||||
|
processDrafts: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@@ -117,7 +115,7 @@ export class IssueProcessor {
|
|||||||
const isPr = !!issue.pull_request;
|
const isPr = !!issue.pull_request;
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`Found issue: issue #${issue.number} last updated ${issue.updated_at} (is pr? ${isPr})`
|
`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`
|
||||||
);
|
);
|
||||||
|
|
||||||
// calculate string based messages for this issue
|
// calculate string based messages for this issue
|
||||||
@@ -130,10 +128,7 @@ export class IssueProcessor {
|
|||||||
const staleLabel: string = isPr
|
const staleLabel: string = isPr
|
||||||
? this.options.stalePrLabel
|
? this.options.stalePrLabel
|
||||||
: this.options.staleIssueLabel;
|
: this.options.staleIssueLabel;
|
||||||
const closeLabel: string = isPr
|
const exemptLabels = IssueProcessor.parseCommaSeparatedString(
|
||||||
? this.options.closePrLabel
|
|
||||||
: this.options.closeIssueLabel;
|
|
||||||
const exemptLabels: string[] = labelsToList(
|
|
||||||
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
|
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
|
||||||
);
|
);
|
||||||
const skipMessage = isPr
|
const skipMessage = isPr
|
||||||
@@ -157,9 +152,14 @@ export class IssueProcessor {
|
|||||||
continue; // don't process locked issues
|
continue; // don't process locked issues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (issue.draft && !this.options.processDrafts) {
|
||||||
|
core.info(`Skipping ${issueType} because it is a draft`);
|
||||||
|
continue; // don't process drafts
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
exemptLabels.some((exemptLabel: string) =>
|
exemptLabels.some((exemptLabel: string) =>
|
||||||
isLabeled(issue, exemptLabel)
|
IssueProcessor.isLabeled(issue, exemptLabel)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
core.info(`Skipping ${issueType} because it has an exempt label`);
|
core.info(`Skipping ${issueType} because it has an exempt label`);
|
||||||
@@ -167,7 +167,7 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// does this issue have a stale label?
|
// does this issue have a stale label?
|
||||||
let isStale = isLabeled(issue, staleLabel);
|
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||||
|
|
||||||
// should this issue be marked stale?
|
// should this issue be marked stale?
|
||||||
const shouldBeStale = !IssueProcessor.updatedSince(
|
const shouldBeStale = !IssueProcessor.updatedSince(
|
||||||
@@ -191,8 +191,7 @@ export class IssueProcessor {
|
|||||||
issue,
|
issue,
|
||||||
issueType,
|
issueType,
|
||||||
staleLabel,
|
staleLabel,
|
||||||
closeMessage,
|
closeMessage
|
||||||
closeLabel
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,8 +210,7 @@ export class IssueProcessor {
|
|||||||
issue: Issue,
|
issue: Issue,
|
||||||
issueType: string,
|
issueType: string,
|
||||||
staleLabel: string,
|
staleLabel: string,
|
||||||
closeMessage?: string,
|
closeMessage?: string
|
||||||
closeLabel?: string
|
|
||||||
) {
|
) {
|
||||||
const markedStaleOn: string =
|
const markedStaleOn: string =
|
||||||
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
||||||
@@ -249,10 +247,10 @@ export class IssueProcessor {
|
|||||||
core.info(
|
core.info(
|
||||||
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
||||||
);
|
);
|
||||||
await this.closeIssue(issue, closeMessage, closeLabel);
|
await this.closeIssue(issue, closeMessage);
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
core.info(
|
||||||
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate})`
|
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,7 +277,7 @@ export class IssueProcessor {
|
|||||||
);
|
);
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`Comments not made by actor or another bot: ${filteredComments.length}`
|
`Comments not made by ${context.actor} or another bot: ${filteredComments.length}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// if there are any user comments returned
|
// if there are any user comments returned
|
||||||
@@ -324,6 +322,8 @@ export class IssueProcessor {
|
|||||||
page
|
page
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
core.info(`issue data: ${JSON.stringify(issueResult.data)}`);
|
||||||
return issueResult.data;
|
return issueResult.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(`Get issues for repo error: ${error.message}`);
|
core.error(`Get issues for repo error: ${error.message}`);
|
||||||
@@ -338,7 +338,7 @@ export class IssueProcessor {
|
|||||||
staleLabel: string,
|
staleLabel: string,
|
||||||
skipMessage: boolean
|
skipMessage: boolean
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
core.info(`Marking issue #${issue.number} as stale`);
|
core.info(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||||
|
|
||||||
this.staleIssues.push(issue);
|
this.staleIssues.push(issue);
|
||||||
|
|
||||||
@@ -379,12 +379,10 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close an issue based on staleness
|
// Close an issue based on staleness
|
||||||
private async closeIssue(
|
private async closeIssue(issue: Issue, closeMessage?: string): Promise<void> {
|
||||||
issue: Issue,
|
core.info(
|
||||||
closeMessage?: string,
|
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
||||||
closeLabel?: string
|
);
|
||||||
): Promise<void> {
|
|
||||||
core.info(`Closing issue #${issue.number} for being stale`);
|
|
||||||
|
|
||||||
this.closedIssues.push(issue);
|
this.closedIssues.push(issue);
|
||||||
|
|
||||||
@@ -407,19 +405,6 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closeLabel) {
|
|
||||||
try {
|
|
||||||
await this.client.issues.addLabels({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
issue_number: issue.number,
|
|
||||||
labels: [closeLabel]
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
core.error(`Error adding a label: ${error.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.client.issues.update({
|
await this.client.issues.update({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
@@ -434,7 +419,9 @@ export class IssueProcessor {
|
|||||||
|
|
||||||
// Remove a label from an issue
|
// Remove a label from an issue
|
||||||
private async removeLabel(issue: Issue, label: string): Promise<void> {
|
private async removeLabel(issue: Issue, label: string): Promise<void> {
|
||||||
core.info(`Removing label from issue #${issue.number}`);
|
core.info(
|
||||||
|
`Removing label ${label} from issue #${issue.number} - ${issue.title}`
|
||||||
|
);
|
||||||
|
|
||||||
this.removedLabelIssues.push(issue);
|
this.removedLabelIssues.push(issue);
|
||||||
|
|
||||||
@@ -462,7 +449,7 @@ export class IssueProcessor {
|
|||||||
issue: Issue,
|
issue: Issue,
|
||||||
label: string
|
label: string
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
core.info(`Checking for label on issue #${issue.number}`);
|
core.info(`Checking for label ${label} on issue #${issue.number}`);
|
||||||
|
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
@@ -488,6 +475,12 @@ export class IssueProcessor {
|
|||||||
return staleLabeledEvent.created_at;
|
return staleLabeledEvent.created_at;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static isLabeled(issue: Issue, label: string): boolean {
|
||||||
|
const labelComparer: (l: Label) => boolean = l =>
|
||||||
|
label.localeCompare(l.name, undefined, {sensitivity: 'accent'}) === 0;
|
||||||
|
return issue.labels.filter(labelComparer).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static updatedSince(timestamp: string, num_days: number): boolean {
|
private static updatedSince(timestamp: string, num_days: number): boolean {
|
||||||
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
||||||
const millisSinceLastUpdated =
|
const millisSinceLastUpdated =
|
||||||
@@ -495,4 +488,11 @@ export class IssueProcessor {
|
|||||||
|
|
||||||
return millisSinceLastUpdated <= daysInMillis;
|
return millisSinceLastUpdated <= daysInMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static parseCommaSeparatedString(s: string): string[] {
|
||||||
|
// String.prototype.split defaults to [''] when called on an empty string
|
||||||
|
// In this case, we'd prefer to just return an empty array indicating no labels
|
||||||
|
if (!s.length) return [];
|
||||||
|
return s.split(',').map(l => l.trim());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,187 +0,0 @@
|
|||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
@@ -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());
|
|
||||||
}
|
|
||||||
@@ -27,10 +27,8 @@ function getAndValidateArgs(): IssueProcessorOptions {
|
|||||||
core.getInput('days-before-close', {required: true})
|
core.getInput('days-before-close', {required: true})
|
||||||
),
|
),
|
||||||
staleIssueLabel: core.getInput('stale-issue-label', {required: true}),
|
staleIssueLabel: core.getInput('stale-issue-label', {required: true}),
|
||||||
closeIssueLabel: core.getInput('close-issue-label'),
|
|
||||||
exemptIssueLabels: core.getInput('exempt-issue-labels'),
|
exemptIssueLabels: core.getInput('exempt-issue-labels'),
|
||||||
stalePrLabel: core.getInput('stale-pr-label', {required: true}),
|
stalePrLabel: core.getInput('stale-pr-label', {required: true}),
|
||||||
closePrLabel: core.getInput('close-pr-label'),
|
|
||||||
exemptPrLabels: core.getInput('exempt-pr-labels'),
|
exemptPrLabels: core.getInput('exempt-pr-labels'),
|
||||||
onlyLabels: core.getInput('only-labels'),
|
onlyLabels: core.getInput('only-labels'),
|
||||||
operationsPerRun: parseInt(
|
operationsPerRun: parseInt(
|
||||||
@@ -42,7 +40,8 @@ function getAndValidateArgs(): IssueProcessorOptions {
|
|||||||
debugOnly: core.getInput('debug-only') === 'true',
|
debugOnly: core.getInput('debug-only') === 'true',
|
||||||
ascending: core.getInput('ascending') === 'true',
|
ascending: core.getInput('ascending') === 'true',
|
||||||
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
|
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
|
||||||
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true'
|
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true',
|
||||||
|
processDrafts: core.getInput('process-drafts') === 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const numberInput of [
|
for (const numberInput of [
|
||||||
|
|||||||
Reference in New Issue
Block a user