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

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

View File

@@ -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);

View File

@@ -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',

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;
debugOnly: boolean;
ascending: boolean;
sortBy: 'created' | 'updated' | 'comments';
deleteBranch: boolean;
startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822
exemptMilestones: string;

View File

@@ -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();