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, 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,

View File

@ -22,12 +22,16 @@ 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: ''

6234
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; 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;
@ -126,6 +128,9 @@ 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
? this.options.closePrLabel
: this.options.closeIssueLabel;
const exemptLabels = IssueProcessor.parseCommaSeparatedString( const exemptLabels = IssueProcessor.parseCommaSeparatedString(
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
); );
@ -184,7 +189,8 @@ export class IssueProcessor {
issue, issue,
issueType, issueType,
staleLabel, staleLabel,
closeMessage closeMessage,
closeLabel
); );
} }
} }
@ -203,7 +209,8 @@ 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;
@ -240,7 +247,7 @@ 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); await this.closeIssue(issue, closeMessage, closeLabel);
} 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}`
@ -370,7 +377,11 @@ export class IssueProcessor {
} }
// Close an issue based on staleness // 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( core.info(
`Closing issue #${issue.number} - ${issue.title} for being stale` `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 { try {
await this.client.issues.update({ await this.client.issues.update({
owner: context.repo.owner, owner: context.repo.owner,

View File

@ -27,8 +27,10 @@ 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(