mirror of
https://github.com/actions/stale.git
synced 2025-12-13 21:53:25 +00:00
feat(draft-pr): add new option to not process PRs which are in draft (#539)
* chore(assignees): add logs * feat(draft-pr): add new option to not process PRs which are in draft * refactor(draft-pr): create a dedicated class to handle the logic * chore(index): update index file
This commit is contained in:
committed by
GitHub
parent
303465a5d2
commit
9912fa74d1
51
src/classes/exempt-draft-pull-request.ts
Normal file
51
src/classes/exempt-draft-pull-request.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import {Option} from '../enums/option';
|
||||
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
|
||||
import {IPullRequest} from '../interfaces/pull-request';
|
||||
import {LoggerService} from '../services/logger.service';
|
||||
import {Issue} from './issue';
|
||||
import {IssueLogger} from './loggers/issue-logger';
|
||||
|
||||
export class ExemptDraftPullRequest {
|
||||
private readonly _options: IIssuesProcessorOptions;
|
||||
private readonly _issue: Issue;
|
||||
private readonly _issueLogger: IssueLogger;
|
||||
|
||||
constructor(options: Readonly<IIssuesProcessorOptions>, issue: Issue) {
|
||||
this._options = options;
|
||||
this._issue = issue;
|
||||
this._issueLogger = new IssueLogger(issue);
|
||||
}
|
||||
|
||||
async shouldExemptDraftPullRequest(
|
||||
pullRequestCallback: () => Promise<IPullRequest | undefined | void>
|
||||
): Promise<boolean> {
|
||||
if (this._issue.isPullRequest) {
|
||||
if (this._options.exemptDraftPr) {
|
||||
this._issueLogger.info(
|
||||
`The option ${this._issueLogger.createOptionLink(
|
||||
Option.ExemptDraftPr
|
||||
)} is enabled`
|
||||
);
|
||||
|
||||
const pullRequest: IPullRequest | undefined | void =
|
||||
await pullRequestCallback();
|
||||
|
||||
if (pullRequest?.draft === true) {
|
||||
this._issueLogger.info(
|
||||
LoggerService.white('└──'),
|
||||
`Skip the $$type draft checks`
|
||||
);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
this._issueLogger.info(
|
||||
LoggerService.white('└──'),
|
||||
`Continuing the process for this $$type because it is not a draft`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user