Add support for adding close label (#135)

This commit is contained in:
Daniel Jankowski 2020-09-08 21:32:42 +02:00 committed by GitHub
parent 23eab295e2
commit 13b324e4b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 3159 additions and 3115 deletions

View File

@ -40,8 +40,10 @@ const DefaultProcessorOptions: IssueProcessorOptions = Object.freeze({
daysBeforeStale: 1,
daysBeforeClose: 30,
staleIssueLabel: 'Stale',
closeIssueLabel: '',
exemptIssueLabels: '',
stalePrLabel: 'Stale',
closePrLabel: '',
exemptPrLabels: '',
onlyLabels: '',
operationsPerRun: 100,

View File

@ -22,12 +22,16 @@ inputs:
stale-issue-label:
description: 'The label to apply when an issue is stale.'
default: 'Stale'
close-issue-label:
description: 'The label to apply when an issue is closed.'
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")'
default: ''
stale-pr-label:
description: 'The label to apply when a pull request is stale.'
default: 'Stale'
close-pr-label:
description: 'The label to apply when a pull request is closed.'
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")'
default: ''

6208
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -40,8 +40,10 @@ export interface IssueProcessorOptions {
daysBeforeStale: number;
daysBeforeClose: number;
staleIssueLabel: string;
closeIssueLabel: string;
exemptIssueLabels: string;
stalePrLabel: string;
closePrLabel: string;
exemptPrLabels: string;
onlyLabels: string;
operationsPerRun: number;
@ -126,6 +128,9 @@ export class IssueProcessor {
const staleLabel: string = isPr
? this.options.stalePrLabel
: this.options.staleIssueLabel;
const closeLabel: string = isPr
? this.options.closePrLabel
: this.options.closeIssueLabel;
const exemptLabels = IssueProcessor.parseCommaSeparatedString(
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
);
@ -184,7 +189,8 @@ export class IssueProcessor {
issue,
issueType,
staleLabel,
closeMessage
closeMessage,
closeLabel
);
}
}
@ -203,7 +209,8 @@ export class IssueProcessor {
issue: Issue,
issueType: string,
staleLabel: string,
closeMessage?: string
closeMessage?: string,
closeLabel?: string
) {
const markedStaleOn: string =
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
@ -240,7 +247,7 @@ export class IssueProcessor {
core.info(
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
);
await this.closeIssue(issue, closeMessage);
await this.closeIssue(issue, closeMessage, closeLabel);
} else {
core.info(
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`
@ -370,7 +377,11 @@ export class IssueProcessor {
}
// Close an issue based on staleness
private async closeIssue(issue: Issue, closeMessage?: string): Promise<void> {
private async closeIssue(
issue: Issue,
closeMessage?: string,
closeLabel?: string
): Promise<void> {
core.info(
`Closing issue #${issue.number} - ${issue.title} for being stale`
);
@ -396,6 +407,19 @@ 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 {
await this.client.issues.update({
owner: context.repo.owner,

View File

@ -27,8 +27,10 @@ function getAndValidateArgs(): IssueProcessorOptions {
core.getInput('days-before-close', {required: true})
),
staleIssueLabel: core.getInput('stale-issue-label', {required: true}),
closeIssueLabel: core.getInput('close-issue-label'),
exemptIssueLabels: core.getInput('exempt-issue-labels'),
stalePrLabel: core.getInput('stale-pr-label', {required: true}),
closePrLabel: core.getInput('close-pr-label'),
exemptPrLabels: core.getInput('exempt-pr-labels'),
onlyLabels: core.getInput('only-labels'),
operationsPerRun: parseInt(