diff --git a/README.md b/README.md index 51a609f9..0474e1e9 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ Every argument is optional. | [ignore-issue-updates](#ignore-issue-updates) | Override [ignore-updates](#ignore-updates) for issues only | | | [ignore-pr-updates](#ignore-pr-updates) | Override [ignore-updates](#ignore-updates) for PRs only | | | [include-only-assigned](#include-only-assigned) | Process only assigned issues | `false` | +| [sort-by](#sort-by) | What to sort issues and PRs by | `created` | ### List of output options @@ -548,6 +549,13 @@ If set to `true`, only the issues or the pull requests with an assignee will be Default value: `false` +#### sort-by + +Useful to sort the issues and PRs by the specified field. It accepts `created`, `updated`, `comments`. + +Default value: `created` + + ### Usage See also [action.yml](./action.yml) for a comprehensive list of all the options. diff --git a/__tests__/constants/default-processor-options.ts b/__tests__/constants/default-processor-options.ts index 0265b644..4ea04cca 100644 --- a/__tests__/constants/default-processor-options.ts +++ b/__tests__/constants/default-processor-options.ts @@ -32,6 +32,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({ removeIssueStaleWhenUpdated: undefined, removePrStaleWhenUpdated: undefined, ascending: false, + sortBy: 'created', deleteBranch: false, startDate: '', exemptMilestones: '', diff --git a/action.yml b/action.yml index d55f8547..ee689362 100644 --- a/action.yml +++ b/action.yml @@ -136,6 +136,10 @@ inputs: description: 'The order to get issues or pull requests. Defaults to false, which is descending.' default: 'false' required: false + sort-by: + description: 'What to sort results by. Valid options are `created`, `updated`, and `comments`. Defaults to `created`.' + default: 'created' + required: false delete-branch: description: 'Delete the git branch after closing a stale pull request.' default: 'false' diff --git a/dist/index.js b/dist/index.js index 50ec5fed..582c6551 100644 --- a/dist/index.js +++ b/dist/index.js @@ -382,6 +382,7 @@ const statistics_1 = __nccwpck_require__(3334); const logger_service_1 = __nccwpck_require__(1973); const plugin_retry_1 = __nccwpck_require__(6298); const rate_limit_1 = __nccwpck_require__(7069); +const get_sort_field_1 = __nccwpck_require__(9551); /*** * Handle processing of issues for staleness/closure. */ @@ -684,6 +685,7 @@ class IssuesProcessor { state: 'open', per_page: 100, direction: this.options.ascending ? 'asc' : 'desc', + sort: (0, get_sort_field_1.getSortField)(this.options.sortBy), page }); (_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCount(issueResult.data.length); @@ -2199,6 +2201,7 @@ var Option; Option["RemovePrStaleWhenUpdated"] = "remove-pr-stale-when-updated"; Option["DebugOnly"] = "debug-only"; Option["Ascending"] = "ascending"; + Option["SortBy"] = "sort-by"; Option["DeleteBranch"] = "delete-branch"; Option["StartDate"] = "start-date"; Option["ExemptMilestones"] = "exempt-milestones"; @@ -2333,6 +2336,25 @@ function isValidDate(date) { exports.isValidDate = isValidDate; +/***/ }), + +/***/ 9551: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getSortField = void 0; +function getSortField(sortOption) { + return sortOption === 'updated' + ? 'updated' + : sortOption === 'comments' + ? 'comments' + : 'created'; +} +exports.getSortField = getSortField; + + /***/ }), /***/ 8236: @@ -2542,6 +2564,7 @@ function _getAndValidateArgs() { removePrStaleWhenUpdated: _toOptionalBoolean('remove-pr-stale-when-updated'), debugOnly: core.getInput('debug-only') === 'true', ascending: core.getInput('ascending') === 'true', + sortBy: _processParamtoString(core.getInput('sort-by')), deleteBranch: core.getInput('delete-branch') === 'true', startDate: core.getInput('start-date') !== '' ? core.getInput('start-date') @@ -2628,6 +2651,13 @@ function _toOptionalBoolean(argumentName) { } return undefined; } +function _processParamtoString(sortByValueInput) { + return sortByValueInput === 'updated' + ? 'updated' + : sortByValueInput === 'comments' + ? 'comments' + : 'created'; +} void _run(); diff --git a/src/classes/issue.spec.ts b/src/classes/issue.spec.ts index a2c82e26..5a5bf32d 100644 --- a/src/classes/issue.spec.ts +++ b/src/classes/issue.spec.ts @@ -13,6 +13,7 @@ describe('Issue', (): void => { beforeEach((): void => { optionsInterface = { ascending: false, + sortBy: 'created', closeIssueLabel: '', closeIssueMessage: '', closePrLabel: '', diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 486c6a78..56c9ecb5 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -29,6 +29,7 @@ import {retry} from '@octokit/plugin-retry'; import {IState} from '../interfaces/state/state'; import {IRateLimit} from '../interfaces/rate-limit'; import {RateLimit} from './rate-limit'; +import {getSortField} from '../functions/get-sort-field'; /*** * Handle processing of issues for staleness/closure. @@ -571,6 +572,7 @@ export class IssuesProcessor { state: 'open', per_page: 100, direction: this.options.ascending ? 'asc' : 'desc', + sort: getSortField(this.options.sortBy), page }); this.statistics?.incrementFetchedItemsCount(issueResult.data.length); diff --git a/src/enums/option.ts b/src/enums/option.ts index 7a9bff02..c7833858 100644 --- a/src/enums/option.ts +++ b/src/enums/option.ts @@ -26,6 +26,7 @@ export enum Option { RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated', DebugOnly = 'debug-only', Ascending = 'ascending', + SortBy = 'sort-by', DeleteBranch = 'delete-branch', StartDate = 'start-date', ExemptMilestones = 'exempt-milestones', diff --git a/src/functions/get-sort-field.ts b/src/functions/get-sort-field.ts new file mode 100644 index 00000000..478c8771 --- /dev/null +++ b/src/functions/get-sort-field.ts @@ -0,0 +1,8 @@ +type sortOptions = 'created' | 'updated' | 'comments'; +export function getSortField(sortOption: sortOptions): sortOptions { + return sortOption === 'updated' + ? 'updated' + : sortOption === 'comments' + ? 'comments' + : 'created'; +} diff --git a/src/interfaces/issues-processor-options.ts b/src/interfaces/issues-processor-options.ts index 93099228..ea379af1 100644 --- a/src/interfaces/issues-processor-options.ts +++ b/src/interfaces/issues-processor-options.ts @@ -30,6 +30,7 @@ export interface IIssuesProcessorOptions { removePrStaleWhenUpdated: boolean | undefined; debugOnly: boolean; ascending: boolean; + sortBy: 'created' | 'updated' | 'comments'; deleteBranch: boolean; startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822 exemptMilestones: string; diff --git a/src/main.ts b/src/main.ts index a7836c16..e1eae661 100644 --- a/src/main.ts +++ b/src/main.ts @@ -97,6 +97,7 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { ), debugOnly: core.getInput('debug-only') === 'true', ascending: core.getInput('ascending') === 'true', + sortBy: _processParamtoString(core.getInput('sort-by')), deleteBranch: core.getInput('delete-branch') === 'true', startDate: core.getInput('start-date') !== '' @@ -198,4 +199,14 @@ function _toOptionalBoolean( return undefined; } +function _processParamtoString( + sortByValueInput: string +): 'created' | 'updated' | 'comments' { + return sortByValueInput === 'updated' + ? 'updated' + : sortByValueInput === 'comments' + ? 'comments' + : 'created'; +} + void _run();