Introducing sort-by option (#1254)

* sort-issues-by introduced

* action.yml updated

* pushing the build code

* Update action.yml

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update README.md for the new parameter (sort-issues-by)

* minor text format changes in README.md

* final draft of sort-issues-by

* Update src/interfaces/issues-processor-options.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/classes/issues-processor.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* refactored the code

* test

* test

* final changes

* update in README.md

* Documentation update

* updated sort-issues-by to sort-by

* minor changes

* dist fixes

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
suyashgaonkar
2025-07-11 09:00:19 +05:30
committed by GitHub
parent f78de9780e
commit 128b2c81d0
10 changed files with 67 additions and 0 deletions

View File

@@ -98,6 +98,7 @@ Every argument is optional.
| [ignore-issue-updates](#ignore-issue-updates) | Override [ignore-updates](#ignore-updates) for issues only | | | [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 | | | [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` | | [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 ### 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` 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 ### Usage
See also [action.yml](./action.yml) for a comprehensive list of all the options. See also [action.yml](./action.yml) for a comprehensive list of all the options.

View File

@@ -32,6 +32,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
removeIssueStaleWhenUpdated: undefined, removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined, removePrStaleWhenUpdated: undefined,
ascending: false, ascending: false,
sortBy: 'created',
deleteBranch: false, deleteBranch: false,
startDate: '', startDate: '',
exemptMilestones: '', exemptMilestones: '',

View File

@@ -136,6 +136,10 @@ inputs:
description: 'The order to get issues or pull requests. Defaults to false, which is descending.' description: 'The order to get issues or pull requests. Defaults to false, which is descending.'
default: 'false' default: 'false'
required: 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: delete-branch:
description: 'Delete the git branch after closing a stale pull request.' description: 'Delete the git branch after closing a stale pull request.'
default: 'false' default: 'false'

30
dist/index.js vendored
View File

@@ -382,6 +382,7 @@ const statistics_1 = __nccwpck_require__(3334);
const logger_service_1 = __nccwpck_require__(1973); const logger_service_1 = __nccwpck_require__(1973);
const plugin_retry_1 = __nccwpck_require__(6298); const plugin_retry_1 = __nccwpck_require__(6298);
const rate_limit_1 = __nccwpck_require__(7069); const rate_limit_1 = __nccwpck_require__(7069);
const get_sort_field_1 = __nccwpck_require__(9551);
/*** /***
* Handle processing of issues for staleness/closure. * Handle processing of issues for staleness/closure.
*/ */
@@ -684,6 +685,7 @@ class IssuesProcessor {
state: 'open', state: 'open',
per_page: 100, per_page: 100,
direction: this.options.ascending ? 'asc' : 'desc', direction: this.options.ascending ? 'asc' : 'desc',
sort: (0, get_sort_field_1.getSortField)(this.options.sortBy),
page page
}); });
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCount(issueResult.data.length); (_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["RemovePrStaleWhenUpdated"] = "remove-pr-stale-when-updated";
Option["DebugOnly"] = "debug-only"; Option["DebugOnly"] = "debug-only";
Option["Ascending"] = "ascending"; Option["Ascending"] = "ascending";
Option["SortBy"] = "sort-by";
Option["DeleteBranch"] = "delete-branch"; Option["DeleteBranch"] = "delete-branch";
Option["StartDate"] = "start-date"; Option["StartDate"] = "start-date";
Option["ExemptMilestones"] = "exempt-milestones"; Option["ExemptMilestones"] = "exempt-milestones";
@@ -2333,6 +2336,25 @@ function isValidDate(date) {
exports.isValidDate = isValidDate; 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: /***/ 8236:
@@ -2542,6 +2564,7 @@ function _getAndValidateArgs() {
removePrStaleWhenUpdated: _toOptionalBoolean('remove-pr-stale-when-updated'), removePrStaleWhenUpdated: _toOptionalBoolean('remove-pr-stale-when-updated'),
debugOnly: core.getInput('debug-only') === 'true', debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true', ascending: core.getInput('ascending') === 'true',
sortBy: _processParamtoString(core.getInput('sort-by')),
deleteBranch: core.getInput('delete-branch') === 'true', deleteBranch: core.getInput('delete-branch') === 'true',
startDate: core.getInput('start-date') !== '' startDate: core.getInput('start-date') !== ''
? core.getInput('start-date') ? core.getInput('start-date')
@@ -2628,6 +2651,13 @@ function _toOptionalBoolean(argumentName) {
} }
return undefined; return undefined;
} }
function _processParamtoString(sortByValueInput) {
return sortByValueInput === 'updated'
? 'updated'
: sortByValueInput === 'comments'
? 'comments'
: 'created';
}
void _run(); void _run();

View File

@@ -13,6 +13,7 @@ describe('Issue', (): void => {
beforeEach((): void => { beforeEach((): void => {
optionsInterface = { optionsInterface = {
ascending: false, ascending: false,
sortBy: 'created',
closeIssueLabel: '', closeIssueLabel: '',
closeIssueMessage: '', closeIssueMessage: '',
closePrLabel: '', closePrLabel: '',

View File

@@ -29,6 +29,7 @@ import {retry} from '@octokit/plugin-retry';
import {IState} from '../interfaces/state/state'; import {IState} from '../interfaces/state/state';
import {IRateLimit} from '../interfaces/rate-limit'; import {IRateLimit} from '../interfaces/rate-limit';
import {RateLimit} from './rate-limit'; import {RateLimit} from './rate-limit';
import {getSortField} from '../functions/get-sort-field';
/*** /***
* Handle processing of issues for staleness/closure. * Handle processing of issues for staleness/closure.
@@ -571,6 +572,7 @@ export class IssuesProcessor {
state: 'open', state: 'open',
per_page: 100, per_page: 100,
direction: this.options.ascending ? 'asc' : 'desc', direction: this.options.ascending ? 'asc' : 'desc',
sort: getSortField(this.options.sortBy),
page page
}); });
this.statistics?.incrementFetchedItemsCount(issueResult.data.length); this.statistics?.incrementFetchedItemsCount(issueResult.data.length);

View File

@@ -26,6 +26,7 @@ export enum Option {
RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated', RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated',
DebugOnly = 'debug-only', DebugOnly = 'debug-only',
Ascending = 'ascending', Ascending = 'ascending',
SortBy = 'sort-by',
DeleteBranch = 'delete-branch', DeleteBranch = 'delete-branch',
StartDate = 'start-date', StartDate = 'start-date',
ExemptMilestones = 'exempt-milestones', ExemptMilestones = 'exempt-milestones',

View File

@@ -0,0 +1,8 @@
type sortOptions = 'created' | 'updated' | 'comments';
export function getSortField(sortOption: sortOptions): sortOptions {
return sortOption === 'updated'
? 'updated'
: sortOption === 'comments'
? 'comments'
: 'created';
}

View File

@@ -30,6 +30,7 @@ export interface IIssuesProcessorOptions {
removePrStaleWhenUpdated: boolean | undefined; removePrStaleWhenUpdated: boolean | undefined;
debugOnly: boolean; debugOnly: boolean;
ascending: boolean; ascending: boolean;
sortBy: 'created' | 'updated' | 'comments';
deleteBranch: boolean; deleteBranch: boolean;
startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822 startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822
exemptMilestones: string; exemptMilestones: string;

View File

@@ -97,6 +97,7 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
), ),
debugOnly: core.getInput('debug-only') === 'true', debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true', ascending: core.getInput('ascending') === 'true',
sortBy: _processParamtoString(core.getInput('sort-by')),
deleteBranch: core.getInput('delete-branch') === 'true', deleteBranch: core.getInput('delete-branch') === 'true',
startDate: startDate:
core.getInput('start-date') !== '' core.getInput('start-date') !== ''
@@ -198,4 +199,14 @@ function _toOptionalBoolean(
return undefined; return undefined;
} }
function _processParamtoString(
sortByValueInput: string
): 'created' | 'updated' | 'comments' {
return sortByValueInput === 'updated'
? 'updated'
: sortByValueInput === 'comments'
? 'comments'
: 'created';
}
void _run(); void _run();