Skip to content

Introducing sort-by option #1254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions __tests__/constants/default-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
ascending: false,
sortBy: 'created',
deleteBranch: false,
startDate: '',
exemptMilestones: '',
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
30 changes: 30 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -2628,6 +2651,13 @@ function _toOptionalBoolean(argumentName) {
}
return undefined;
}
function _processParamtoString(sortByValueInput) {
return sortByValueInput === 'updated'
? 'updated'
: sortByValueInput === 'comments'
? 'comments'
: 'created';
}
void _run();


Expand Down
1 change: 1 addition & 0 deletions src/classes/issue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Issue', (): void => {
beforeEach((): void => {
optionsInterface = {
ascending: false,
sortBy: 'created',
closeIssueLabel: '',
closeIssueMessage: '',
closePrLabel: '',
Expand Down
2 changes: 2 additions & 0 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/enums/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions src/functions/get-sort-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type sortOptions = 'created' | 'updated' | 'comments';
export function getSortField(sortOption: sortOptions): sortOptions {
return sortOption === 'updated'
? 'updated'
: sortOption === 'comments'
? 'comments'
: 'created';
}
1 change: 1 addition & 0 deletions src/interfaces/issues-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') !== ''
Expand Down Expand Up @@ -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();
Loading