Add skip-stale-pr-message and skip-stale-issue-message (#119)

This introduces two new flags `skip-stale-issue-message` and `skip-stale-pr-message` which would skip the message addition if these are set to true.

They are backward compatible as empty `stale-issue-message` or `stale-pr-message` will take precedence over them
This commit is contained in:
Harshit Pant
2020-07-24 17:38:48 +05:30
committed by GitHub
parent 213e2e3dbb
commit fbaa974a12
5 changed files with 209 additions and 29 deletions

View File

@@ -50,6 +50,8 @@ export interface IssueProcessorOptions {
removeStaleWhenUpdated: boolean;
debugOnly: boolean;
ascending: boolean;
skipStaleIssueMessage: boolean;
skipStalePrMessage: boolean;
}
/***
@@ -129,6 +131,9 @@ export class IssueProcessor {
const exemptLabels = IssueProcessor.parseCommaSeparatedString(
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
);
const skipMessage = isPr
? this.options.skipStalePrMessage
: this.options.skipStaleIssueMessage;
const issueType: string = isPr ? 'pr' : 'issue';
const shouldMarkWhenStale = this.options.daysBeforeStale > -1;
@@ -170,7 +175,7 @@ export class IssueProcessor {
core.info(
`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`
);
await this.markStale(issue, staleMessage, staleLabel);
await this.markStale(issue, staleMessage, staleLabel, skipMessage);
isStale = true; // this issue is now considered stale
}
@@ -320,7 +325,8 @@ export class IssueProcessor {
private async markStale(
issue: Issue,
staleMessage: string,
staleLabel: string
staleLabel: string,
skipMessage: boolean
): Promise<void> {
core.info(`Marking issue #${issue.number} - ${issue.title} as stale`);
@@ -337,15 +343,17 @@ export class IssueProcessor {
return;
}
try {
await this.client.issues.createComment({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: issue.number,
body: staleMessage
});
} catch (error) {
core.error(`Error creating a comment: ${error.message}`);
if (!skipMessage) {
try {
await this.client.issues.createComment({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: issue.number,
body: staleMessage
});
} catch (error) {
core.error(`Error creating a comment: ${error.message}`);
}
}
try {