Revert "Merge pull request #586 from C0ZEN/feature/split-pr-and-issue-options"

This reverts commit db699ab3b1, reversing
changes made to b83d488cb9.
This commit is contained in:
Luke Tomlinson
2021-10-20 09:25:24 -04:00
parent fc4a5ff942
commit 3a971aeb80
23 changed files with 12014 additions and 6533 deletions

View File

@@ -3,28 +3,29 @@ import {context, getOctokit} from '@actions/github';
import {GitHub} from '@actions/github/lib/utils';
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
import {Option} from '../enums/option';
import {cleanLabel} from '../functions/clean-label';
import {getHumanizedDate} from '../functions/dates/get-humanized-date';
import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than';
import {isValidDate} from '../functions/dates/is-valid-date';
import {isBoolean} from '../functions/is-boolean';
import {isLabeled} from '../functions/is-labeled';
import {cleanLabel} from '../functions/clean-label';
import {shouldMarkWhenStale} from '../functions/should-mark-when-stale';
import {wordsToList} from '../functions/words-to-list';
import {IComment} from '../interfaces/comment';
import {IIssue} from '../interfaces/issue';
import {IIssueEvent} from '../interfaces/issue-event';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {IPullRequest} from '../interfaces/pull-request';
import {LoggerService} from '../services/logger.service';
import {Assignees} from './assignees';
import {ExemptDraftPullRequest} from './exempt-draft-pull-request';
import {IgnoreUpdates} from './ignore-updates';
import {ExemptDraftPullRequest} from './exempt-draft-pull-request';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
import {Logger} from './loggers/logger';
import {Milestones} from './milestones';
import {StaleOperations} from './stale-operations';
import {Statistics} from './statistics';
import {LoggerService} from '../services/logger.service';
import {IIssue} from '../interfaces/issue';
/***
* Handle processing of issues for staleness/closure.
@@ -206,8 +207,8 @@ export class IssuesProcessor {
? this.options.stalePrMessage.length === 0
: this.options.staleIssueMessage.length === 0;
const daysBeforeStale: number = issue.isPullRequest
? this.options.daysBeforePrStale
: this.options.daysBeforeIssueStale;
? this._getDaysBeforePrStale()
: this._getDaysBeforeIssueStale();
if (issue.state === 'closed') {
issueLogger.info(`Skipping this $$type because it is closed`);
@@ -226,7 +227,7 @@ export class IssuesProcessor {
if (onlyLabels.length > 0) {
issueLogger.info(
`The option ${issueLogger.createOptionLink(
issue.isPullRequest ? Option.OnlyPrLabels : Option.OnlyIssueLabels
Option.OnlyLabels
)} was specified to only process issues and pull requests with all those labels (${LoggerService.cyan(
onlyLabels.length
)})`
@@ -259,7 +260,7 @@ export class IssuesProcessor {
} else {
issueLogger.info(
`The option ${issueLogger.createOptionLink(
issue.isPullRequest ? Option.OnlyPrLabels : Option.OnlyIssueLabels
Option.OnlyLabels
)} was not specified`
);
issueLogger.info(
@@ -344,7 +345,7 @@ export class IssuesProcessor {
if (anyOfLabels.length > 0) {
issueLogger.info(
`The option ${issueLogger.createOptionLink(
issue.isPullRequest ? Option.AnyOfPrLabels : Option.AnyOfIssueLabels
Option.AnyOfLabels
)} was specified to only process the issues and pull requests with one of those labels (${LoggerService.cyan(
anyOfLabels.length
)})`
@@ -376,7 +377,7 @@ export class IssuesProcessor {
} else {
issueLogger.info(
`The option ${issueLogger.createOptionLink(
issue.isPullRequest ? Option.AnyOfPrLabels : Option.AnyOfIssueLabels
Option.AnyOfLabels
)} was not specified`
);
issueLogger.info(
@@ -460,7 +461,7 @@ export class IssuesProcessor {
if (shouldMarkAsStale) {
issueLogger.info(
`This $$type should be marked as stale based on the option ${issueLogger.createOptionLink(
IssuesProcessor._getDaysBeforeStaleUsedOptionName(issue)
this._getDaysBeforeStaleUsedOptionName(issue)
)} (${LoggerService.cyan(daysBeforeStale)})`
);
await this._markStale(issue, staleMessage, staleLabel, skipMessage);
@@ -469,7 +470,7 @@ export class IssuesProcessor {
} else {
issueLogger.info(
`This $$type should not be marked as stale based on the option ${issueLogger.createOptionLink(
IssuesProcessor._getDaysBeforeStaleUsedOptionName(issue)
this._getDaysBeforeStaleUsedOptionName(issue)
)} (${LoggerService.cyan(daysBeforeStale)})`
);
}
@@ -639,8 +640,8 @@ export class IssuesProcessor {
);
const daysBeforeClose: number = issue.isPullRequest
? this.options.daysBeforePrClose
: this.options.daysBeforeIssueClose;
? this._getDaysBeforePrClose()
: this._getDaysBeforeIssueClose();
issueLogger.info(
`Days before $$type close: ${LoggerService.cyan(daysBeforeClose)}`
@@ -659,7 +660,7 @@ export class IssuesProcessor {
issueLogger.info(
`The option ${issueLogger.createOptionLink(
IssuesProcessor._getRemoveStaleWhenUpdatedUsedOptionName(issue)
this._getRemoveStaleWhenUpdatedUsedOptionName(issue)
)} is: ${LoggerService.cyan(shouldRemoveStaleWhenUpdated)}`
);
@@ -956,26 +957,72 @@ export class IssuesProcessor {
}
}
private _getDaysBeforeIssueStale(): number {
return isNaN(this.options.daysBeforeIssueStale)
? this.options.daysBeforeStale
: this.options.daysBeforeIssueStale;
}
private _getDaysBeforePrStale(): number {
return isNaN(this.options.daysBeforePrStale)
? this.options.daysBeforeStale
: this.options.daysBeforePrStale;
}
private _getDaysBeforeIssueClose(): number {
return isNaN(this.options.daysBeforeIssueClose)
? this.options.daysBeforeClose
: this.options.daysBeforeIssueClose;
}
private _getDaysBeforePrClose(): number {
return isNaN(this.options.daysBeforePrClose)
? this.options.daysBeforeClose
: this.options.daysBeforePrClose;
}
private _getOnlyLabels(issue: Issue): string {
if (issue.isPullRequest) {
return this.options.onlyPrLabels;
if (this.options.onlyPrLabels !== '') {
return this.options.onlyPrLabels;
}
} else {
if (this.options.onlyIssueLabels !== '') {
return this.options.onlyIssueLabels;
}
}
return this.options.onlyIssueLabels;
return this.options.onlyLabels;
}
private _getAnyOfLabels(issue: Issue): string {
if (issue.isPullRequest) {
return this.options.anyOfPrLabels;
if (this.options.anyOfPrLabels !== '') {
return this.options.anyOfPrLabels;
}
} else {
if (this.options.anyOfIssueLabels !== '') {
return this.options.anyOfIssueLabels;
}
}
return this.options.anyOfIssueLabels;
return this.options.anyOfLabels;
}
private _shouldRemoveStaleWhenUpdated(issue: Issue): boolean {
return issue.isPullRequest
? this.options.removePrStaleWhenUpdated
: this.options.removeIssueStaleWhenUpdated;
if (issue.isPullRequest) {
if (isBoolean(this.options.removePrStaleWhenUpdated)) {
return this.options.removePrStaleWhenUpdated;
}
return this.options.removeStaleWhenUpdated;
}
if (isBoolean(this.options.removeIssueStaleWhenUpdated)) {
return this.options.removeIssueStaleWhenUpdated;
}
return this.options.removeStaleWhenUpdated;
}
private async _removeLabelsWhenUnstale(
@@ -1094,24 +1141,56 @@ export class IssuesProcessor {
}
}
private static _getDaysBeforeStaleUsedOptionName(
issue: Readonly<Issue>
): Option.DaysBeforeIssueStale | Option.DaysBeforePrStale {
return issue.isPullRequest
? Option.DaysBeforePrStale
: Option.DaysBeforeIssueStale;
}
private static _getRemoveStaleWhenUpdatedUsedOptionName(
issue: Readonly<Issue>
): Option.RemovePrStaleWhenUpdated | Option.RemoveIssueStaleWhenUpdated {
return issue.isPullRequest
? Option.RemovePrStaleWhenUpdated
: Option.RemoveIssueStaleWhenUpdated;
}
private _consumeIssueOperation(issue: Readonly<Issue>): void {
this.operations.consumeOperation();
issue.operations.consumeOperation();
}
private _getDaysBeforeStaleUsedOptionName(
issue: Readonly<Issue>
):
| Option.DaysBeforeStale
| Option.DaysBeforeIssueStale
| Option.DaysBeforePrStale {
return issue.isPullRequest
? this._getDaysBeforePrStaleUsedOptionName()
: this._getDaysBeforeIssueStaleUsedOptionName();
}
private _getDaysBeforeIssueStaleUsedOptionName():
| Option.DaysBeforeStale
| Option.DaysBeforeIssueStale {
return isNaN(this.options.daysBeforeIssueStale)
? Option.DaysBeforeStale
: Option.DaysBeforeIssueStale;
}
private _getDaysBeforePrStaleUsedOptionName():
| Option.DaysBeforeStale
| Option.DaysBeforePrStale {
return isNaN(this.options.daysBeforePrStale)
? Option.DaysBeforeStale
: Option.DaysBeforePrStale;
}
private _getRemoveStaleWhenUpdatedUsedOptionName(
issue: Readonly<Issue>
):
| Option.RemovePrStaleWhenUpdated
| Option.RemoveStaleWhenUpdated
| Option.RemoveIssueStaleWhenUpdated {
if (issue.isPullRequest) {
if (isBoolean(this.options.removePrStaleWhenUpdated)) {
return Option.RemovePrStaleWhenUpdated;
}
return Option.RemoveStaleWhenUpdated;
}
if (isBoolean(this.options.removeIssueStaleWhenUpdated)) {
return Option.RemoveIssueStaleWhenUpdated;
}
return Option.RemoveStaleWhenUpdated;
}
}