From 3e6d35b685f0b2fa1a69be893fa07d3d85e05ee0 Mon Sep 17 00:00:00 2001 From: Falk Puschner Date: Thu, 3 Jun 2021 15:18:48 +0200 Subject: [PATCH] feat(output): print output parameters (#458) * :sparkles: print output parameters * :memo: add output table * :alembic: try output parameters * :alembic: stringify output * :alembic: try test output * :fire: remove test output * :green_heart: build and lint code * :fire: remove output test * :lock: fix vulnerabilities * :art: renaming staled variables * :art: build code * :memo: update contributing commands --- .github/workflows/test.yml | 3 + CONTRIBUTING.md | 8 +- README.md | 9 +- action.yml | 5 + dist/index.js | 3779 ++++++++++++++++++------------------ package-lock.json | 35 +- src/main.ts | 17 +- 7 files changed, 1924 insertions(+), 1932 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fcd39da73..d58f47cea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,10 @@ jobs: steps: - uses: actions/checkout@v2 - uses: ./ + id: stale with: stale-issue-message: 'This issue is stale' stale-pr-message: 'This PR is stale' debug-only: true + - name: print outputs + run: echo ${{ join(steps.stale.outputs.*, ',') }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7a2bf26d8..a31f68332 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,19 +21,19 @@ $ npm test Run the tests and display only the first failing tests :heavy_check_mark: ```bash -$ npm test:only-errors +$ npm run test:only-errors ``` Run the tests with the watch mode :heavy_check_mark: ```bash -$ npm test:watch +$ npm run test:watch ``` Run the linter and fix (almost) every issue for you :heavy_check_mark: ```bash -$ npm lint:all:fix +$ npm run lint:all:fix ``` # Before creating a PR @@ -43,7 +43,7 @@ $ npm lint:all:fix Build, lint, package and test everything. ```bash -$ npm all +$ npm run all ``` # Release diff --git a/README.md b/README.md index 52f722a94..07a5b9899 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The default configuration will: ## All options -### List of options +### List of input options Every argument is optional. @@ -61,6 +61,13 @@ Every argument is optional. | [exempt-all-pr-assignees](#exempt-all-pr-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for PRs only | | | [enable-statistics](#enable-statistics) | Display statistics in the logs | `true` | +### List of output options + +| Output | Description | +| ----------------- | -------------------------------------------- | +| staled-issues-prs | List of all staled issues and pull requests. | +| closed-issues-prs | List of all closed issues and pull requests. | + ### Detailed options #### repo-token diff --git a/action.yml b/action.yml index b4bb19f49..4adb85a7d 100644 --- a/action.yml +++ b/action.yml @@ -168,6 +168,11 @@ inputs: description: 'Display some statistics at the end regarding the stale workflow (only when the logs are enabled).' default: 'true' required: false +outputs: + closed-issues-prs: + description: 'List of all closed issues and pull requests.' + staled-issues-prs: + description: 'List of all staled issues and pull requests.' runs: using: 'node12' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index ce365adf4..c0de1d825 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6,140 +6,140 @@ module.exports = /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Assignees = void 0; -const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601)); -const option_1 = __nccwpck_require__(5931); -const words_to_list_1 = __nccwpck_require__(1883); -const issue_logger_1 = __nccwpck_require__(2984); -const logger_service_1 = __nccwpck_require__(1973); -class Assignees { - constructor(options, issue) { - this._options = options; - this._issue = issue; - this._issueLogger = new issue_logger_1.IssueLogger(issue); - } - static _cleanAssignee(assignee) { - return lodash_deburr_1.default(assignee.toLowerCase()); - } - shouldExemptAssignees() { - if (!this._issue.hasAssignees) { - this._issueLogger.info('This $$type has no assignee'); - this._logSkip(); - return false; - } - if (this._shouldExemptAllAssignees()) { - this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has an exempt assignee'); - return true; - } - const exemptAssignees = this._getExemptAssignees(); - if (exemptAssignees.length === 0) { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `No assignee option was specified to skip the stale process for this $$type`); - this._logSkip(); - return false; - } - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `Found ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length > 1 ? 's' : ''} that can exempt stale on this $$type`); - const hasExemptAssignee = exemptAssignees.some((exemptAssignee) => this._hasAssignee(exemptAssignee)); - if (!hasExemptAssignee) { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), 'No assignee on this $$type can exempt the stale process'); - this._logSkip(); - } - else { - this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has an exempt assignee'); - } - return hasExemptAssignee; - } - _getExemptAssignees() { - return this._issue.isPullRequest - ? this._getExemptPullRequestAssignees() - : this._getExemptIssueAssignees(); - } - _getExemptIssueAssignees() { - if (this._options.exemptIssueAssignees === '') { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); - if (this._options.exemptAssignees === '') { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); - return []; - } - const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptAssignees); - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); - return exemptAssignees; - } - const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptIssueAssignees); - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueAssignees)} is set. ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); - return exemptAssignees; - } - _getExemptPullRequestAssignees() { - if (this._options.exemptPrAssignees === '') { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); - if (this._options.exemptAssignees === '') { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); - return []; - } - const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptAssignees); - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); - return exemptAssignees; - } - const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptPrAssignees); - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrAssignees)} is set. ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); - return exemptAssignees; - } - _hasAssignee(assignee) { - const cleanAssignee = Assignees._cleanAssignee(assignee); - return this._issue.assignees.some((issueAssignee) => { - const isSameAssignee = cleanAssignee === Assignees._cleanAssignee(issueAssignee.login); - if (isSameAssignee) { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `@${issueAssignee.login} is assigned on this $$type and is an exempt assignee`); - } - return isSameAssignee; - }); - } - _shouldExemptAllAssignees() { - return this._issue.isPullRequest - ? this._shouldExemptAllPullRequestAssignees() - : this._shouldExemptAllIssueAssignees(); - } - _shouldExemptAllIssueAssignees() { - if (this._options.exemptAllIssueAssignees === true) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueAssignees)} is enabled. Any assignee on this $$type will skip the stale process`); - return true; - } - else if (this._options.exemptAllIssueAssignees === false) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueAssignees)} is disabled. Only some specific assignees on this $$type will skip the stale process`); - return false; - } - this._logExemptAllAssigneesOption(); - return this._options.exemptAllAssignees; - } - _shouldExemptAllPullRequestAssignees() { - if (this._options.exemptAllPrAssignees === true) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrAssignees)} is enabled. Any assignee on this $$type will skip the stale process`); - return true; - } - else if (this._options.exemptAllPrAssignees === false) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrAssignees)} is disabled. Only some specific assignees on this $$type will skip the stale process`); - return false; - } - this._logExemptAllAssigneesOption(); - return this._options.exemptAllAssignees; - } - _logExemptAllAssigneesOption() { - if (this._options.exemptAllAssignees) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllAssignees)} is enabled. Any assignee on this $$type will skip the stale process`); - } - else { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllAssignees)} is disabled. Only some specific assignees on this $$type will skip the stale process`); - } - } - _logSkip() { - this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skip the assignees checks'); - } -} -exports.Assignees = Assignees; + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Assignees = void 0; +const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601)); +const option_1 = __nccwpck_require__(5931); +const words_to_list_1 = __nccwpck_require__(1883); +const issue_logger_1 = __nccwpck_require__(2984); +const logger_service_1 = __nccwpck_require__(1973); +class Assignees { + constructor(options, issue) { + this._options = options; + this._issue = issue; + this._issueLogger = new issue_logger_1.IssueLogger(issue); + } + static _cleanAssignee(assignee) { + return lodash_deburr_1.default(assignee.toLowerCase()); + } + shouldExemptAssignees() { + if (!this._issue.hasAssignees) { + this._issueLogger.info('This $$type has no assignee'); + this._logSkip(); + return false; + } + if (this._shouldExemptAllAssignees()) { + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has an exempt assignee'); + return true; + } + const exemptAssignees = this._getExemptAssignees(); + if (exemptAssignees.length === 0) { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `No assignee option was specified to skip the stale process for this $$type`); + this._logSkip(); + return false; + } + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `Found ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length > 1 ? 's' : ''} that can exempt stale on this $$type`); + const hasExemptAssignee = exemptAssignees.some((exemptAssignee) => this._hasAssignee(exemptAssignee)); + if (!hasExemptAssignee) { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), 'No assignee on this $$type can exempt the stale process'); + this._logSkip(); + } + else { + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has an exempt assignee'); + } + return hasExemptAssignee; + } + _getExemptAssignees() { + return this._issue.isPullRequest + ? this._getExemptPullRequestAssignees() + : this._getExemptIssueAssignees(); + } + _getExemptIssueAssignees() { + if (this._options.exemptIssueAssignees === '') { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); + if (this._options.exemptAssignees === '') { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); + return []; + } + const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptAssignees); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + return exemptAssignees; + } + const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptIssueAssignees); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueAssignees)} is set. ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + return exemptAssignees; + } + _getExemptPullRequestAssignees() { + if (this._options.exemptPrAssignees === '') { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); + if (this._options.exemptAssignees === '') { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is disabled. No specific assignee can skip the stale process for this $$type`); + return []; + } + const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptAssignees); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAssignees)} is set. ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + return exemptAssignees; + } + const exemptAssignees = words_to_list_1.wordsToList(this._options.exemptPrAssignees); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrAssignees)} is set. ${logger_service_1.LoggerService.cyan(exemptAssignees.length)} assignee${exemptAssignees.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + return exemptAssignees; + } + _hasAssignee(assignee) { + const cleanAssignee = Assignees._cleanAssignee(assignee); + return this._issue.assignees.some((issueAssignee) => { + const isSameAssignee = cleanAssignee === Assignees._cleanAssignee(issueAssignee.login); + if (isSameAssignee) { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `@${issueAssignee.login} is assigned on this $$type and is an exempt assignee`); + } + return isSameAssignee; + }); + } + _shouldExemptAllAssignees() { + return this._issue.isPullRequest + ? this._shouldExemptAllPullRequestAssignees() + : this._shouldExemptAllIssueAssignees(); + } + _shouldExemptAllIssueAssignees() { + if (this._options.exemptAllIssueAssignees === true) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueAssignees)} is enabled. Any assignee on this $$type will skip the stale process`); + return true; + } + else if (this._options.exemptAllIssueAssignees === false) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueAssignees)} is disabled. Only some specific assignees on this $$type will skip the stale process`); + return false; + } + this._logExemptAllAssigneesOption(); + return this._options.exemptAllAssignees; + } + _shouldExemptAllPullRequestAssignees() { + if (this._options.exemptAllPrAssignees === true) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrAssignees)} is enabled. Any assignee on this $$type will skip the stale process`); + return true; + } + else if (this._options.exemptAllPrAssignees === false) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrAssignees)} is disabled. Only some specific assignees on this $$type will skip the stale process`); + return false; + } + this._logExemptAllAssigneesOption(); + return this._options.exemptAllAssignees; + } + _logExemptAllAssigneesOption() { + if (this._options.exemptAllAssignees) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllAssignees)} is enabled. Any assignee on this $$type will skip the stale process`); + } + else { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllAssignees)} is disabled. Only some specific assignees on this $$type will skip the stale process`); + } + } + _logSkip() { + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skip the assignees checks'); + } +} +exports.Assignees = Assignees; /***/ }), @@ -148,44 +148,44 @@ exports.Assignees = Assignees; /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Issue = void 0; -const is_labeled_1 = __nccwpck_require__(6792); -const is_pull_request_1 = __nccwpck_require__(5400); -const operations_1 = __nccwpck_require__(7957); -class Issue { - constructor(options, issue) { - this.operations = new operations_1.Operations(); - this._options = options; - this.title = issue.title; - this.number = issue.number; - this.created_at = issue.created_at; - this.updated_at = issue.updated_at; - this.labels = issue.labels; - this.pull_request = issue.pull_request; - this.state = issue.state; - this.locked = issue.locked; - this.milestone = issue.milestone; - this.assignees = issue.assignees; - this.isStale = is_labeled_1.isLabeled(this, this.staleLabel); - } - get isPullRequest() { - return is_pull_request_1.isPullRequest(this); - } - get staleLabel() { - return this._getStaleLabel(); - } - get hasAssignees() { - return this.assignees.length > 0; - } - _getStaleLabel() { - return this.isPullRequest - ? this._options.stalePrLabel - : this._options.staleIssueLabel; - } -} -exports.Issue = Issue; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Issue = void 0; +const is_labeled_1 = __nccwpck_require__(6792); +const is_pull_request_1 = __nccwpck_require__(5400); +const operations_1 = __nccwpck_require__(7957); +class Issue { + constructor(options, issue) { + this.operations = new operations_1.Operations(); + this._options = options; + this.title = issue.title; + this.number = issue.number; + this.created_at = issue.created_at; + this.updated_at = issue.updated_at; + this.labels = issue.labels; + this.pull_request = issue.pull_request; + this.state = issue.state; + this.locked = issue.locked; + this.milestone = issue.milestone; + this.assignees = issue.assignees; + this.isStale = is_labeled_1.isLabeled(this, this.staleLabel); + } + get isPullRequest() { + return is_pull_request_1.isPullRequest(this); + } + get staleLabel() { + return this._getStaleLabel(); + } + get hasAssignees() { + return this.assignees.length > 0; + } + _getStaleLabel() { + return this.isPullRequest + ? this._options.stalePrLabel + : this._options.staleIssueLabel; + } +} +exports.Issue = Issue; /***/ }), @@ -194,691 +194,691 @@ exports.Issue = Issue; /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.IssuesProcessor = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const github_1 = __nccwpck_require__(5438); -const option_1 = __nccwpck_require__(5931); -const get_humanized_date_1 = __nccwpck_require__(965); -const is_date_more_recent_than_1 = __nccwpck_require__(1473); -const is_valid_date_1 = __nccwpck_require__(891); -const is_boolean_1 = __nccwpck_require__(8236); -const is_labeled_1 = __nccwpck_require__(6792); -const should_mark_when_stale_1 = __nccwpck_require__(2461); -const words_to_list_1 = __nccwpck_require__(1883); -const assignees_1 = __nccwpck_require__(7236); -const issue_1 = __nccwpck_require__(4783); -const issue_logger_1 = __nccwpck_require__(2984); -const logger_1 = __nccwpck_require__(6212); -const milestones_1 = __nccwpck_require__(4601); -const stale_operations_1 = __nccwpck_require__(5080); -const statistics_1 = __nccwpck_require__(3334); -const logger_service_1 = __nccwpck_require__(1973); -/*** - * Handle processing of issues for staleness/closure. - */ -class IssuesProcessor { - constructor(options) { - this._logger = new logger_1.Logger(); - this.staleIssues = []; - this.closedIssues = []; - this.deletedBranchIssues = []; - this.removedLabelIssues = []; - this.options = options; - this.client = github_1.getOctokit(this.options.repoToken); - this._operations = new stale_operations_1.StaleOperations(this.options); - this._logger.info(logger_service_1.LoggerService.yellow(`Starting the stale action process...`)); - if (this.options.debugOnly) { - this._logger.warning(logger_service_1.LoggerService.yellowBright(`Executing in debug mode!`)); - this._logger.warning(logger_service_1.LoggerService.yellowBright(`The debug output will be written but no issues/PRs will be processed.`)); - } - if (this.options.enableStatistics) { - this._statistics = new statistics_1.Statistics(); - } - } - static _updatedSince(timestamp, num_days) { - const daysInMillis = 1000 * 60 * 60 * 24 * num_days; - const millisSinceLastUpdated = new Date().getTime() - new Date(timestamp).getTime(); - return millisSinceLastUpdated <= daysInMillis; - } - static _endIssueProcessing(issue) { - const consumedOperationsCount = issue.operations.getConsumedOperationsCount(); - if (consumedOperationsCount > 0) { - const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(logger_service_1.LoggerService.cyan(consumedOperationsCount), `operation${consumedOperationsCount > 1 ? 's' : ''} consumed for this $$type`); - } - } - static _getStaleMessageUsedOptionName(issue) { - return issue.isPullRequest - ? option_1.Option.StalePrMessage - : option_1.Option.StaleIssueMessage; - } - processIssues(page = 1) { - var _a, _b; - return __awaiter(this, void 0, void 0, function* () { - // get the next batch of issues - const issues = yield this.getIssues(page); - const actor = yield this.getActor(); - if (issues.length <= 0) { - this._logger.info(logger_service_1.LoggerService.green(`No more issues found to process. Exiting...`)); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.setRemainingOperations(this._operations.getRemainingOperationsCount()).logStats(); - return this._operations.getRemainingOperationsCount(); - } - else { - this._logger.info(`${logger_service_1.LoggerService.yellow('Processing the batch of issues')} ${logger_service_1.LoggerService.cyan(`#${page}`)} ${logger_service_1.LoggerService.yellow('containing')} ${logger_service_1.LoggerService.cyan(issues.length)} ${logger_service_1.LoggerService.yellow(`issue${issues.length > 1 ? 's' : ''}...`)}`); - } - for (const issue of issues.values()) { - const issueLogger = new issue_logger_1.IssueLogger(issue); - (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementProcessedItemsCount(issue); - issueLogger.info(`Found this $$type last updated at: ${logger_service_1.LoggerService.cyan(issue.updated_at)}`); - // calculate string based messages for this issue - const staleMessage = issue.isPullRequest - ? this.options.stalePrMessage - : this.options.staleIssueMessage; - const closeMessage = issue.isPullRequest - ? this.options.closePrMessage - : this.options.closeIssueMessage; - const staleLabel = issue.isPullRequest - ? this.options.stalePrLabel - : this.options.staleIssueLabel; - const closeLabel = issue.isPullRequest - ? this.options.closePrLabel - : this.options.closeIssueLabel; - const skipMessage = issue.isPullRequest - ? this.options.stalePrMessage.length === 0 - : this.options.staleIssueMessage.length === 0; - const daysBeforeStale = issue.isPullRequest - ? this._getDaysBeforePrStale() - : this._getDaysBeforeIssueStale(); - const onlyLabels = words_to_list_1.wordsToList(this._getOnlyLabels(issue)); - if (onlyLabels.length > 0) { - issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.OnlyLabels)} was specified to only process issues and pull requests with all those labels (${logger_service_1.LoggerService.cyan(onlyLabels.length)})`); - const hasAllWhitelistedLabels = onlyLabels.every((label) => { - return is_labeled_1.isLabeled(issue, label); - }); - if (!hasAllWhitelistedLabels) { - issueLogger.info(logger_service_1.LoggerService.white('└──'), `Skipping this $$type because it doesn't have all the required labels`); - IssuesProcessor._endIssueProcessing(issue); - continue; // Don't process issues without all of the required labels - } - else { - issueLogger.info(logger_service_1.LoggerService.white('├──'), `All the required labels are present on this $$type`); - issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); - } - } - else { - issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.OnlyLabels)} was not specified`); - issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); - } - issueLogger.info(`Days before $$type stale: ${logger_service_1.LoggerService.cyan(daysBeforeStale)}`); - const shouldMarkAsStale = should_mark_when_stale_1.shouldMarkWhenStale(daysBeforeStale); - if (issue.state === 'closed') { - issueLogger.info(`Skipping this $$type because it is closed`); - IssuesProcessor._endIssueProcessing(issue); - continue; // Don't process closed issues - } - if (issue.locked) { - issueLogger.info(`Skipping this $$type because it is locked`); - IssuesProcessor._endIssueProcessing(issue); - continue; // Don't process locked issues - } - // Try to remove the close label when not close/locked issue or PR - yield this._removeCloseLabel(issue, closeLabel); - if (this.options.startDate) { - const startDate = new Date(this.options.startDate); - const createdAt = new Date(issue.created_at); - issueLogger.info(`A start date was specified for the ${get_humanized_date_1.getHumanizedDate(startDate)} (${logger_service_1.LoggerService.cyan(this.options.startDate)})`); - // Expecting that GitHub will always set a creation date on the issues and PRs - // But you never know! - if (!is_valid_date_1.isValidDate(createdAt)) { - IssuesProcessor._endIssueProcessing(issue); - core.setFailed(new Error(`Invalid issue field: "created_at". Expected a valid date`)); - } - issueLogger.info(`$$type created the ${get_humanized_date_1.getHumanizedDate(createdAt)} (${logger_service_1.LoggerService.cyan(issue.created_at)})`); - if (!is_date_more_recent_than_1.isDateMoreRecentThan(createdAt, startDate)) { - issueLogger.info(`Skipping this $$type because it was created before the specified start date`); - IssuesProcessor._endIssueProcessing(issue); - continue; // Don't process issues which were created before the start date - } - } - if (issue.isStale) { - issueLogger.info(`This $$type has a stale label`); - } - else { - issueLogger.info(`This $$type hasn't a stale label`); - } - const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest - ? this.options.exemptPrLabels - : this.options.exemptIssueLabels); - if (exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel))) { - if (issue.isStale) { - issueLogger.info(`An exempt label was added after the stale label.`); - yield this._removeStaleLabel(issue, staleLabel); - } - issueLogger.info(`Skipping this $$type because it has an exempt label`); - IssuesProcessor._endIssueProcessing(issue); - continue; // Don't process exempt issues - } - const anyOfLabels = words_to_list_1.wordsToList(this._getAnyOfLabels(issue)); - if (anyOfLabels.length > 0) { - issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.AnyOfLabels)} was specified to only process the issues and pull requests with one of those labels (${logger_service_1.LoggerService.cyan(anyOfLabels.length)})`); - const hasOneOfWhitelistedLabels = anyOfLabels.some((label) => { - return is_labeled_1.isLabeled(issue, label); - }); - if (!hasOneOfWhitelistedLabels) { - issueLogger.info(logger_service_1.LoggerService.white('└──'), `Skipping this $$type because it doesn't have one of the required labels`); - IssuesProcessor._endIssueProcessing(issue); - continue; // Don't process issues without any of the required labels - } - else { - issueLogger.info(logger_service_1.LoggerService.white('├──'), `One of the required labels is present on this $$type`); - issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); - } - } - else { - issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.AnyOfLabels)} was not specified`); - issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); - } - const milestones = new milestones_1.Milestones(this.options, issue); - if (milestones.shouldExemptMilestones()) { - IssuesProcessor._endIssueProcessing(issue); - continue; // Don't process exempt milestones - } - const assignees = new assignees_1.Assignees(this.options, issue); - if (assignees.shouldExemptAssignees()) { - IssuesProcessor._endIssueProcessing(issue); - continue; // Don't process exempt assignees - } - // Should this issue be marked stale? - const shouldBeStale = !IssuesProcessor._updatedSince(issue.updated_at, daysBeforeStale); - // Determine if this issue needs to be marked stale first - if (!issue.isStale) { - issueLogger.info(`This $$type is not stale`); - const updatedAtDate = new Date(issue.updated_at); - if (shouldBeStale) { - issueLogger.info(`This $$type should be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`); - if (shouldMarkAsStale) { - issueLogger.info(`This $$type should be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${logger_service_1.LoggerService.cyan(daysBeforeStale)})`); - yield this._markStale(issue, staleMessage, staleLabel, skipMessage); - issue.isStale = true; // This issue is now considered stale - issueLogger.info(`This $$type is now stale`); - } - else { - issueLogger.info(`This $$type should not be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${logger_service_1.LoggerService.cyan(daysBeforeStale)})`); - } - } - else { - issueLogger.info(`This $$type should not be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`); - } - } - // Process the issue if it was marked stale - if (issue.isStale) { - issueLogger.info(`This $$type is already stale`); - yield this._processStaleIssue(issue, staleLabel, actor, closeMessage, closeLabel); - } - IssuesProcessor._endIssueProcessing(issue); - } - if (!this._operations.hasRemainingOperations()) { - this._logger.warning(logger_service_1.LoggerService.yellowBright(`No more operations left! Exiting...`)); - this._logger.warning(`${logger_service_1.LoggerService.yellowBright('If you think that not enough issues were processed you could try to increase the quantity related to the')} ${this._logger.createOptionLink(option_1.Option.OperationsPerRun)} ${logger_service_1.LoggerService.yellowBright('option which is currently set to')} ${logger_service_1.LoggerService.cyan(this.options.operationsPerRun)}`); - return 0; - } - this._logger.info(`${logger_service_1.LoggerService.green('Batch')} ${logger_service_1.LoggerService.cyan(`#${page}`)} ${logger_service_1.LoggerService.green('processed.')}`); - // Do the next batch - return this.processIssues(page + 1); - }); - } - // Grab comments for an issue since a given date - listIssueComments(issueNumber, sinceDate) { - var _a; - return __awaiter(this, void 0, void 0, function* () { - // Find any comments since date on the given issue - try { - this._operations.consumeOperation(); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCommentsCount(); - const comments = yield this.client.issues.listComments({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issueNumber, - since: sinceDate - }); - return comments.data; - } - catch (error) { - this._logger.error(`List issue comments error: ${error.message}`); - return Promise.resolve([]); - } - }); - } - // get the actor from the GitHub token or context - getActor() { - return __awaiter(this, void 0, void 0, function* () { - let actor; - try { - this._operations.consumeOperation(); - actor = yield this.client.users.getAuthenticated(); - } - catch (error) { - return github_1.context.actor; - } - return actor.data.login; - }); - } - // grab issues from github in batches of 100 - getIssues(page) { - var _a; - return __awaiter(this, void 0, void 0, function* () { - // generate type for response - const endpoint = this.client.issues.listForRepo; - try { - this._operations.consumeOperation(); - const issueResult = yield this.client.issues.listForRepo({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - state: 'open', - per_page: 100, - direction: this.options.ascending ? 'asc' : 'desc', - page - }); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCount(issueResult.data.length); - return issueResult.data.map((issue) => new issue_1.Issue(this.options, issue)); - } - catch (error) { - this._logger.error(`Get issues for repo error: ${error.message}`); - return Promise.resolve([]); - } - }); - } - // returns the creation date of a given label on an issue (or nothing if no label existed) - ///see https://developer.github.com/v3/activity/events/ - getLabelCreationDate(issue, label) { - var _a; - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`Checking for label on this $$type`); - this._consumeIssueOperation(issue); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsEventsCount(); - const options = this.client.issues.listEvents.endpoint.merge({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - per_page: 100, - issue_number: issue.number - }); - const events = yield this.client.paginate(options); - const reversedEvents = events.reverse(); - const staleLabeledEvent = reversedEvents.find(event => event.event === 'labeled' && event.label.name === label); - if (!staleLabeledEvent) { - // Must be old rather than labeled - return undefined; - } - return staleLabeledEvent.created_at; - }); - } - // handle all of the stale issue logic when we find a stale issue - _processStaleIssue(issue, staleLabel, actor, closeMessage, closeLabel) { - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at; - issueLogger.info(`$$type marked stale on: ${logger_service_1.LoggerService.cyan(markedStaleOn)}`); - const issueHasComments = yield this._hasCommentsSince(issue, markedStaleOn, actor); - issueLogger.info(`$$type has been commented on: ${logger_service_1.LoggerService.cyan(issueHasComments)}`); - const daysBeforeClose = issue.isPullRequest - ? this._getDaysBeforePrClose() - : this._getDaysBeforeIssueClose(); - issueLogger.info(`Days before $$type close: ${logger_service_1.LoggerService.cyan(daysBeforeClose)}`); - const issueHasUpdate = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose); - issueLogger.info(`$$type has been updated: ${logger_service_1.LoggerService.cyan(issueHasUpdate)}`); - // should we un-stale this issue? - if (this._shouldRemoveStaleWhenUpdated(issue) && issueHasComments) { - yield this._removeStaleLabel(issue, staleLabel); - issueLogger.info(`Skipping the process since the $$type is now un-stale`); - return; // nothing to do because it is no longer stale - } - // now start closing logic - if (daysBeforeClose < 0) { - return; // nothing to do because we aren't closing stale issues - } - if (!issueHasComments && !issueHasUpdate) { - issueLogger.info(`Closing $$type because it was last updated on! ${logger_service_1.LoggerService.cyan(issue.updated_at)}`); - yield this._closeIssue(issue, closeMessage, closeLabel); - if (this.options.deleteBranch && issue.pull_request) { - issueLogger.info(`Deleting the branch the option ${issueLogger.createOptionLink(option_1.Option.DeleteBranch)} was specified`); - yield this._deleteBranch(issue); - this.deletedBranchIssues.push(issue); - } - } - else { - issueLogger.info(`Stale $$type is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate})`); - } - }); - } - // checks to see if a given issue is still stale (has had activity on it) - _hasCommentsSince(issue, sinceDate, actor) { - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`Checking for comments on $$type since: ${logger_service_1.LoggerService.cyan(sinceDate)}`); - if (!sinceDate) { - return true; - } - // find any comments since the date - const comments = yield this.listIssueComments(issue.number, sinceDate); - const filteredComments = comments.filter(comment => comment.user.type === 'User' && comment.user.login !== actor); - issueLogger.info(`Comments not made by actor or another bot: ${logger_service_1.LoggerService.cyan(filteredComments.length)}`); - // if there are any user comments returned - return filteredComments.length > 0; - }); - } - // Mark an issue as stale with a comment and a label - _markStale(issue, staleMessage, staleLabel, skipMessage) { - var _a, _b, _c; - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`Marking this $$type as stale`); - this.staleIssues.push(issue); - // if the issue is being marked stale, the updated date should be changed to right now - // so that close calculations work correctly - const newUpdatedAtDate = new Date(); - issue.updated_at = newUpdatedAtDate.toString(); - if (this.options.debugOnly) { - return; - } - if (!skipMessage) { - try { - this._consumeIssueOperation(issue); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue); - yield this.client.issues.createComment({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issue.number, - body: staleMessage - }); - } - catch (error) { - issueLogger.error(`Error when creating a comment: ${error.message}`); - } - } - try { - this._consumeIssueOperation(issue); - (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue); - (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementStaleItemsCount(issue); - yield this.client.issues.addLabels({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issue.number, - labels: [staleLabel] - }); - } - catch (error) { - issueLogger.error(`Error when adding a label: ${error.message}`); - } - }); - } - // Close an issue based on staleness - _closeIssue(issue, closeMessage, closeLabel) { - var _a, _b, _c; - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`Closing $$type for being stale`); - this.closedIssues.push(issue); - if (this.options.debugOnly) { - return; - } - if (closeMessage) { - try { - this._consumeIssueOperation(issue); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue); - yield this.client.issues.createComment({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issue.number, - body: closeMessage - }); - } - catch (error) { - issueLogger.error(`Error when creating a comment: ${error.message}`); - } - } - if (closeLabel) { - try { - this._consumeIssueOperation(issue); - (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue); - yield this.client.issues.addLabels({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issue.number, - labels: [closeLabel] - }); - } - catch (error) { - issueLogger.error(`Error when adding a label: ${error.message}`); - } - } - try { - this._consumeIssueOperation(issue); - (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementClosedItemsCount(issue); - yield this.client.issues.update({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issue.number, - state: 'closed' - }); - } - catch (error) { - issueLogger.error(`Error when updating this $$type: ${error.message}`); - } - }); - } - _getPullRequest(issue) { - var _a; - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - if (this.options.debugOnly) { - return; - } - try { - this._consumeIssueOperation(issue); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedPullRequestsCount(); - const pullRequest = yield this.client.pulls.get({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - pull_number: issue.number - }); - return pullRequest.data; - } - catch (error) { - issueLogger.error(`Error when getting this $$type: ${error.message}`); - } - }); - } - // Delete the branch on closed pull request - _deleteBranch(issue) { - var _a; - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`Delete branch from closed $$type - ${issue.title}`); - const pullRequest = yield this._getPullRequest(issue); - if (!pullRequest) { - issueLogger.info(`Not deleting this branch as no pull request was found for this $$type`); - return; - } - if (this.options.debugOnly) { - return; - } - const branch = pullRequest.head.ref; - issueLogger.info(`Deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from closed $$type`); - try { - this._consumeIssueOperation(issue); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedBranchesCount(); - yield this.client.git.deleteRef({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - ref: `heads/${branch}` - }); - } - catch (error) { - issueLogger.error(`Error when deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from $$type: ${error.message}`); - } - }); - } - // Remove a label from an issue or a pull request - _removeLabel(issue, label) { - var _a; - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`Removing the label "${logger_service_1.LoggerService.cyan(label)}" from this $$type...`); - this.removedLabelIssues.push(issue); - if (this.options.debugOnly) { - return; - } - try { - this._consumeIssueOperation(issue); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedItemsLabelsCount(issue); - yield this.client.issues.removeLabel({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issue.number, - name: label - }); - issueLogger.info(`The label "${logger_service_1.LoggerService.cyan(label)}" was removed`); - } - catch (error) { - issueLogger.error(`Error when removing the label: "${logger_service_1.LoggerService.cyan(error.message)}"`); - } - }); - } - _getDaysBeforeIssueStale() { - return isNaN(this.options.daysBeforeIssueStale) - ? this.options.daysBeforeStale - : this.options.daysBeforeIssueStale; - } - _getDaysBeforePrStale() { - return isNaN(this.options.daysBeforePrStale) - ? this.options.daysBeforeStale - : this.options.daysBeforePrStale; - } - _getDaysBeforeIssueClose() { - return isNaN(this.options.daysBeforeIssueClose) - ? this.options.daysBeforeClose - : this.options.daysBeforeIssueClose; - } - _getDaysBeforePrClose() { - return isNaN(this.options.daysBeforePrClose) - ? this.options.daysBeforeClose - : this.options.daysBeforePrClose; - } - _getOnlyLabels(issue) { - if (issue.isPullRequest) { - if (this.options.onlyPrLabels !== '') { - return this.options.onlyPrLabels; - } - } - else { - if (this.options.onlyIssueLabels !== '') { - return this.options.onlyIssueLabels; - } - } - return this.options.onlyLabels; - } - _getAnyOfLabels(issue) { - if (issue.isPullRequest) { - if (this.options.anyOfPrLabels !== '') { - return this.options.anyOfPrLabels; - } - } - else { - if (this.options.anyOfIssueLabels !== '') { - return this.options.anyOfIssueLabels; - } - } - return this.options.anyOfLabels; - } - _shouldRemoveStaleWhenUpdated(issue) { - if (issue.isPullRequest) { - if (is_boolean_1.isBoolean(this.options.removePrStaleWhenUpdated)) { - return this.options.removePrStaleWhenUpdated; - } - return this.options.removeStaleWhenUpdated; - } - if (is_boolean_1.isBoolean(this.options.removeIssueStaleWhenUpdated)) { - return this.options.removeIssueStaleWhenUpdated; - } - return this.options.removeStaleWhenUpdated; - } - _removeStaleLabel(issue, staleLabel) { - var _a; - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`The $$type is no longer stale. Removing the stale label...`); - yield this._removeLabel(issue, staleLabel); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementUndoStaleItemsCount(issue); - }); - } - _removeCloseLabel(issue, closeLabel) { - var _a; - return __awaiter(this, void 0, void 0, function* () { - const issueLogger = new issue_logger_1.IssueLogger(issue); - issueLogger.info(`The $$type is not closed nor locked. Trying to remove the close label...`); - if (!closeLabel) { - issueLogger.info(`There is no close label on this $$type. Skip`); - return Promise.resolve(); - } - if (is_labeled_1.isLabeled(issue, closeLabel)) { - issueLogger.info(`The $$type has a close label "${logger_service_1.LoggerService.cyan(closeLabel)}". Removing the close label...`); - yield this._removeLabel(issue, closeLabel); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedCloseItemsLabelsCount(issue); - } - }); - } - _consumeIssueOperation(issue) { - this._operations.consumeOperation(); - issue.operations.consumeOperation(); - } - _getDaysBeforeStaleUsedOptionName(issue) { - return issue.isPullRequest - ? this._getDaysBeforePrStaleUsedOptionName() - : this._getDaysBeforeIssueStaleUsedOptionName(); - } - _getDaysBeforeIssueStaleUsedOptionName() { - return isNaN(this.options.daysBeforeIssueStale) - ? option_1.Option.DaysBeforeStale - : option_1.Option.DaysBeforeIssueStale; - } - _getDaysBeforePrStaleUsedOptionName() { - return isNaN(this.options.daysBeforePrStale) - ? option_1.Option.DaysBeforeStale - : option_1.Option.DaysBeforePrStale; - } -} -exports.IssuesProcessor = IssuesProcessor; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.IssuesProcessor = void 0; +const core = __importStar(__nccwpck_require__(2186)); +const github_1 = __nccwpck_require__(5438); +const option_1 = __nccwpck_require__(5931); +const get_humanized_date_1 = __nccwpck_require__(965); +const is_date_more_recent_than_1 = __nccwpck_require__(1473); +const is_valid_date_1 = __nccwpck_require__(891); +const is_boolean_1 = __nccwpck_require__(8236); +const is_labeled_1 = __nccwpck_require__(6792); +const should_mark_when_stale_1 = __nccwpck_require__(2461); +const words_to_list_1 = __nccwpck_require__(1883); +const assignees_1 = __nccwpck_require__(7236); +const issue_1 = __nccwpck_require__(4783); +const issue_logger_1 = __nccwpck_require__(2984); +const logger_1 = __nccwpck_require__(6212); +const milestones_1 = __nccwpck_require__(4601); +const stale_operations_1 = __nccwpck_require__(5080); +const statistics_1 = __nccwpck_require__(3334); +const logger_service_1 = __nccwpck_require__(1973); +/*** + * Handle processing of issues for staleness/closure. + */ +class IssuesProcessor { + constructor(options) { + this._logger = new logger_1.Logger(); + this.staleIssues = []; + this.closedIssues = []; + this.deletedBranchIssues = []; + this.removedLabelIssues = []; + this.options = options; + this.client = github_1.getOctokit(this.options.repoToken); + this._operations = new stale_operations_1.StaleOperations(this.options); + this._logger.info(logger_service_1.LoggerService.yellow(`Starting the stale action process...`)); + if (this.options.debugOnly) { + this._logger.warning(logger_service_1.LoggerService.yellowBright(`Executing in debug mode!`)); + this._logger.warning(logger_service_1.LoggerService.yellowBright(`The debug output will be written but no issues/PRs will be processed.`)); + } + if (this.options.enableStatistics) { + this._statistics = new statistics_1.Statistics(); + } + } + static _updatedSince(timestamp, num_days) { + const daysInMillis = 1000 * 60 * 60 * 24 * num_days; + const millisSinceLastUpdated = new Date().getTime() - new Date(timestamp).getTime(); + return millisSinceLastUpdated <= daysInMillis; + } + static _endIssueProcessing(issue) { + const consumedOperationsCount = issue.operations.getConsumedOperationsCount(); + if (consumedOperationsCount > 0) { + const issueLogger = new issue_logger_1.IssueLogger(issue); + issueLogger.info(logger_service_1.LoggerService.cyan(consumedOperationsCount), `operation${consumedOperationsCount > 1 ? 's' : ''} consumed for this $$type`); + } + } + static _getStaleMessageUsedOptionName(issue) { + return issue.isPullRequest + ? option_1.Option.StalePrMessage + : option_1.Option.StaleIssueMessage; + } + processIssues(page = 1) { + var _a, _b; + return __awaiter(this, void 0, void 0, function* () { + // get the next batch of issues + const issues = yield this.getIssues(page); + const actor = yield this.getActor(); + if (issues.length <= 0) { + this._logger.info(logger_service_1.LoggerService.green(`No more issues found to process. Exiting...`)); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.setRemainingOperations(this._operations.getRemainingOperationsCount()).logStats(); + return this._operations.getRemainingOperationsCount(); + } + else { + this._logger.info(`${logger_service_1.LoggerService.yellow('Processing the batch of issues')} ${logger_service_1.LoggerService.cyan(`#${page}`)} ${logger_service_1.LoggerService.yellow('containing')} ${logger_service_1.LoggerService.cyan(issues.length)} ${logger_service_1.LoggerService.yellow(`issue${issues.length > 1 ? 's' : ''}...`)}`); + } + for (const issue of issues.values()) { + const issueLogger = new issue_logger_1.IssueLogger(issue); + (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementProcessedItemsCount(issue); + issueLogger.info(`Found this $$type last updated at: ${logger_service_1.LoggerService.cyan(issue.updated_at)}`); + // calculate string based messages for this issue + const staleMessage = issue.isPullRequest + ? this.options.stalePrMessage + : this.options.staleIssueMessage; + const closeMessage = issue.isPullRequest + ? this.options.closePrMessage + : this.options.closeIssueMessage; + const staleLabel = issue.isPullRequest + ? this.options.stalePrLabel + : this.options.staleIssueLabel; + const closeLabel = issue.isPullRequest + ? this.options.closePrLabel + : this.options.closeIssueLabel; + const skipMessage = issue.isPullRequest + ? this.options.stalePrMessage.length === 0 + : this.options.staleIssueMessage.length === 0; + const daysBeforeStale = issue.isPullRequest + ? this._getDaysBeforePrStale() + : this._getDaysBeforeIssueStale(); + const onlyLabels = words_to_list_1.wordsToList(this._getOnlyLabels(issue)); + if (onlyLabels.length > 0) { + issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.OnlyLabels)} was specified to only process issues and pull requests with all those labels (${logger_service_1.LoggerService.cyan(onlyLabels.length)})`); + const hasAllWhitelistedLabels = onlyLabels.every((label) => { + return is_labeled_1.isLabeled(issue, label); + }); + if (!hasAllWhitelistedLabels) { + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Skipping this $$type because it doesn't have all the required labels`); + IssuesProcessor._endIssueProcessing(issue); + continue; // Don't process issues without all of the required labels + } + else { + issueLogger.info(logger_service_1.LoggerService.white('├──'), `All the required labels are present on this $$type`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); + } + } + else { + issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.OnlyLabels)} was not specified`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); + } + issueLogger.info(`Days before $$type stale: ${logger_service_1.LoggerService.cyan(daysBeforeStale)}`); + const shouldMarkAsStale = should_mark_when_stale_1.shouldMarkWhenStale(daysBeforeStale); + if (issue.state === 'closed') { + issueLogger.info(`Skipping this $$type because it is closed`); + IssuesProcessor._endIssueProcessing(issue); + continue; // Don't process closed issues + } + if (issue.locked) { + issueLogger.info(`Skipping this $$type because it is locked`); + IssuesProcessor._endIssueProcessing(issue); + continue; // Don't process locked issues + } + // Try to remove the close label when not close/locked issue or PR + yield this._removeCloseLabel(issue, closeLabel); + if (this.options.startDate) { + const startDate = new Date(this.options.startDate); + const createdAt = new Date(issue.created_at); + issueLogger.info(`A start date was specified for the ${get_humanized_date_1.getHumanizedDate(startDate)} (${logger_service_1.LoggerService.cyan(this.options.startDate)})`); + // Expecting that GitHub will always set a creation date on the issues and PRs + // But you never know! + if (!is_valid_date_1.isValidDate(createdAt)) { + IssuesProcessor._endIssueProcessing(issue); + core.setFailed(new Error(`Invalid issue field: "created_at". Expected a valid date`)); + } + issueLogger.info(`$$type created the ${get_humanized_date_1.getHumanizedDate(createdAt)} (${logger_service_1.LoggerService.cyan(issue.created_at)})`); + if (!is_date_more_recent_than_1.isDateMoreRecentThan(createdAt, startDate)) { + issueLogger.info(`Skipping this $$type because it was created before the specified start date`); + IssuesProcessor._endIssueProcessing(issue); + continue; // Don't process issues which were created before the start date + } + } + if (issue.isStale) { + issueLogger.info(`This $$type has a stale label`); + } + else { + issueLogger.info(`This $$type hasn't a stale label`); + } + const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest + ? this.options.exemptPrLabels + : this.options.exemptIssueLabels); + if (exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel))) { + if (issue.isStale) { + issueLogger.info(`An exempt label was added after the stale label.`); + yield this._removeStaleLabel(issue, staleLabel); + } + issueLogger.info(`Skipping this $$type because it has an exempt label`); + IssuesProcessor._endIssueProcessing(issue); + continue; // Don't process exempt issues + } + const anyOfLabels = words_to_list_1.wordsToList(this._getAnyOfLabels(issue)); + if (anyOfLabels.length > 0) { + issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.AnyOfLabels)} was specified to only process the issues and pull requests with one of those labels (${logger_service_1.LoggerService.cyan(anyOfLabels.length)})`); + const hasOneOfWhitelistedLabels = anyOfLabels.some((label) => { + return is_labeled_1.isLabeled(issue, label); + }); + if (!hasOneOfWhitelistedLabels) { + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Skipping this $$type because it doesn't have one of the required labels`); + IssuesProcessor._endIssueProcessing(issue); + continue; // Don't process issues without any of the required labels + } + else { + issueLogger.info(logger_service_1.LoggerService.white('├──'), `One of the required labels is present on this $$type`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); + } + } + else { + issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.AnyOfLabels)} was not specified`); + issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type`); + } + const milestones = new milestones_1.Milestones(this.options, issue); + if (milestones.shouldExemptMilestones()) { + IssuesProcessor._endIssueProcessing(issue); + continue; // Don't process exempt milestones + } + const assignees = new assignees_1.Assignees(this.options, issue); + if (assignees.shouldExemptAssignees()) { + IssuesProcessor._endIssueProcessing(issue); + continue; // Don't process exempt assignees + } + // Should this issue be marked stale? + const shouldBeStale = !IssuesProcessor._updatedSince(issue.updated_at, daysBeforeStale); + // Determine if this issue needs to be marked stale first + if (!issue.isStale) { + issueLogger.info(`This $$type is not stale`); + const updatedAtDate = new Date(issue.updated_at); + if (shouldBeStale) { + issueLogger.info(`This $$type should be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`); + if (shouldMarkAsStale) { + issueLogger.info(`This $$type should be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${logger_service_1.LoggerService.cyan(daysBeforeStale)})`); + yield this._markStale(issue, staleMessage, staleLabel, skipMessage); + issue.isStale = true; // This issue is now considered stale + issueLogger.info(`This $$type is now stale`); + } + else { + issueLogger.info(`This $$type should not be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${logger_service_1.LoggerService.cyan(daysBeforeStale)})`); + } + } + else { + issueLogger.info(`This $$type should not be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`); + } + } + // Process the issue if it was marked stale + if (issue.isStale) { + issueLogger.info(`This $$type is already stale`); + yield this._processStaleIssue(issue, staleLabel, actor, closeMessage, closeLabel); + } + IssuesProcessor._endIssueProcessing(issue); + } + if (!this._operations.hasRemainingOperations()) { + this._logger.warning(logger_service_1.LoggerService.yellowBright(`No more operations left! Exiting...`)); + this._logger.warning(`${logger_service_1.LoggerService.yellowBright('If you think that not enough issues were processed you could try to increase the quantity related to the')} ${this._logger.createOptionLink(option_1.Option.OperationsPerRun)} ${logger_service_1.LoggerService.yellowBright('option which is currently set to')} ${logger_service_1.LoggerService.cyan(this.options.operationsPerRun)}`); + return 0; + } + this._logger.info(`${logger_service_1.LoggerService.green('Batch')} ${logger_service_1.LoggerService.cyan(`#${page}`)} ${logger_service_1.LoggerService.green('processed.')}`); + // Do the next batch + return this.processIssues(page + 1); + }); + } + // Grab comments for an issue since a given date + listIssueComments(issueNumber, sinceDate) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + // Find any comments since date on the given issue + try { + this._operations.consumeOperation(); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCommentsCount(); + const comments = yield this.client.issues.listComments({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issueNumber, + since: sinceDate + }); + return comments.data; + } + catch (error) { + this._logger.error(`List issue comments error: ${error.message}`); + return Promise.resolve([]); + } + }); + } + // get the actor from the GitHub token or context + getActor() { + return __awaiter(this, void 0, void 0, function* () { + let actor; + try { + this._operations.consumeOperation(); + actor = yield this.client.users.getAuthenticated(); + } + catch (error) { + return github_1.context.actor; + } + return actor.data.login; + }); + } + // grab issues from github in batches of 100 + getIssues(page) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + // generate type for response + const endpoint = this.client.issues.listForRepo; + try { + this._operations.consumeOperation(); + const issueResult = yield this.client.issues.listForRepo({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + state: 'open', + per_page: 100, + direction: this.options.ascending ? 'asc' : 'desc', + page + }); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCount(issueResult.data.length); + return issueResult.data.map((issue) => new issue_1.Issue(this.options, issue)); + } + catch (error) { + this._logger.error(`Get issues for repo error: ${error.message}`); + return Promise.resolve([]); + } + }); + } + // returns the creation date of a given label on an issue (or nothing if no label existed) + ///see https://developer.github.com/v3/activity/events/ + getLabelCreationDate(issue, label) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + issueLogger.info(`Checking for label on this $$type`); + this._consumeIssueOperation(issue); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsEventsCount(); + const options = this.client.issues.listEvents.endpoint.merge({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + per_page: 100, + issue_number: issue.number + }); + const events = yield this.client.paginate(options); + const reversedEvents = events.reverse(); + const staleLabeledEvent = reversedEvents.find(event => event.event === 'labeled' && event.label.name === label); + if (!staleLabeledEvent) { + // Must be old rather than labeled + return undefined; + } + return staleLabeledEvent.created_at; + }); + } + // handle all of the stale issue logic when we find a stale issue + _processStaleIssue(issue, staleLabel, actor, closeMessage, closeLabel) { + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at; + issueLogger.info(`$$type marked stale on: ${logger_service_1.LoggerService.cyan(markedStaleOn)}`); + const issueHasComments = yield this._hasCommentsSince(issue, markedStaleOn, actor); + issueLogger.info(`$$type has been commented on: ${logger_service_1.LoggerService.cyan(issueHasComments)}`); + const daysBeforeClose = issue.isPullRequest + ? this._getDaysBeforePrClose() + : this._getDaysBeforeIssueClose(); + issueLogger.info(`Days before $$type close: ${logger_service_1.LoggerService.cyan(daysBeforeClose)}`); + const issueHasUpdate = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose); + issueLogger.info(`$$type has been updated: ${logger_service_1.LoggerService.cyan(issueHasUpdate)}`); + // should we un-stale this issue? + if (this._shouldRemoveStaleWhenUpdated(issue) && issueHasComments) { + yield this._removeStaleLabel(issue, staleLabel); + issueLogger.info(`Skipping the process since the $$type is now un-stale`); + return; // nothing to do because it is no longer stale + } + // now start closing logic + if (daysBeforeClose < 0) { + return; // nothing to do because we aren't closing stale issues + } + if (!issueHasComments && !issueHasUpdate) { + issueLogger.info(`Closing $$type because it was last updated on! ${logger_service_1.LoggerService.cyan(issue.updated_at)}`); + yield this._closeIssue(issue, closeMessage, closeLabel); + if (this.options.deleteBranch && issue.pull_request) { + issueLogger.info(`Deleting the branch the option ${issueLogger.createOptionLink(option_1.Option.DeleteBranch)} was specified`); + yield this._deleteBranch(issue); + this.deletedBranchIssues.push(issue); + } + } + else { + issueLogger.info(`Stale $$type is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate})`); + } + }); + } + // checks to see if a given issue is still stale (has had activity on it) + _hasCommentsSince(issue, sinceDate, actor) { + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + issueLogger.info(`Checking for comments on $$type since: ${logger_service_1.LoggerService.cyan(sinceDate)}`); + if (!sinceDate) { + return true; + } + // find any comments since the date + const comments = yield this.listIssueComments(issue.number, sinceDate); + const filteredComments = comments.filter(comment => comment.user.type === 'User' && comment.user.login !== actor); + issueLogger.info(`Comments not made by actor or another bot: ${logger_service_1.LoggerService.cyan(filteredComments.length)}`); + // if there are any user comments returned + return filteredComments.length > 0; + }); + } + // Mark an issue as stale with a comment and a label + _markStale(issue, staleMessage, staleLabel, skipMessage) { + var _a, _b, _c; + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + issueLogger.info(`Marking this $$type as stale`); + this.staleIssues.push(issue); + // if the issue is being marked stale, the updated date should be changed to right now + // so that close calculations work correctly + const newUpdatedAtDate = new Date(); + issue.updated_at = newUpdatedAtDate.toString(); + if (this.options.debugOnly) { + return; + } + if (!skipMessage) { + try { + this._consumeIssueOperation(issue); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue); + yield this.client.issues.createComment({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issue.number, + body: staleMessage + }); + } + catch (error) { + issueLogger.error(`Error when creating a comment: ${error.message}`); + } + } + try { + this._consumeIssueOperation(issue); + (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue); + (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementStaleItemsCount(issue); + yield this.client.issues.addLabels({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issue.number, + labels: [staleLabel] + }); + } + catch (error) { + issueLogger.error(`Error when adding a label: ${error.message}`); + } + }); + } + // Close an issue based on staleness + _closeIssue(issue, closeMessage, closeLabel) { + var _a, _b, _c; + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + issueLogger.info(`Closing $$type for being stale`); + this.closedIssues.push(issue); + if (this.options.debugOnly) { + return; + } + if (closeMessage) { + try { + this._consumeIssueOperation(issue); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue); + yield this.client.issues.createComment({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issue.number, + body: closeMessage + }); + } + catch (error) { + issueLogger.error(`Error when creating a comment: ${error.message}`); + } + } + if (closeLabel) { + try { + this._consumeIssueOperation(issue); + (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue); + yield this.client.issues.addLabels({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issue.number, + labels: [closeLabel] + }); + } + catch (error) { + issueLogger.error(`Error when adding a label: ${error.message}`); + } + } + try { + this._consumeIssueOperation(issue); + (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementClosedItemsCount(issue); + yield this.client.issues.update({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issue.number, + state: 'closed' + }); + } + catch (error) { + issueLogger.error(`Error when updating this $$type: ${error.message}`); + } + }); + } + _getPullRequest(issue) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + if (this.options.debugOnly) { + return; + } + try { + this._consumeIssueOperation(issue); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedPullRequestsCount(); + const pullRequest = yield this.client.pulls.get({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + pull_number: issue.number + }); + return pullRequest.data; + } + catch (error) { + issueLogger.error(`Error when getting this $$type: ${error.message}`); + } + }); + } + // Delete the branch on closed pull request + _deleteBranch(issue) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + issueLogger.info(`Delete branch from closed $$type - ${issue.title}`); + const pullRequest = yield this._getPullRequest(issue); + if (!pullRequest) { + issueLogger.info(`Not deleting this branch as no pull request was found for this $$type`); + return; + } + if (this.options.debugOnly) { + return; + } + const branch = pullRequest.head.ref; + issueLogger.info(`Deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from closed $$type`); + try { + this._consumeIssueOperation(issue); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedBranchesCount(); + yield this.client.git.deleteRef({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + ref: `heads/${branch}` + }); + } + catch (error) { + issueLogger.error(`Error when deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from $$type: ${error.message}`); + } + }); + } + // Remove a label from an issue or a pull request + _removeLabel(issue, label) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + issueLogger.info(`Removing the label "${logger_service_1.LoggerService.cyan(label)}" from this $$type...`); + this.removedLabelIssues.push(issue); + if (this.options.debugOnly) { + return; + } + try { + this._consumeIssueOperation(issue); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedItemsLabelsCount(issue); + yield this.client.issues.removeLabel({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issue.number, + name: label + }); + issueLogger.info(`The label "${logger_service_1.LoggerService.cyan(label)}" was removed`); + } + catch (error) { + issueLogger.error(`Error when removing the label: "${logger_service_1.LoggerService.cyan(error.message)}"`); + } + }); + } + _getDaysBeforeIssueStale() { + return isNaN(this.options.daysBeforeIssueStale) + ? this.options.daysBeforeStale + : this.options.daysBeforeIssueStale; + } + _getDaysBeforePrStale() { + return isNaN(this.options.daysBeforePrStale) + ? this.options.daysBeforeStale + : this.options.daysBeforePrStale; + } + _getDaysBeforeIssueClose() { + return isNaN(this.options.daysBeforeIssueClose) + ? this.options.daysBeforeClose + : this.options.daysBeforeIssueClose; + } + _getDaysBeforePrClose() { + return isNaN(this.options.daysBeforePrClose) + ? this.options.daysBeforeClose + : this.options.daysBeforePrClose; + } + _getOnlyLabels(issue) { + if (issue.isPullRequest) { + if (this.options.onlyPrLabels !== '') { + return this.options.onlyPrLabels; + } + } + else { + if (this.options.onlyIssueLabels !== '') { + return this.options.onlyIssueLabels; + } + } + return this.options.onlyLabels; + } + _getAnyOfLabels(issue) { + if (issue.isPullRequest) { + if (this.options.anyOfPrLabels !== '') { + return this.options.anyOfPrLabels; + } + } + else { + if (this.options.anyOfIssueLabels !== '') { + return this.options.anyOfIssueLabels; + } + } + return this.options.anyOfLabels; + } + _shouldRemoveStaleWhenUpdated(issue) { + if (issue.isPullRequest) { + if (is_boolean_1.isBoolean(this.options.removePrStaleWhenUpdated)) { + return this.options.removePrStaleWhenUpdated; + } + return this.options.removeStaleWhenUpdated; + } + if (is_boolean_1.isBoolean(this.options.removeIssueStaleWhenUpdated)) { + return this.options.removeIssueStaleWhenUpdated; + } + return this.options.removeStaleWhenUpdated; + } + _removeStaleLabel(issue, staleLabel) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + issueLogger.info(`The $$type is no longer stale. Removing the stale label...`); + yield this._removeLabel(issue, staleLabel); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementUndoStaleItemsCount(issue); + }); + } + _removeCloseLabel(issue, closeLabel) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + const issueLogger = new issue_logger_1.IssueLogger(issue); + issueLogger.info(`The $$type is not closed nor locked. Trying to remove the close label...`); + if (!closeLabel) { + issueLogger.info(`There is no close label on this $$type. Skip`); + return Promise.resolve(); + } + if (is_labeled_1.isLabeled(issue, closeLabel)) { + issueLogger.info(`The $$type has a close label "${logger_service_1.LoggerService.cyan(closeLabel)}". Removing the close label...`); + yield this._removeLabel(issue, closeLabel); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedCloseItemsLabelsCount(issue); + } + }); + } + _consumeIssueOperation(issue) { + this._operations.consumeOperation(); + issue.operations.consumeOperation(); + } + _getDaysBeforeStaleUsedOptionName(issue) { + return issue.isPullRequest + ? this._getDaysBeforePrStaleUsedOptionName() + : this._getDaysBeforeIssueStaleUsedOptionName(); + } + _getDaysBeforeIssueStaleUsedOptionName() { + return isNaN(this.options.daysBeforeIssueStale) + ? option_1.Option.DaysBeforeStale + : option_1.Option.DaysBeforeIssueStale; + } + _getDaysBeforePrStaleUsedOptionName() { + return isNaN(this.options.daysBeforePrStale) + ? option_1.Option.DaysBeforeStale + : option_1.Option.DaysBeforePrStale; + } +} +exports.IssuesProcessor = IssuesProcessor; /***/ }), @@ -887,68 +887,68 @@ exports.IssuesProcessor = IssuesProcessor; /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.IssueLogger = void 0; -const logger_1 = __nccwpck_require__(6212); -const logger_service_1 = __nccwpck_require__(1973); -/** - * @description - * Each log will prefix the message with the issue number - * - * @example - * warning('No stale') => "[#123] No stale" - * - * Each log method can have special tokens: - * - $$type => will replace this by either "pull request" or "issue" depending of the type of issue - * - * @example - * warning('The $$type will stale') => "The pull request will stale" - */ -class IssueLogger extends logger_1.Logger { - constructor(issue) { - super(); - this._issue = issue; - } - warning(...message) { - super.warning(this._format(...message)); - } - info(...message) { - super.info(this._format(...message)); - } - error(...message) { - super.error(this._format(...message)); - } - _replaceTokens(message) { - return this._replaceTypeToken(message); - } - _replaceTypeToken(message) { - return message - .replace(/^\$\$type/, this._issue.isPullRequest ? 'Pull request' : 'Issue') - .replace(/\$\$type/g, this._issue.isPullRequest ? 'pull request' : 'issue'); - } - _prefixWithIssueNumber(message) { - return `${this._getPrefix()} ${message}`; - } - _getIssueNumber() { - return this._issue.number; - } - _format(...message) { - return this._prefixWithIssueNumber(this._replaceTokens(message.join(' '))); - } - _getPrefix() { - return this._issue.isPullRequest - ? this._getPullRequestPrefix() - : this._getIssuePrefix(); - } - _getIssuePrefix() { - return logger_service_1.LoggerService.red(`[#${this._getIssueNumber()}]`); - } - _getPullRequestPrefix() { - return logger_service_1.LoggerService.blue(`[#${this._getIssueNumber()}]`); - } -} -exports.IssueLogger = IssueLogger; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.IssueLogger = void 0; +const logger_1 = __nccwpck_require__(6212); +const logger_service_1 = __nccwpck_require__(1973); +/** + * @description + * Each log will prefix the message with the issue number + * + * @example + * warning('No stale') => "[#123] No stale" + * + * Each log method can have special tokens: + * - $$type => will replace this by either "pull request" or "issue" depending of the type of issue + * + * @example + * warning('The $$type will stale') => "The pull request will stale" + */ +class IssueLogger extends logger_1.Logger { + constructor(issue) { + super(); + this._issue = issue; + } + warning(...message) { + super.warning(this._format(...message)); + } + info(...message) { + super.info(this._format(...message)); + } + error(...message) { + super.error(this._format(...message)); + } + _replaceTokens(message) { + return this._replaceTypeToken(message); + } + _replaceTypeToken(message) { + return message + .replace(/^\$\$type/, this._issue.isPullRequest ? 'Pull request' : 'Issue') + .replace(/\$\$type/g, this._issue.isPullRequest ? 'pull request' : 'issue'); + } + _prefixWithIssueNumber(message) { + return `${this._getPrefix()} ${message}`; + } + _getIssueNumber() { + return this._issue.number; + } + _format(...message) { + return this._prefixWithIssueNumber(this._replaceTokens(message.join(' '))); + } + _getPrefix() { + return this._issue.isPullRequest + ? this._getPullRequestPrefix() + : this._getIssuePrefix(); + } + _getIssuePrefix() { + return logger_service_1.LoggerService.red(`[#${this._getIssueNumber()}]`); + } + _getPullRequestPrefix() { + return logger_service_1.LoggerService.blue(`[#${this._getIssueNumber()}]`); + } +} +exports.IssueLogger = IssueLogger; /***/ }), @@ -957,52 +957,52 @@ exports.IssueLogger = IssueLogger; /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Logger = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const terminal_link_1 = __importDefault(__nccwpck_require__(1898)); -const logger_service_1 = __nccwpck_require__(1973); -class Logger { - warning(...message) { - core.warning(logger_service_1.LoggerService.whiteBright(message.join(' '))); - } - info(...message) { - core.info(logger_service_1.LoggerService.whiteBright(message.join(' '))); - } - error(...message) { - core.error(logger_service_1.LoggerService.whiteBright(message.join(' '))); - } - createLink(name, link) { - return terminal_link_1.default(name, link); - } - createOptionLink(option) { - return logger_service_1.LoggerService.magenta(this.createLink(option, `https://github.com/actions/stale#${option}`)); - } -} -exports.Logger = Logger; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Logger = void 0; +const core = __importStar(__nccwpck_require__(2186)); +const terminal_link_1 = __importDefault(__nccwpck_require__(1898)); +const logger_service_1 = __nccwpck_require__(1973); +class Logger { + warning(...message) { + core.warning(logger_service_1.LoggerService.whiteBright(message.join(' '))); + } + info(...message) { + core.info(logger_service_1.LoggerService.whiteBright(message.join(' '))); + } + error(...message) { + core.error(logger_service_1.LoggerService.whiteBright(message.join(' '))); + } + createLink(name, link) { + return terminal_link_1.default(name, link); + } + createOptionLink(option) { + return logger_service_1.LoggerService.magenta(this.createLink(option, `https://github.com/actions/stale#${option}`)); + } +} +exports.Logger = Logger; /***/ }), @@ -1011,145 +1011,145 @@ exports.Logger = Logger; /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Milestones = void 0; -const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601)); -const option_1 = __nccwpck_require__(5931); -const words_to_list_1 = __nccwpck_require__(1883); -const issue_logger_1 = __nccwpck_require__(2984); -const logger_service_1 = __nccwpck_require__(1973); -class Milestones { - constructor(options, issue) { - this._options = options; - this._issue = issue; - this._issueLogger = new issue_logger_1.IssueLogger(issue); - } - static _cleanMilestone(milestone) { - return lodash_deburr_1.default(milestone.toLowerCase()); - } - shouldExemptMilestones() { - if (!this._issue.milestone) { - this._issueLogger.info('This $$type has no milestone'); - this._logSkip(); - return false; - } - if (this._shouldExemptAllMilestones()) { - this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has a milestone'); - return true; - } - const exemptMilestones = this._getExemptMilestones(); - if (exemptMilestones.length === 0) { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `No milestone option was specified to skip the stale process for this $$type`); - this._logSkip(); - return false; - } - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `Found ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length > 1 ? 's' : ''} that can exempt stale on this $$type`); - const hasExemptMilestone = exemptMilestones.some((exemptMilestone) => this._hasMilestone(exemptMilestone)); - if (!hasExemptMilestone) { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), 'No milestone on this $$type can exempt the stale process'); - this._logSkip(); - } - else { - this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has an exempt milestone'); - } - return hasExemptMilestone; - } - _getExemptMilestones() { - return this._issue.isPullRequest - ? this._getExemptPullRequestMilestones() - : this._getExemptIssueMilestones(); - } - _getExemptIssueMilestones() { - if (this._options.exemptIssueMilestones === '') { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); - if (this._options.exemptMilestones === '') { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); - return []; - } - const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptMilestones); - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); - return exemptMilestones; - } - const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptIssueMilestones); - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueMilestones)} is set. ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); - return exemptMilestones; - } - _getExemptPullRequestMilestones() { - if (this._options.exemptPrMilestones === '') { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); - if (this._options.exemptMilestones === '') { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); - return []; - } - const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptMilestones); - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); - return exemptMilestones; - } - const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptPrMilestones); - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrMilestones)} is set. ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); - return exemptMilestones; - } - _hasMilestone(milestone) { - if (!this._issue.milestone) { - return false; - } - const cleanMilestone = Milestones._cleanMilestone(milestone); - const isSameMilestone = cleanMilestone === - Milestones._cleanMilestone(this._issue.milestone.title); - if (isSameMilestone) { - this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The milestone "${logger_service_1.LoggerService.cyan(milestone)}" is set on this $$type and is an exempt milestone`); - } - return isSameMilestone; - } - _shouldExemptAllMilestones() { - if (this._issue.milestone) { - return this._issue.isPullRequest - ? this._shouldExemptAllPullRequestMilestones() - : this._shouldExemptAllIssueMilestones(); - } - return false; - } - _shouldExemptAllIssueMilestones() { - if (this._options.exemptAllIssueMilestones === true) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueMilestones)} is enabled. Any milestone on this $$type will skip the stale process`); - return true; - } - else if (this._options.exemptAllIssueMilestones === false) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueMilestones)} is disabled. Only some specific milestones on this $$type will skip the stale process`); - return false; - } - this._logExemptAllMilestonesOption(); - return this._options.exemptAllMilestones; - } - _shouldExemptAllPullRequestMilestones() { - if (this._options.exemptAllPrMilestones === true) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrMilestones)} is enabled. Any milestone on this $$type will skip the stale process`); - return true; - } - else if (this._options.exemptAllPrMilestones === false) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrMilestones)} is disabled. Only some specific milestones on this $$type will skip the stale process`); - return false; - } - this._logExemptAllMilestonesOption(); - return this._options.exemptAllMilestones; - } - _logExemptAllMilestonesOption() { - if (this._options.exemptAllMilestones) { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllMilestones)} is enabled. Any milestone on this $$type will skip the stale process`); - } - else { - this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllMilestones)} is disabled. Only some specific milestones on this $$type will skip the stale process`); - } - } - _logSkip() { - this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skip the milestones checks'); - } -} -exports.Milestones = Milestones; + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Milestones = void 0; +const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601)); +const option_1 = __nccwpck_require__(5931); +const words_to_list_1 = __nccwpck_require__(1883); +const issue_logger_1 = __nccwpck_require__(2984); +const logger_service_1 = __nccwpck_require__(1973); +class Milestones { + constructor(options, issue) { + this._options = options; + this._issue = issue; + this._issueLogger = new issue_logger_1.IssueLogger(issue); + } + static _cleanMilestone(milestone) { + return lodash_deburr_1.default(milestone.toLowerCase()); + } + shouldExemptMilestones() { + if (!this._issue.milestone) { + this._issueLogger.info('This $$type has no milestone'); + this._logSkip(); + return false; + } + if (this._shouldExemptAllMilestones()) { + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has a milestone'); + return true; + } + const exemptMilestones = this._getExemptMilestones(); + if (exemptMilestones.length === 0) { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `No milestone option was specified to skip the stale process for this $$type`); + this._logSkip(); + return false; + } + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `Found ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length > 1 ? 's' : ''} that can exempt stale on this $$type`); + const hasExemptMilestone = exemptMilestones.some((exemptMilestone) => this._hasMilestone(exemptMilestone)); + if (!hasExemptMilestone) { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), 'No milestone on this $$type can exempt the stale process'); + this._logSkip(); + } + else { + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skipping this $$type because it has an exempt milestone'); + } + return hasExemptMilestone; + } + _getExemptMilestones() { + return this._issue.isPullRequest + ? this._getExemptPullRequestMilestones() + : this._getExemptIssueMilestones(); + } + _getExemptIssueMilestones() { + if (this._options.exemptIssueMilestones === '') { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); + if (this._options.exemptMilestones === '') { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); + return []; + } + const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptMilestones); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + return exemptMilestones; + } + const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptIssueMilestones); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptIssueMilestones)} is set. ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + return exemptMilestones; + } + _getExemptPullRequestMilestones() { + if (this._options.exemptPrMilestones === '') { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); + if (this._options.exemptMilestones === '') { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is disabled. No specific milestone can skip the stale process for this $$type`); + return []; + } + const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptMilestones); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptMilestones)} is set. ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + return exemptMilestones; + } + const exemptMilestones = words_to_list_1.wordsToList(this._options.exemptPrMilestones); + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptPrMilestones)} is set. ${logger_service_1.LoggerService.cyan(exemptMilestones.length)} milestone${exemptMilestones.length === 1 ? '' : 's'} can skip the stale process for this $$type`); + return exemptMilestones; + } + _hasMilestone(milestone) { + if (!this._issue.milestone) { + return false; + } + const cleanMilestone = Milestones._cleanMilestone(milestone); + const isSameMilestone = cleanMilestone === + Milestones._cleanMilestone(this._issue.milestone.title); + if (isSameMilestone) { + this._issueLogger.info(logger_service_1.LoggerService.white('├──'), `The milestone "${logger_service_1.LoggerService.cyan(milestone)}" is set on this $$type and is an exempt milestone`); + } + return isSameMilestone; + } + _shouldExemptAllMilestones() { + if (this._issue.milestone) { + return this._issue.isPullRequest + ? this._shouldExemptAllPullRequestMilestones() + : this._shouldExemptAllIssueMilestones(); + } + return false; + } + _shouldExemptAllIssueMilestones() { + if (this._options.exemptAllIssueMilestones === true) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueMilestones)} is enabled. Any milestone on this $$type will skip the stale process`); + return true; + } + else if (this._options.exemptAllIssueMilestones === false) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllIssueMilestones)} is disabled. Only some specific milestones on this $$type will skip the stale process`); + return false; + } + this._logExemptAllMilestonesOption(); + return this._options.exemptAllMilestones; + } + _shouldExemptAllPullRequestMilestones() { + if (this._options.exemptAllPrMilestones === true) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrMilestones)} is enabled. Any milestone on this $$type will skip the stale process`); + return true; + } + else if (this._options.exemptAllPrMilestones === false) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllPrMilestones)} is disabled. Only some specific milestones on this $$type will skip the stale process`); + return false; + } + this._logExemptAllMilestonesOption(); + return this._options.exemptAllMilestones; + } + _logExemptAllMilestonesOption() { + if (this._options.exemptAllMilestones) { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllMilestones)} is enabled. Any milestone on this $$type will skip the stale process`); + } + else { + this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptAllMilestones)} is disabled. Only some specific milestones on this $$type will skip the stale process`); + } + } + _logSkip() { + this._issueLogger.info(logger_service_1.LoggerService.white('└──'), 'Skip the milestones checks'); + } +} +exports.Milestones = Milestones; /***/ }), @@ -1158,25 +1158,25 @@ exports.Milestones = Milestones; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Operations = void 0; -class Operations { - constructor() { - this._operationsConsumed = 0; - } - consumeOperation() { - return this.consumeOperations(1); - } - consumeOperations(quantity) { - this._operationsConsumed += quantity; - return this; - } - getConsumedOperationsCount() { - return this._operationsConsumed; - } -} -exports.Operations = Operations; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Operations = void 0; +class Operations { + constructor() { + this._operationsConsumed = 0; + } + consumeOperation() { + return this.consumeOperations(1); + } + consumeOperations(quantity) { + this._operationsConsumed += quantity; + return this; + } + getConsumedOperationsCount() { + return this._operationsConsumed; + } +} +exports.Operations = Operations; /***/ }), @@ -1185,23 +1185,23 @@ exports.Operations = Operations; /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.StaleOperations = void 0; -const operations_1 = __nccwpck_require__(7957); -class StaleOperations extends operations_1.Operations { - constructor(options) { - super(); - this._options = options; - } - hasRemainingOperations() { - return this._operationsConsumed < this._options.operationsPerRun; - } - getRemainingOperationsCount() { - return this._options.operationsPerRun - this._operationsConsumed; - } -} -exports.StaleOperations = StaleOperations; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.StaleOperations = void 0; +const operations_1 = __nccwpck_require__(7957); +class StaleOperations extends operations_1.Operations { + constructor(options) { + super(); + this._options = options; + } + hasRemainingOperations() { + return this._operationsConsumed < this._options.operationsPerRun; + } + getRemainingOperationsCount() { + return this._options.operationsPerRun - this._operationsConsumed; + } +} +exports.StaleOperations = StaleOperations; /***/ }), @@ -1210,364 +1210,364 @@ exports.StaleOperations = StaleOperations; /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Statistics = void 0; -const logger_1 = __nccwpck_require__(6212); -const logger_service_1 = __nccwpck_require__(1973); -class Statistics { - constructor() { - this._logger = new logger_1.Logger(); - this._processedIssuesCount = 0; - this._processedPullRequestsCount = 0; - this._staleIssuesCount = 0; - this._stalePullRequestsCount = 0; - this._undoStaleIssuesCount = 0; - this._undoStalePullRequestsCount = 0; - this._operationsCount = 0; - this._closedIssuesCount = 0; - this._closedPullRequestsCount = 0; - this._deletedIssuesLabelsCount = 0; - this._deletedPullRequestsLabelsCount = 0; - this._deletedCloseIssuesLabelsCount = 0; - this._deletedClosePullRequestsLabelsCount = 0; - this._deletedBranchesCount = 0; - this._addedIssuesLabelsCount = 0; - this._addedPullRequestsLabelsCount = 0; - this._addedIssuesCommentsCount = 0; - this._addedPullRequestsCommentsCount = 0; - this._fetchedItemsCount = 0; - this._fetchedItemsEventsCount = 0; - this._fetchedItemsCommentsCount = 0; - this._fetchedPullRequestsCount = 0; - } - incrementProcessedItemsCount(issue, increment = 1) { - if (issue.isPullRequest) { - return this._incrementProcessedPullRequestsCount(increment); - } - return this._incrementProcessedIssuesCount(increment); - } - incrementStaleItemsCount(issue, increment = 1) { - if (issue.isPullRequest) { - return this._incrementStalePullRequestsCount(increment); - } - return this._incrementStaleIssuesCount(increment); - } - incrementUndoStaleItemsCount(issue, increment = 1) { - if (issue.isPullRequest) { - return this._incrementUndoStalePullRequestsCount(increment); - } - return this._incrementUndoStaleIssuesCount(increment); - } - setRemainingOperations(remainingOperations) { - this._operationsCount = remainingOperations; - return this; - } - incrementClosedItemsCount(issue, increment = 1) { - if (issue.isPullRequest) { - return this._incrementClosedPullRequestsCount(increment); - } - return this._incrementClosedIssuesCount(increment); - } - incrementDeletedItemsLabelsCount(issue, increment = 1) { - if (issue.isPullRequest) { - return this._incrementDeletedPullRequestsLabelsCount(increment); - } - return this._incrementDeletedIssuesLabelsCount(increment); - } - incrementDeletedCloseItemsLabelsCount(issue, increment = 1) { - if (issue.isPullRequest) { - return this._incrementDeletedClosePullRequestsLabelsCount(increment); - } - return this._incrementDeletedCloseIssuesLabelsCount(increment); - } - incrementDeletedBranchesCount(increment = 1) { - this._deletedBranchesCount += increment; - return this; - } - incrementAddedItemsLabel(issue, increment = 1) { - if (issue.isPullRequest) { - return this._incrementAddedPullRequestsLabel(increment); - } - return this._incrementAddedIssuesLabel(increment); - } - incrementAddedItemsComment(issue, increment = 1) { - if (issue.isPullRequest) { - return this._incrementAddedPullRequestsComment(increment); - } - return this._incrementAddedIssuesComment(increment); - } - incrementFetchedItemsCount(increment = 1) { - this._fetchedItemsCount += increment; - return this; - } - incrementFetchedItemsEventsCount(increment = 1) { - this._fetchedItemsEventsCount += increment; - return this; - } - incrementFetchedItemsCommentsCount(increment = 1) { - this._fetchedItemsCommentsCount += increment; - return this; - } - incrementFetchedPullRequestsCount(increment = 1) { - this._fetchedPullRequestsCount += increment; - return this; - } - logStats() { - this._logger.info(logger_service_1.LoggerService.yellow(logger_service_1.LoggerService.bold(`Statistics:`))); - this._logProcessedIssuesAndPullRequestsCount(); - this._logStaleIssuesAndPullRequestsCount(); - this._logUndoStaleIssuesAndPullRequestsCount(); - this._logClosedIssuesAndPullRequestsCount(); - this._logDeletedIssuesAndPullRequestsLabelsCount(); - this._logDeletedCloseIssuesAndPullRequestsLabelsCount(); - this._logDeletedBranchesCount(); - this._logAddedIssuesAndPullRequestsLabelsCount(); - this._logAddedIssuesAndPullRequestsCommentsCount(); - this._logFetchedItemsCount(); - this._logFetchedItemsEventsCount(); - this._logFetchedItemsCommentsCount(); - this._logFetchedPullRequestsCount(); - this._logOperationsCount(); - return this; - } - _incrementProcessedIssuesCount(increment = 1) { - this._processedIssuesCount += increment; - return this; - } - _incrementProcessedPullRequestsCount(increment = 1) { - this._processedPullRequestsCount += increment; - return this; - } - _incrementStaleIssuesCount(increment = 1) { - this._staleIssuesCount += increment; - return this; - } - _incrementStalePullRequestsCount(increment = 1) { - this._stalePullRequestsCount += increment; - return this; - } - _incrementUndoStaleIssuesCount(increment = 1) { - this._undoStaleIssuesCount += increment; - return this; - } - _incrementUndoStalePullRequestsCount(increment = 1) { - this._undoStalePullRequestsCount += increment; - return this; - } - _incrementClosedIssuesCount(increment = 1) { - this._closedIssuesCount += increment; - return this; - } - _incrementClosedPullRequestsCount(increment = 1) { - this._closedPullRequestsCount += increment; - return this; - } - _incrementDeletedIssuesLabelsCount(increment = 1) { - this._deletedIssuesLabelsCount += increment; - return this; - } - _incrementDeletedPullRequestsLabelsCount(increment = 1) { - this._deletedPullRequestsLabelsCount += increment; - return this; - } - _incrementDeletedCloseIssuesLabelsCount(increment = 1) { - this._deletedCloseIssuesLabelsCount += increment; - return this; - } - _incrementDeletedClosePullRequestsLabelsCount(increment = 1) { - this._deletedClosePullRequestsLabelsCount += increment; - return this; - } - _incrementAddedIssuesLabel(increment = 1) { - this._addedIssuesLabelsCount += increment; - return this; - } - _incrementAddedPullRequestsLabel(increment = 1) { - this._addedPullRequestsLabelsCount += increment; - return this; - } - _incrementAddedIssuesComment(increment = 1) { - this._addedIssuesCommentsCount += increment; - return this; - } - _incrementAddedPullRequestsComment(increment = 1) { - this._addedPullRequestsCommentsCount += increment; - return this; - } - _logProcessedIssuesAndPullRequestsCount() { - this._logGroup('Processed items', [ - { - name: 'Processed issues', - count: this._processedIssuesCount - }, - { - name: 'Processed PRs', - count: this._processedPullRequestsCount - } - ]); - } - _logStaleIssuesAndPullRequestsCount() { - this._logGroup('New stale items', [ - { - name: 'New stale issues', - count: this._staleIssuesCount - }, - { - name: 'New stale PRs', - count: this._stalePullRequestsCount - } - ]); - } - _logUndoStaleIssuesAndPullRequestsCount() { - this._logGroup('No longer stale items', [ - { - name: 'No longer stale issues', - count: this._undoStaleIssuesCount - }, - { - name: 'No longer stale PRs', - count: this._undoStalePullRequestsCount - } - ]); - } - _logClosedIssuesAndPullRequestsCount() { - this._logGroup('Closed items', [ - { - name: 'Closed issues', - count: this._closedIssuesCount - }, - { - name: 'Closed PRs', - count: this._closedPullRequestsCount - } - ]); - } - _logDeletedIssuesAndPullRequestsLabelsCount() { - this._logGroup('Deleted items labels', [ - { - name: 'Deleted issues labels', - count: this._deletedIssuesLabelsCount - }, - { - name: 'Deleted PRs labels', - count: this._deletedPullRequestsLabelsCount - } - ]); - } - _logDeletedCloseIssuesAndPullRequestsLabelsCount() { - this._logGroup('Deleted close items labels', [ - { - name: 'Deleted close issues labels', - count: this._deletedCloseIssuesLabelsCount - }, - { - name: 'Deleted close PRs labels', - count: this._deletedClosePullRequestsLabelsCount - } - ]); - } - _logDeletedBranchesCount() { - this._logCount('Deleted branches', this._deletedBranchesCount); - } - _logAddedIssuesAndPullRequestsLabelsCount() { - this._logGroup('Added items labels', [ - { - name: 'Added issues labels', - count: this._addedIssuesLabelsCount - }, - { - name: 'Added PRs labels', - count: this._addedPullRequestsLabelsCount - } - ]); - } - _logAddedIssuesAndPullRequestsCommentsCount() { - this._logGroup('Added items comments', [ - { - name: 'Added issues comments', - count: this._addedIssuesCommentsCount - }, - { - name: 'Added PRs comments', - count: this._addedPullRequestsCommentsCount - } - ]); - } - _logFetchedItemsCount() { - this._logCount('Fetched items', this._fetchedItemsCount); - } - _logFetchedItemsEventsCount() { - this._logCount('Fetched items events', this._fetchedItemsEventsCount); - } - _logFetchedItemsCommentsCount() { - this._logCount('Fetched items comments', this._fetchedItemsCommentsCount); - } - _logFetchedPullRequestsCount() { - this._logCount('Fetched pull requests', this._fetchedPullRequestsCount); - } - _logOperationsCount() { - this._logCount('Operations performed', this._operationsCount); - } - _logCount(name, count) { - if (count > 0) { - this._logger.info(`${name}:`, logger_service_1.LoggerService.cyan(count)); - } - } - _logGroup(groupName, values) { - if (this._isGroupValuesPartiallySet(values)) { - this._logCount(groupName, this._getGroupValuesTotalCount(values)); - this._logGroupValues(values); - } - else { - // Only one value will be display - for (const value of values) { - this._logCount(value.name, value.count); - } - } - } - /** - * @private - * @description - * If there is a least two elements with a valid count then it's partially set - * Useful to defined if we should display the values as a group or not - * - * @param {IGroupValue[]} values The list of group values to check - */ - _isGroupValuesPartiallySet(values) { - return (values - .map((value) => { - return value.count > 0; - }) - .filter((isSet) => isSet).length >= 2); - } - _getGroupValuesTotalCount(values) { - return values.reduce((count, value) => { - return count + value.count; - }, 0); - } - _getAllGroupValuesSet(values) { - return values.filter((value) => { - return value.count > 0; - }); - } - _logGroupValues(values) { - const onlyValuesSet = this._getAllGroupValuesSet(values); - const longestValue = this._getLongestGroupValue(onlyValuesSet); - for (const [index, value] of onlyValuesSet.entries()) { - const prefix = index === onlyValuesSet.length - 1 ? '└──' : '├──'; - this._logCount(`${logger_service_1.LoggerService.white(prefix)} ${value.name.padEnd(longestValue, ' ')}`, value.count); - } - } - _getLongestGroupValue(values) { - return values.reduce((longestValue, value) => { - return value.name.length > longestValue - ? value.name.length - : longestValue; - }, 0); - } -} -exports.Statistics = Statistics; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Statistics = void 0; +const logger_1 = __nccwpck_require__(6212); +const logger_service_1 = __nccwpck_require__(1973); +class Statistics { + constructor() { + this._logger = new logger_1.Logger(); + this._processedIssuesCount = 0; + this._processedPullRequestsCount = 0; + this._staleIssuesCount = 0; + this._stalePullRequestsCount = 0; + this._undoStaleIssuesCount = 0; + this._undoStalePullRequestsCount = 0; + this._operationsCount = 0; + this._closedIssuesCount = 0; + this._closedPullRequestsCount = 0; + this._deletedIssuesLabelsCount = 0; + this._deletedPullRequestsLabelsCount = 0; + this._deletedCloseIssuesLabelsCount = 0; + this._deletedClosePullRequestsLabelsCount = 0; + this._deletedBranchesCount = 0; + this._addedIssuesLabelsCount = 0; + this._addedPullRequestsLabelsCount = 0; + this._addedIssuesCommentsCount = 0; + this._addedPullRequestsCommentsCount = 0; + this._fetchedItemsCount = 0; + this._fetchedItemsEventsCount = 0; + this._fetchedItemsCommentsCount = 0; + this._fetchedPullRequestsCount = 0; + } + incrementProcessedItemsCount(issue, increment = 1) { + if (issue.isPullRequest) { + return this._incrementProcessedPullRequestsCount(increment); + } + return this._incrementProcessedIssuesCount(increment); + } + incrementStaleItemsCount(issue, increment = 1) { + if (issue.isPullRequest) { + return this._incrementStalePullRequestsCount(increment); + } + return this._incrementStaleIssuesCount(increment); + } + incrementUndoStaleItemsCount(issue, increment = 1) { + if (issue.isPullRequest) { + return this._incrementUndoStalePullRequestsCount(increment); + } + return this._incrementUndoStaleIssuesCount(increment); + } + setRemainingOperations(remainingOperations) { + this._operationsCount = remainingOperations; + return this; + } + incrementClosedItemsCount(issue, increment = 1) { + if (issue.isPullRequest) { + return this._incrementClosedPullRequestsCount(increment); + } + return this._incrementClosedIssuesCount(increment); + } + incrementDeletedItemsLabelsCount(issue, increment = 1) { + if (issue.isPullRequest) { + return this._incrementDeletedPullRequestsLabelsCount(increment); + } + return this._incrementDeletedIssuesLabelsCount(increment); + } + incrementDeletedCloseItemsLabelsCount(issue, increment = 1) { + if (issue.isPullRequest) { + return this._incrementDeletedClosePullRequestsLabelsCount(increment); + } + return this._incrementDeletedCloseIssuesLabelsCount(increment); + } + incrementDeletedBranchesCount(increment = 1) { + this._deletedBranchesCount += increment; + return this; + } + incrementAddedItemsLabel(issue, increment = 1) { + if (issue.isPullRequest) { + return this._incrementAddedPullRequestsLabel(increment); + } + return this._incrementAddedIssuesLabel(increment); + } + incrementAddedItemsComment(issue, increment = 1) { + if (issue.isPullRequest) { + return this._incrementAddedPullRequestsComment(increment); + } + return this._incrementAddedIssuesComment(increment); + } + incrementFetchedItemsCount(increment = 1) { + this._fetchedItemsCount += increment; + return this; + } + incrementFetchedItemsEventsCount(increment = 1) { + this._fetchedItemsEventsCount += increment; + return this; + } + incrementFetchedItemsCommentsCount(increment = 1) { + this._fetchedItemsCommentsCount += increment; + return this; + } + incrementFetchedPullRequestsCount(increment = 1) { + this._fetchedPullRequestsCount += increment; + return this; + } + logStats() { + this._logger.info(logger_service_1.LoggerService.yellow(logger_service_1.LoggerService.bold(`Statistics:`))); + this._logProcessedIssuesAndPullRequestsCount(); + this._logStaleIssuesAndPullRequestsCount(); + this._logUndoStaleIssuesAndPullRequestsCount(); + this._logClosedIssuesAndPullRequestsCount(); + this._logDeletedIssuesAndPullRequestsLabelsCount(); + this._logDeletedCloseIssuesAndPullRequestsLabelsCount(); + this._logDeletedBranchesCount(); + this._logAddedIssuesAndPullRequestsLabelsCount(); + this._logAddedIssuesAndPullRequestsCommentsCount(); + this._logFetchedItemsCount(); + this._logFetchedItemsEventsCount(); + this._logFetchedItemsCommentsCount(); + this._logFetchedPullRequestsCount(); + this._logOperationsCount(); + return this; + } + _incrementProcessedIssuesCount(increment = 1) { + this._processedIssuesCount += increment; + return this; + } + _incrementProcessedPullRequestsCount(increment = 1) { + this._processedPullRequestsCount += increment; + return this; + } + _incrementStaleIssuesCount(increment = 1) { + this._staleIssuesCount += increment; + return this; + } + _incrementStalePullRequestsCount(increment = 1) { + this._stalePullRequestsCount += increment; + return this; + } + _incrementUndoStaleIssuesCount(increment = 1) { + this._undoStaleIssuesCount += increment; + return this; + } + _incrementUndoStalePullRequestsCount(increment = 1) { + this._undoStalePullRequestsCount += increment; + return this; + } + _incrementClosedIssuesCount(increment = 1) { + this._closedIssuesCount += increment; + return this; + } + _incrementClosedPullRequestsCount(increment = 1) { + this._closedPullRequestsCount += increment; + return this; + } + _incrementDeletedIssuesLabelsCount(increment = 1) { + this._deletedIssuesLabelsCount += increment; + return this; + } + _incrementDeletedPullRequestsLabelsCount(increment = 1) { + this._deletedPullRequestsLabelsCount += increment; + return this; + } + _incrementDeletedCloseIssuesLabelsCount(increment = 1) { + this._deletedCloseIssuesLabelsCount += increment; + return this; + } + _incrementDeletedClosePullRequestsLabelsCount(increment = 1) { + this._deletedClosePullRequestsLabelsCount += increment; + return this; + } + _incrementAddedIssuesLabel(increment = 1) { + this._addedIssuesLabelsCount += increment; + return this; + } + _incrementAddedPullRequestsLabel(increment = 1) { + this._addedPullRequestsLabelsCount += increment; + return this; + } + _incrementAddedIssuesComment(increment = 1) { + this._addedIssuesCommentsCount += increment; + return this; + } + _incrementAddedPullRequestsComment(increment = 1) { + this._addedPullRequestsCommentsCount += increment; + return this; + } + _logProcessedIssuesAndPullRequestsCount() { + this._logGroup('Processed items', [ + { + name: 'Processed issues', + count: this._processedIssuesCount + }, + { + name: 'Processed PRs', + count: this._processedPullRequestsCount + } + ]); + } + _logStaleIssuesAndPullRequestsCount() { + this._logGroup('New stale items', [ + { + name: 'New stale issues', + count: this._staleIssuesCount + }, + { + name: 'New stale PRs', + count: this._stalePullRequestsCount + } + ]); + } + _logUndoStaleIssuesAndPullRequestsCount() { + this._logGroup('No longer stale items', [ + { + name: 'No longer stale issues', + count: this._undoStaleIssuesCount + }, + { + name: 'No longer stale PRs', + count: this._undoStalePullRequestsCount + } + ]); + } + _logClosedIssuesAndPullRequestsCount() { + this._logGroup('Closed items', [ + { + name: 'Closed issues', + count: this._closedIssuesCount + }, + { + name: 'Closed PRs', + count: this._closedPullRequestsCount + } + ]); + } + _logDeletedIssuesAndPullRequestsLabelsCount() { + this._logGroup('Deleted items labels', [ + { + name: 'Deleted issues labels', + count: this._deletedIssuesLabelsCount + }, + { + name: 'Deleted PRs labels', + count: this._deletedPullRequestsLabelsCount + } + ]); + } + _logDeletedCloseIssuesAndPullRequestsLabelsCount() { + this._logGroup('Deleted close items labels', [ + { + name: 'Deleted close issues labels', + count: this._deletedCloseIssuesLabelsCount + }, + { + name: 'Deleted close PRs labels', + count: this._deletedClosePullRequestsLabelsCount + } + ]); + } + _logDeletedBranchesCount() { + this._logCount('Deleted branches', this._deletedBranchesCount); + } + _logAddedIssuesAndPullRequestsLabelsCount() { + this._logGroup('Added items labels', [ + { + name: 'Added issues labels', + count: this._addedIssuesLabelsCount + }, + { + name: 'Added PRs labels', + count: this._addedPullRequestsLabelsCount + } + ]); + } + _logAddedIssuesAndPullRequestsCommentsCount() { + this._logGroup('Added items comments', [ + { + name: 'Added issues comments', + count: this._addedIssuesCommentsCount + }, + { + name: 'Added PRs comments', + count: this._addedPullRequestsCommentsCount + } + ]); + } + _logFetchedItemsCount() { + this._logCount('Fetched items', this._fetchedItemsCount); + } + _logFetchedItemsEventsCount() { + this._logCount('Fetched items events', this._fetchedItemsEventsCount); + } + _logFetchedItemsCommentsCount() { + this._logCount('Fetched items comments', this._fetchedItemsCommentsCount); + } + _logFetchedPullRequestsCount() { + this._logCount('Fetched pull requests', this._fetchedPullRequestsCount); + } + _logOperationsCount() { + this._logCount('Operations performed', this._operationsCount); + } + _logCount(name, count) { + if (count > 0) { + this._logger.info(`${name}:`, logger_service_1.LoggerService.cyan(count)); + } + } + _logGroup(groupName, values) { + if (this._isGroupValuesPartiallySet(values)) { + this._logCount(groupName, this._getGroupValuesTotalCount(values)); + this._logGroupValues(values); + } + else { + // Only one value will be display + for (const value of values) { + this._logCount(value.name, value.count); + } + } + } + /** + * @private + * @description + * If there is a least two elements with a valid count then it's partially set + * Useful to defined if we should display the values as a group or not + * + * @param {IGroupValue[]} values The list of group values to check + */ + _isGroupValuesPartiallySet(values) { + return (values + .map((value) => { + return value.count > 0; + }) + .filter((isSet) => isSet).length >= 2); + } + _getGroupValuesTotalCount(values) { + return values.reduce((count, value) => { + return count + value.count; + }, 0); + } + _getAllGroupValuesSet(values) { + return values.filter((value) => { + return value.count > 0; + }); + } + _logGroupValues(values) { + const onlyValuesSet = this._getAllGroupValuesSet(values); + const longestValue = this._getLongestGroupValue(onlyValuesSet); + for (const [index, value] of onlyValuesSet.entries()) { + const prefix = index === onlyValuesSet.length - 1 ? '└──' : '├──'; + this._logCount(`${logger_service_1.LoggerService.white(prefix)} ${value.name.padEnd(longestValue, ' ')}`, value.count); + } + } + _getLongestGroupValue(values) { + return values.reduce((longestValue, value) => { + return value.name.length > longestValue + ? value.name.length + : longestValue; + }, 0); + } +} +exports.Statistics = Statistics; /***/ }), @@ -1576,52 +1576,52 @@ exports.Statistics = Statistics; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Option = void 0; -var Option; -(function (Option) { - Option["RepoToken"] = "repo-token"; - Option["StaleIssueMessage"] = "stale-issue-message"; - Option["StalePrMessage"] = "stale-pr-message"; - Option["CloseIssueMessage"] = "close-issue-message"; - Option["ClosePrMessage"] = "close-pr-message"; - Option["DaysBeforeStale"] = "days-before-stale"; - Option["DaysBeforeIssueStale"] = "days-before-issue-stale"; - Option["DaysBeforePrStale"] = "days-before-pr-stale"; - Option["DaysBeforeClose"] = "days-before-close"; - Option["DaysBeforeIssueClose"] = "days-before-issue-close"; - Option["DaysBeforePrClose"] = "days-before-pr-close"; - Option["StaleIssueLabel"] = "stale-issue-label"; - Option["CloseIssueLabel"] = "close-issue-label"; - Option["ExemptIssueLabels"] = "exempt-issue-labels"; - Option["StalePrLabel"] = "stale-pr-label"; - Option["ClosePrLabel"] = "close-pr-label"; - Option["ExemptPrLabels"] = "exempt-pr-labels"; - Option["OnlyLabels"] = "only-labels"; - Option["OnlyIssueLabels"] = "only-issue-labels"; - Option["OnlyPrLabels"] = "only-pr-labels"; - Option["AnyOfLabels"] = "any-of-labels"; - Option["OperationsPerRun"] = "operations-per-run"; - Option["RemoveStaleWhenUpdated"] = "remove-stale-when-updated"; - Option["DebugOnly"] = "debug-only"; - Option["Ascending"] = "ascending"; - Option["DeleteBranch"] = "delete-branch"; - Option["StartDate"] = "start-date"; - Option["ExemptMilestones"] = "exempt-milestones"; - Option["ExemptIssueMilestones"] = "exempt-issue-milestones"; - Option["ExemptPrMilestones"] = "exempt-pr-milestones"; - Option["ExemptAllMilestones"] = "exempt-all-milestones"; - Option["ExemptAllIssueMilestones"] = "exempt-all-issue-milestones"; - Option["ExemptAllPrMilestones"] = "exempt-all-pr-milestones"; - Option["ExemptAssignees"] = "exempt-assignees"; - Option["ExemptIssueAssignees"] = "exempt-issue-assignees"; - Option["ExemptPrAssignees"] = "exempt-pr-assignees"; - Option["ExemptAllAssignees"] = "exempt-all-assignees"; - Option["ExemptAllIssueAssignees"] = "exempt-all-issue-assignees"; - Option["ExemptAllPrAssignees"] = "exempt-all-pr-assignees"; - Option["EnableStatistics"] = "enable-statistics"; -})(Option = exports.Option || (exports.Option = {})); + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Option = void 0; +var Option; +(function (Option) { + Option["RepoToken"] = "repo-token"; + Option["StaleIssueMessage"] = "stale-issue-message"; + Option["StalePrMessage"] = "stale-pr-message"; + Option["CloseIssueMessage"] = "close-issue-message"; + Option["ClosePrMessage"] = "close-pr-message"; + Option["DaysBeforeStale"] = "days-before-stale"; + Option["DaysBeforeIssueStale"] = "days-before-issue-stale"; + Option["DaysBeforePrStale"] = "days-before-pr-stale"; + Option["DaysBeforeClose"] = "days-before-close"; + Option["DaysBeforeIssueClose"] = "days-before-issue-close"; + Option["DaysBeforePrClose"] = "days-before-pr-close"; + Option["StaleIssueLabel"] = "stale-issue-label"; + Option["CloseIssueLabel"] = "close-issue-label"; + Option["ExemptIssueLabels"] = "exempt-issue-labels"; + Option["StalePrLabel"] = "stale-pr-label"; + Option["ClosePrLabel"] = "close-pr-label"; + Option["ExemptPrLabels"] = "exempt-pr-labels"; + Option["OnlyLabels"] = "only-labels"; + Option["OnlyIssueLabels"] = "only-issue-labels"; + Option["OnlyPrLabels"] = "only-pr-labels"; + Option["AnyOfLabels"] = "any-of-labels"; + Option["OperationsPerRun"] = "operations-per-run"; + Option["RemoveStaleWhenUpdated"] = "remove-stale-when-updated"; + Option["DebugOnly"] = "debug-only"; + Option["Ascending"] = "ascending"; + Option["DeleteBranch"] = "delete-branch"; + Option["StartDate"] = "start-date"; + Option["ExemptMilestones"] = "exempt-milestones"; + Option["ExemptIssueMilestones"] = "exempt-issue-milestones"; + Option["ExemptPrMilestones"] = "exempt-pr-milestones"; + Option["ExemptAllMilestones"] = "exempt-all-milestones"; + Option["ExemptAllIssueMilestones"] = "exempt-all-issue-milestones"; + Option["ExemptAllPrMilestones"] = "exempt-all-pr-milestones"; + Option["ExemptAssignees"] = "exempt-assignees"; + Option["ExemptIssueAssignees"] = "exempt-issue-assignees"; + Option["ExemptPrAssignees"] = "exempt-pr-assignees"; + Option["ExemptAllAssignees"] = "exempt-all-assignees"; + Option["ExemptAllIssueAssignees"] = "exempt-all-issue-assignees"; + Option["ExemptAllPrAssignees"] = "exempt-all-pr-assignees"; + Option["EnableStatistics"] = "enable-statistics"; +})(Option = exports.Option || (exports.Option = {})); /***/ }), @@ -1630,22 +1630,22 @@ var Option; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getHumanizedDate = void 0; -function getHumanizedDate(date) { - const year = date.getFullYear(); - let month = `${date.getMonth() + 1}`; - let day = `${date.getDate()}`; - if (month.length < 2) { - month = `0${month}`; - } - if (day.length < 2) { - day = `0${day}`; - } - return [day, month, year].join('-'); -} -exports.getHumanizedDate = getHumanizedDate; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getHumanizedDate = void 0; +function getHumanizedDate(date) { + const year = date.getFullYear(); + let month = `${date.getMonth() + 1}`; + let day = `${date.getDate()}`; + if (month.length < 2) { + month = `0${month}`; + } + if (day.length < 2) { + day = `0${day}`; + } + return [day, month, year].join('-'); +} +exports.getHumanizedDate = getHumanizedDate; /***/ }), @@ -1654,13 +1654,13 @@ exports.getHumanizedDate = getHumanizedDate; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isDateMoreRecentThan = void 0; -function isDateMoreRecentThan(date, comparedDate) { - return date > comparedDate; -} -exports.isDateMoreRecentThan = isDateMoreRecentThan; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.isDateMoreRecentThan = void 0; +function isDateMoreRecentThan(date, comparedDate) { + return date > comparedDate; +} +exports.isDateMoreRecentThan = isDateMoreRecentThan; /***/ }), @@ -1669,27 +1669,27 @@ exports.isDateMoreRecentThan = isDateMoreRecentThan; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isValidDate = void 0; -/** - * @description - * Check if a date is valid - * - * @see - * https://stackoverflow.com/a/1353711/4440414 - * - * @param {Readonly} date The date to check - * - * @returns {boolean} true when the given date is valid - */ -function isValidDate(date) { - if (Object.prototype.toString.call(date) === '[object Date]') { - return !isNaN(date.getTime()); - } - return false; -} -exports.isValidDate = isValidDate; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.isValidDate = void 0; +/** + * @description + * Check if a date is valid + * + * @see + * https://stackoverflow.com/a/1353711/4440414 + * + * @param {Readonly} date The date to check + * + * @returns {boolean} true when the given date is valid + */ +function isValidDate(date) { + if (Object.prototype.toString.call(date) === '[object Date]') { + return !isNaN(date.getTime()); + } + return false; +} +exports.isValidDate = isValidDate; /***/ }), @@ -1698,13 +1698,13 @@ exports.isValidDate = isValidDate; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isBoolean = void 0; -function isBoolean(value) { - return value === true || value === false; -} -exports.isBoolean = isBoolean; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.isBoolean = void 0; +function isBoolean(value) { + return value === true || value === false; +} +exports.isBoolean = isBoolean; /***/ }), @@ -1713,31 +1713,31 @@ exports.isBoolean = isBoolean; /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isLabeled = void 0; -const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601)); -/** - * @description - * Check if the given label is listed as a label of the given issue - * - * @param {Readonly} issue A GitHub issue containing some labels - * @param {Readonly} label The label to check the presence with - * - * @return {boolean} Return true when the given label is also in the given issue labels - */ -function isLabeled(issue, label) { - return !!issue.labels.find((issueLabel) => { - return cleanLabel(label) === cleanLabel(issueLabel.name); - }); -} -exports.isLabeled = isLabeled; -function cleanLabel(label) { - return lodash_deburr_1.default(label.toLowerCase()); -} + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.isLabeled = void 0; +const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601)); +/** + * @description + * Check if the given label is listed as a label of the given issue + * + * @param {Readonly} issue A GitHub issue containing some labels + * @param {Readonly} label The label to check the presence with + * + * @return {boolean} Return true when the given label is also in the given issue labels + */ +function isLabeled(issue, label) { + return !!issue.labels.find((issueLabel) => { + return cleanLabel(label) === cleanLabel(issueLabel.name); + }); +} +exports.isLabeled = isLabeled; +function cleanLabel(label) { + return lodash_deburr_1.default(label.toLowerCase()); +} /***/ }), @@ -1746,13 +1746,13 @@ function cleanLabel(label) { /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isPullRequest = void 0; -function isPullRequest(issue) { - return !!issue.pull_request; -} -exports.isPullRequest = isPullRequest; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.isPullRequest = void 0; +function isPullRequest(issue) { + return !!issue.pull_request; +} +exports.isPullRequest = isPullRequest; /***/ }), @@ -1761,13 +1761,13 @@ exports.isPullRequest = isPullRequest; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.shouldMarkWhenStale = void 0; -function shouldMarkWhenStale(daysBeforeStale) { - return daysBeforeStale >= 0; -} -exports.shouldMarkWhenStale = shouldMarkWhenStale; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.shouldMarkWhenStale = void 0; +function shouldMarkWhenStale(daysBeforeStale) { + return daysBeforeStale >= 0; +} +exports.shouldMarkWhenStale = shouldMarkWhenStale; /***/ }), @@ -1776,32 +1776,32 @@ exports.shouldMarkWhenStale = shouldMarkWhenStale; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.wordsToList = void 0; -/** - * @description - * Transform a string of comma separated words - * to an array of words - * - * @example - * wordsToList('label') => ['label'] - * wordsToList('label,label') => ['label', 'label'] - * wordsToList('kebab-label') => ['kebab-label'] - * wordsToList('kebab%20label') => ['kebab%20label'] - * wordsToList('label with words') => ['label with words'] - * - * @param {Readonly} words A string of comma separated words - * - * @return {string[]} A list of words - */ -function wordsToList(words) { - if (!words.length) { - return []; - } - return words.split(',').map((word) => word.trim()); -} -exports.wordsToList = wordsToList; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.wordsToList = void 0; +/** + * @description + * Transform a string of comma separated words + * to an array of words + * + * @example + * wordsToList('label') => ['label'] + * wordsToList('label,label') => ['label', 'label'] + * wordsToList('kebab-label') => ['kebab-label'] + * wordsToList('kebab%20label') => ['kebab%20label'] + * wordsToList('label with words') => ['label with words'] + * + * @param {Readonly} words A string of comma separated words + * + * @return {string[]} A list of words + */ +function wordsToList(words) { + if (!words.length) { + return []; + } + return words.split(',').map((word) => word.trim()); +} +exports.wordsToList = wordsToList; /***/ }), @@ -1810,134 +1810,142 @@ exports.wordsToList = wordsToList; /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -const core = __importStar(__nccwpck_require__(2186)); -const issues_processor_1 = __nccwpck_require__(3292); -const is_valid_date_1 = __nccwpck_require__(891); -function _run() { - return __awaiter(this, void 0, void 0, function* () { - try { - const args = _getAndValidateArgs(); - yield new issues_processor_1.IssuesProcessor(args).processIssues(); - } - catch (error) { - core.error(error); - core.setFailed(error.message); - } - }); -} -function _getAndValidateArgs() { - const args = { - repoToken: core.getInput('repo-token'), - staleIssueMessage: core.getInput('stale-issue-message'), - stalePrMessage: core.getInput('stale-pr-message'), - closeIssueMessage: core.getInput('close-issue-message'), - closePrMessage: core.getInput('close-pr-message'), - daysBeforeStale: parseInt(core.getInput('days-before-stale', { required: true })), - daysBeforeIssueStale: parseInt(core.getInput('days-before-issue-stale')), - daysBeforePrStale: parseInt(core.getInput('days-before-pr-stale')), - daysBeforeClose: parseInt(core.getInput('days-before-close', { required: true })), - daysBeforeIssueClose: parseInt(core.getInput('days-before-issue-close')), - daysBeforePrClose: parseInt(core.getInput('days-before-pr-close')), - 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'), - onlyIssueLabels: core.getInput('only-issue-labels'), - onlyPrLabels: core.getInput('only-pr-labels'), - anyOfLabels: core.getInput('any-of-labels'), - anyOfIssueLabels: core.getInput('any-of-issue-labels'), - anyOfPrLabels: core.getInput('any-of-pr-labels'), - operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true })), - removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'), - removeIssueStaleWhenUpdated: _toOptionalBoolean(core.getInput('remove-issue-stale-when-updated')), - removePrStaleWhenUpdated: _toOptionalBoolean(core.getInput('remove-pr-stale-when-updated')), - debugOnly: core.getInput('debug-only') === 'true', - ascending: core.getInput('ascending') === 'true', - deleteBranch: core.getInput('delete-branch') === 'true', - startDate: core.getInput('start-date') !== '' - ? core.getInput('start-date') - : undefined, - exemptMilestones: core.getInput('exempt-milestones'), - exemptIssueMilestones: core.getInput('exempt-issue-milestones'), - exemptPrMilestones: core.getInput('exempt-pr-milestones'), - exemptAllMilestones: core.getInput('exempt-all-milestones') === 'true', - exemptAllIssueMilestones: _toOptionalBoolean('exempt-all-issue-milestones'), - exemptAllPrMilestones: _toOptionalBoolean('exempt-all-pr-milestones'), - exemptAssignees: core.getInput('exempt-assignees'), - exemptIssueAssignees: core.getInput('exempt-issue-assignees'), - exemptPrAssignees: core.getInput('exempt-pr-assignees'), - exemptAllAssignees: core.getInput('exempt-all-assignees') === 'true', - exemptAllIssueAssignees: _toOptionalBoolean('exempt-all-issue-assignees'), - exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-assignees'), - enableStatistics: core.getInput('enable-statistics') === 'true' - }; - for (const numberInput of [ - 'days-before-stale', - 'days-before-close', - 'operations-per-run' - ]) { - if (isNaN(parseInt(core.getInput(numberInput)))) { - const errorMessage = `Option "${numberInput}" did not parse to a valid integer`; - core.setFailed(errorMessage); - throw new Error(errorMessage); - } - } - for (const optionalDateInput of ['start-date']) { - // Ignore empty dates because it is considered as the right type for a default value (so a valid one) - if (core.getInput(optionalDateInput) !== '') { - if (!is_valid_date_1.isValidDate(new Date(core.getInput(optionalDateInput)))) { - const errorMessage = `Option "${optionalDateInput}" did not parse to a valid date`; - core.setFailed(errorMessage); - throw new Error(errorMessage); - } - } - } - return args; -} -function _toOptionalBoolean(argumentName) { - const argument = core.getInput(argumentName); - if (argument === 'true') { - return true; - } - else if (argument === 'false') { - return false; - } - return undefined; -} -void _run(); + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +const core = __importStar(__nccwpck_require__(2186)); +const issues_processor_1 = __nccwpck_require__(3292); +const is_valid_date_1 = __nccwpck_require__(891); +function _run() { + return __awaiter(this, void 0, void 0, function* () { + try { + const args = _getAndValidateArgs(); + const issueProcessor = new issues_processor_1.IssuesProcessor(args); + yield issueProcessor.processIssues(); + yield processOutput(issueProcessor.closedIssues, issueProcessor.staleIssues); + } + catch (error) { + core.error(error); + core.setFailed(error.message); + } + }); +} +function _getAndValidateArgs() { + const args = { + repoToken: core.getInput('repo-token'), + staleIssueMessage: core.getInput('stale-issue-message'), + stalePrMessage: core.getInput('stale-pr-message'), + closeIssueMessage: core.getInput('close-issue-message'), + closePrMessage: core.getInput('close-pr-message'), + daysBeforeStale: parseInt(core.getInput('days-before-stale', { required: true })), + daysBeforeIssueStale: parseInt(core.getInput('days-before-issue-stale')), + daysBeforePrStale: parseInt(core.getInput('days-before-pr-stale')), + daysBeforeClose: parseInt(core.getInput('days-before-close', { required: true })), + daysBeforeIssueClose: parseInt(core.getInput('days-before-issue-close')), + daysBeforePrClose: parseInt(core.getInput('days-before-pr-close')), + 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'), + onlyIssueLabels: core.getInput('only-issue-labels'), + onlyPrLabels: core.getInput('only-pr-labels'), + anyOfLabels: core.getInput('any-of-labels'), + anyOfIssueLabels: core.getInput('any-of-issue-labels'), + anyOfPrLabels: core.getInput('any-of-pr-labels'), + operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true })), + removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'), + removeIssueStaleWhenUpdated: _toOptionalBoolean(core.getInput('remove-issue-stale-when-updated')), + removePrStaleWhenUpdated: _toOptionalBoolean(core.getInput('remove-pr-stale-when-updated')), + debugOnly: core.getInput('debug-only') === 'true', + ascending: core.getInput('ascending') === 'true', + deleteBranch: core.getInput('delete-branch') === 'true', + startDate: core.getInput('start-date') !== '' + ? core.getInput('start-date') + : undefined, + exemptMilestones: core.getInput('exempt-milestones'), + exemptIssueMilestones: core.getInput('exempt-issue-milestones'), + exemptPrMilestones: core.getInput('exempt-pr-milestones'), + exemptAllMilestones: core.getInput('exempt-all-milestones') === 'true', + exemptAllIssueMilestones: _toOptionalBoolean('exempt-all-issue-milestones'), + exemptAllPrMilestones: _toOptionalBoolean('exempt-all-pr-milestones'), + exemptAssignees: core.getInput('exempt-assignees'), + exemptIssueAssignees: core.getInput('exempt-issue-assignees'), + exemptPrAssignees: core.getInput('exempt-pr-assignees'), + exemptAllAssignees: core.getInput('exempt-all-assignees') === 'true', + exemptAllIssueAssignees: _toOptionalBoolean('exempt-all-issue-assignees'), + exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-assignees'), + enableStatistics: core.getInput('enable-statistics') === 'true' + }; + for (const numberInput of [ + 'days-before-stale', + 'days-before-close', + 'operations-per-run' + ]) { + if (isNaN(parseInt(core.getInput(numberInput)))) { + const errorMessage = `Option "${numberInput}" did not parse to a valid integer`; + core.setFailed(errorMessage); + throw new Error(errorMessage); + } + } + for (const optionalDateInput of ['start-date']) { + // Ignore empty dates because it is considered as the right type for a default value (so a valid one) + if (core.getInput(optionalDateInput) !== '') { + if (!is_valid_date_1.isValidDate(new Date(core.getInput(optionalDateInput)))) { + const errorMessage = `Option "${optionalDateInput}" did not parse to a valid date`; + core.setFailed(errorMessage); + throw new Error(errorMessage); + } + } + } + return args; +} +function processOutput(staledIssues, closedIssues) { + return __awaiter(this, void 0, void 0, function* () { + core.setOutput('staled-issues-prs', JSON.stringify(staledIssues)); + core.setOutput('closed-issues-prs', JSON.stringify(closedIssues)); + }); +} +function _toOptionalBoolean(argumentName) { + const argument = core.getInput(argumentName); + if (argument === 'true') { + return true; + } + else if (argument === 'false') { + return false; + } + return undefined; +} +void _run(); /***/ }), @@ -1946,49 +1954,49 @@ void _run(); /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.LoggerService = void 0; -const ansi_styles_1 = __importDefault(__nccwpck_require__(2068)); -class LoggerService { - static whiteBright(message) { - return this._format(message, 'whiteBright'); - } - static yellowBright(message) { - return this._format(message, 'yellowBright'); - } - static magenta(message) { - return this._format(message, 'magenta'); - } - static cyan(message) { - return this._format(message, 'cyan'); - } - static yellow(message) { - return this._format(message, 'yellow'); - } - static white(message) { - return this._format(message, 'white'); - } - static green(message) { - return this._format(message, 'green'); - } - static red(message) { - return this._format(message, 'red'); - } - static blue(message) { - return this._format(message, 'blue'); - } - static bold(message) { - return this._format(message, 'bold'); - } - static _format(message, style) { - return `${ansi_styles_1.default[style].open}${message}${ansi_styles_1.default[style].close}`; - } -} -exports.LoggerService = LoggerService; + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.LoggerService = void 0; +const ansi_styles_1 = __importDefault(__nccwpck_require__(2068)); +class LoggerService { + static whiteBright(message) { + return this._format(message, 'whiteBright'); + } + static yellowBright(message) { + return this._format(message, 'yellowBright'); + } + static magenta(message) { + return this._format(message, 'magenta'); + } + static cyan(message) { + return this._format(message, 'cyan'); + } + static yellow(message) { + return this._format(message, 'yellow'); + } + static white(message) { + return this._format(message, 'white'); + } + static green(message) { + return this._format(message, 'green'); + } + static red(message) { + return this._format(message, 'red'); + } + static blue(message) { + return this._format(message, 'blue'); + } + static bold(message) { + return this._format(message, 'bold'); + } + static _format(message, style) { + return `${ansi_styles_1.default[style].open}${message}${ansi_styles_1.default[style].close}`; + } +} +exports.LoggerService = LoggerService; /***/ }), @@ -5661,16 +5669,13 @@ ansiEscapes.iTerm = { /***/ }), /***/ 2068: -/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => { +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { "use strict"; -__nccwpck_require__.r(__webpack_exports__); -/* harmony export */ __nccwpck_require__.d(__webpack_exports__, { -/* harmony export */ "default": () => __WEBPACK_DEFAULT_EXPORT__ -/* harmony export */ }); -const ANSI_BACKGROUND_OFFSET = 10; +/* module decorator */ module = __nccwpck_require__.nmd(module); + -const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`; +const ANSI_BACKGROUND_OFFSET = 10; const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`; @@ -5765,10 +5770,8 @@ function assembleStyles() { styles.color.close = '\u001B[39m'; styles.bgColor.close = '\u001B[49m'; - styles.color.ansi = wrapAnsi16(); styles.color.ansi256 = wrapAnsi256(); styles.color.ansi16m = wrapAnsi16m(); - styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET); styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET); styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET); @@ -5823,67 +5826,17 @@ function assembleStyles() { hexToAnsi256: { value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)), enumerable: false - }, - ansi256ToAnsi: { - value: code => { - if (code < 8) { - return 30 + code; - } - - if (code < 16) { - return 90 + (code - 8); - } - - let red; - let green; - let blue; - - if (code >= 232) { - red = (((code - 232) * 10) + 8) / 255; - green = red; - blue = red; - } else { - code -= 16; - - const remainder = code % 36; - - red = Math.floor(code / 36) / 5; - green = Math.floor(remainder / 6) / 5; - blue = (remainder % 6) / 5; - } - - const value = Math.max(red, green, blue) * 2; - - if (value === 0) { - return 30; - } - - let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red)); - - if (value === 2) { - result += 60; - } - - return result; - }, - enumerable: false - }, - rgbToAnsi: { - value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)), - enumerable: false - }, - hexToAnsi: { - value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)), - enumerable: false } }); return styles; } -const ansiStyles = assembleStyles(); - -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ansiStyles); +// Make the export immutable +Object.defineProperty(module, 'exports', { + enumerable: true, + get: assembleStyles +}); /***/ }), @@ -8874,8 +8827,8 @@ module.exports = require("zlib");; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed +/******/ id: moduleId, +/******/ loaded: false, /******/ exports: {} /******/ }; /******/ @@ -8888,36 +8841,20 @@ module.exports = require("zlib");; /******/ if(threw) delete __webpack_module_cache__[moduleId]; /******/ } /******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ -/******/ /* webpack/runtime/define property getters */ -/******/ (() => { -/******/ // define getter functions for harmony exports -/******/ __nccwpck_require__.d = (exports, definition) => { -/******/ for(var key in definition) { -/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); -/******/ } -/******/ } -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/hasOwnProperty shorthand */ -/******/ (() => { -/******/ __nccwpck_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop) -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ +/******/ /* webpack/runtime/node module decorator */ /******/ (() => { -/******/ // define __esModule on exports -/******/ __nccwpck_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ __nccwpck_require__.nmd = (module) => { +/******/ module.paths = []; +/******/ if (!module.children) module.children = []; +/******/ return module; /******/ }; /******/ })(); /******/ diff --git a/package-lock.json b/package-lock.json index 1ee3849fb..a0801ccd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7026,8 +7026,7 @@ }, "ws": { "version": "7.4.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.0.tgz", - "integrity": "sha512-kyFwXuV/5ymf+IXhS6f0+eAFvydbaBW3zjpT6hUdAh/hbVjTIB5EHBGi0bPoCLSK2wcuz3BrEkB9LrYv1Nm4NQ==", + "resolved": "", "dev": true }, "yargs": { @@ -10292,6 +10291,32 @@ "yargs": "^16.0.0" }, "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + }, + "dependencies": { + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + } + } + }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -11245,9 +11270,9 @@ } }, "ws": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.2.tgz", - "integrity": "sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA==", + "version": "7.4.6", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", + "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", "dev": true }, "xml-name-validator": { diff --git a/src/main.ts b/src/main.ts index 679c5844f..433e98c3f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,12 +2,19 @@ import * as core from '@actions/core'; import {IssuesProcessor} from './classes/issues-processor'; import {isValidDate} from './functions/dates/is-valid-date'; import {IIssuesProcessorOptions} from './interfaces/issues-processor-options'; +import {Issue} from './classes/issue'; async function _run(): Promise { try { const args = _getAndValidateArgs(); - await new IssuesProcessor(args).processIssues(); + const issueProcessor: IssuesProcessor = new IssuesProcessor(args); + await issueProcessor.processIssues(); + + await processOutput( + issueProcessor.closedIssues, + issueProcessor.staleIssues + ); } catch (error) { core.error(error); core.setFailed(error.message); @@ -103,6 +110,14 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { return args; } +async function processOutput( + staledIssues: Issue[], + closedIssues: Issue[] +): Promise { + core.setOutput('staled-issues-prs', JSON.stringify(staledIssues)); + core.setOutput('closed-issues-prs', JSON.stringify(closedIssues)); +} + function _toOptionalBoolean( argumentName: Readonly ): boolean | undefined {