Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 128b2c8

Browse filesBrowse files
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>
1 parent f78de97 commit 128b2c8
Copy full SHA for 128b2c8

File tree

Expand file treeCollapse file tree

10 files changed

+67
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

10 files changed

+67
-0
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+8Lines changed: 8 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Every argument is optional.
9898
| [ignore-issue-updates](#ignore-issue-updates) | Override [ignore-updates](#ignore-updates) for issues only | |
9999
| [ignore-pr-updates](#ignore-pr-updates) | Override [ignore-updates](#ignore-updates) for PRs only | |
100100
| [include-only-assigned](#include-only-assigned) | Process only assigned issues | `false` |
101+
| [sort-by](#sort-by) | What to sort issues and PRs by | `created` |
101102

102103
### List of output options
103104

@@ -548,6 +549,13 @@ If set to `true`, only the issues or the pull requests with an assignee will be
548549

549550
Default value: `false`
550551

552+
#### sort-by
553+
554+
Useful to sort the issues and PRs by the specified field. It accepts `created`, `updated`, `comments`.
555+
556+
Default value: `created`
557+
558+
551559
### Usage
552560

553561
See also [action.yml](./action.yml) for a comprehensive list of all the options.
Collapse file

‎__tests__/constants/default-processor-options.ts‎

Copy file name to clipboardExpand all lines: __tests__/constants/default-processor-options.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
3232
removeIssueStaleWhenUpdated: undefined,
3333
removePrStaleWhenUpdated: undefined,
3434
ascending: false,
35+
sortBy: 'created',
3536
deleteBranch: false,
3637
startDate: '',
3738
exemptMilestones: '',
Collapse file

‎action.yml‎

Copy file name to clipboardExpand all lines: action.yml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ inputs:
136136
description: 'The order to get issues or pull requests. Defaults to false, which is descending.'
137137
default: 'false'
138138
required: false
139+
sort-by:
140+
description: 'What to sort results by. Valid options are `created`, `updated`, and `comments`. Defaults to `created`.'
141+
default: 'created'
142+
required: false
139143
delete-branch:
140144
description: 'Delete the git branch after closing a stale pull request.'
141145
default: 'false'
Collapse file

‎dist/index.js‎

Copy file name to clipboardExpand all lines: dist/index.js
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ const statistics_1 = __nccwpck_require__(3334);
382382
const logger_service_1 = __nccwpck_require__(1973);
383383
const plugin_retry_1 = __nccwpck_require__(6298);
384384
const rate_limit_1 = __nccwpck_require__(7069);
385+
const get_sort_field_1 = __nccwpck_require__(9551);
385386
/***
386387
* Handle processing of issues for staleness/closure.
387388
*/
@@ -684,6 +685,7 @@ class IssuesProcessor {
684685
state: 'open',
685686
per_page: 100,
686687
direction: this.options.ascending ? 'asc' : 'desc',
688+
sort: (0, get_sort_field_1.getSortField)(this.options.sortBy),
687689
page
688690
});
689691
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCount(issueResult.data.length);
@@ -2199,6 +2201,7 @@ var Option;
21992201
Option["RemovePrStaleWhenUpdated"] = "remove-pr-stale-when-updated";
22002202
Option["DebugOnly"] = "debug-only";
22012203
Option["Ascending"] = "ascending";
2204+
Option["SortBy"] = "sort-by";
22022205
Option["DeleteBranch"] = "delete-branch";
22032206
Option["StartDate"] = "start-date";
22042207
Option["ExemptMilestones"] = "exempt-milestones";
@@ -2333,6 +2336,25 @@ function isValidDate(date) {
23332336
exports.isValidDate = isValidDate;
23342337

23352338

2339+
/***/ }),
2340+
2341+
/***/ 9551:
2342+
/***/ ((__unused_webpack_module, exports) => {
2343+
2344+
"use strict";
2345+
2346+
Object.defineProperty(exports, "__esModule", ({ value: true }));
2347+
exports.getSortField = void 0;
2348+
function getSortField(sortOption) {
2349+
return sortOption === 'updated'
2350+
? 'updated'
2351+
: sortOption === 'comments'
2352+
? 'comments'
2353+
: 'created';
2354+
}
2355+
exports.getSortField = getSortField;
2356+
2357+
23362358
/***/ }),
23372359

23382360
/***/ 8236:
@@ -2542,6 +2564,7 @@ function _getAndValidateArgs() {
25422564
removePrStaleWhenUpdated: _toOptionalBoolean('remove-pr-stale-when-updated'),
25432565
debugOnly: core.getInput('debug-only') === 'true',
25442566
ascending: core.getInput('ascending') === 'true',
2567+
sortBy: _processParamtoString(core.getInput('sort-by')),
25452568
deleteBranch: core.getInput('delete-branch') === 'true',
25462569
startDate: core.getInput('start-date') !== ''
25472570
? core.getInput('start-date')
@@ -2628,6 +2651,13 @@ function _toOptionalBoolean(argumentName) {
26282651
}
26292652
return undefined;
26302653
}
2654+
function _processParamtoString(sortByValueInput) {
2655+
return sortByValueInput === 'updated'
2656+
? 'updated'
2657+
: sortByValueInput === 'comments'
2658+
? 'comments'
2659+
: 'created';
2660+
}
26312661
void _run();
26322662

26332663

Collapse file

‎src/classes/issue.spec.ts‎

Copy file name to clipboardExpand all lines: src/classes/issue.spec.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Issue', (): void => {
1313
beforeEach((): void => {
1414
optionsInterface = {
1515
ascending: false,
16+
sortBy: 'created',
1617
closeIssueLabel: '',
1718
closeIssueMessage: '',
1819
closePrLabel: '',
Collapse file

‎src/classes/issues-processor.ts‎

Copy file name to clipboardExpand all lines: src/classes/issues-processor.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {retry} from '@octokit/plugin-retry';
2929
import {IState} from '../interfaces/state/state';
3030
import {IRateLimit} from '../interfaces/rate-limit';
3131
import {RateLimit} from './rate-limit';
32+
import {getSortField} from '../functions/get-sort-field';
3233

3334
/***
3435
* Handle processing of issues for staleness/closure.
@@ -571,6 +572,7 @@ export class IssuesProcessor {
571572
state: 'open',
572573
per_page: 100,
573574
direction: this.options.ascending ? 'asc' : 'desc',
575+
sort: getSortField(this.options.sortBy),
574576
page
575577
});
576578
this.statistics?.incrementFetchedItemsCount(issueResult.data.length);
Collapse file

‎src/enums/option.ts‎

Copy file name to clipboardExpand all lines: src/enums/option.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export enum Option {
2626
RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated',
2727
DebugOnly = 'debug-only',
2828
Ascending = 'ascending',
29+
SortBy = 'sort-by',
2930
DeleteBranch = 'delete-branch',
3031
StartDate = 'start-date',
3132
ExemptMilestones = 'exempt-milestones',
Collapse file

‎src/functions/get-sort-field.ts‎

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type sortOptions = 'created' | 'updated' | 'comments';
2+
export function getSortField(sortOption: sortOptions): sortOptions {
3+
return sortOption === 'updated'
4+
? 'updated'
5+
: sortOption === 'comments'
6+
? 'comments'
7+
: 'created';
8+
}
Collapse file

‎src/interfaces/issues-processor-options.ts‎

Copy file name to clipboardExpand all lines: src/interfaces/issues-processor-options.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface IIssuesProcessorOptions {
3030
removePrStaleWhenUpdated: boolean | undefined;
3131
debugOnly: boolean;
3232
ascending: boolean;
33+
sortBy: 'created' | 'updated' | 'comments';
3334
deleteBranch: boolean;
3435
startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822
3536
exemptMilestones: string;
Collapse file

‎src/main.ts‎

Copy file name to clipboardExpand all lines: src/main.ts
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
9797
),
9898
debugOnly: core.getInput('debug-only') === 'true',
9999
ascending: core.getInput('ascending') === 'true',
100+
sortBy: _processParamtoString(core.getInput('sort-by')),
100101
deleteBranch: core.getInput('delete-branch') === 'true',
101102
startDate:
102103
core.getInput('start-date') !== ''
@@ -198,4 +199,14 @@ function _toOptionalBoolean(
198199
return undefined;
199200
}
200201

202+
function _processParamtoString(
203+
sortByValueInput: string
204+
): 'created' | 'updated' | 'comments' {
205+
return sortByValueInput === 'updated'
206+
? 'updated'
207+
: sortByValueInput === 'comments'
208+
? 'comments'
209+
: 'created';
210+
}
211+
201212
void _run();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.