Skip to content
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

Filter issues by labels when listing if possible #1084

Open
wants to merge 1 commit 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
21 changes: 21 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,12 +676,33 @@ class IssuesProcessor {
getIssues(page) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
// Compute labels filter.
let labels = '';
// We can filter issues already when listing them if neither only-pr-labels
// nor only-issue-labels are specified or both are the same.
if (this.options.onlyPrLabels === '' &&
this.options.onlyIssueLabels === '') {
labels = this.options.onlyLabels;
}
else if (this.options.onlyPrLabels == this.options.onlyIssueLabels) {
labels = this.options.onlyIssueLabels;
}
mraleph marked this conversation as resolved.
Show resolved Hide resolved
// If we don't have to mark issues and pull requests stale and
// both the stale labels are the same then we can use it as a filter:
mraleph marked this conversation as resolved.
Show resolved Hide resolved
// because we only want to process stale issues.
if (!(0, should_mark_when_stale_1.shouldMarkWhenStale)(this._getDaysBeforeIssueStale()) &&
!(0, should_mark_when_stale_1.shouldMarkWhenStale)(this._getDaysBeforePrStale()) &&
mraleph marked this conversation as resolved.
Show resolved Hide resolved
this.options.stalePrLabel === this.options.staleIssueLabel &&
!labels.includes(this.options.staleIssueLabel)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The includes doesn't require the text to be an entire label. If we have labels stale and maybe-stale, then the includes('stale') will match a maybe-stale label.
Consider over-engineering this as:

!new RegExp('(?:^|,)' + this.options.staleIssueLabel + '(?:,|$)').test(labels)

If there can be surrounding whitespace around the label, then:

!new RegExp('(?:^|,)\\s*' + this.options.staleIssueLabel + '\\s*(?:,|$)').test(labels)

(Or the, maybe, more memory-intensive, but less RegExp-y:

  ![...labels.split(',').map(s=>s.trim())].includes(this.options.staleIssueLable)

)

labels += (labels !== '' ? ',' : '') + this.options.staleIssueLabel;
}
try {
this.operations.consumeOperation();
const issueResult = yield this.client.rest.issues.listForRepo({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
state: 'open',
labels,
per_page: 100,
direction: this.options.ascending ? 'asc' : 'desc',
page
Expand Down
27 changes: 27 additions & 0 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,39 @@ export class IssuesProcessor {

// grab issues from github in batches of 100
async getIssues(page: number): Promise<Issue[]> {
// Compute labels filter.
let labels = '';

// We can filter issues already when listing them if neither only-pr-labels
// nor only-issue-labels are specified or both are the same.
if (
this.options.onlyPrLabels === '' &&
this.options.onlyIssueLabels === ''
) {
labels = this.options.onlyLabels;
} else if (this.options.onlyPrLabels == this.options.onlyIssueLabels) {
labels = this.options.onlyIssueLabels;
}

// If we don't have to mark issues and pull requests stale and
// both the stale labels are the same then we can use it as a filter:
// because we only want to process stale issues.
if (
!shouldMarkWhenStale(this._getDaysBeforeIssueStale()) &&
!shouldMarkWhenStale(this._getDaysBeforePrStale()) &&
this.options.stalePrLabel === this.options.staleIssueLabel &&
!labels.includes(this.options.staleIssueLabel)
) {
labels += (labels !== '' ? ',' : '') + this.options.staleIssueLabel;
}

try {
this.operations.consumeOperation();
const issueResult = await this.client.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels,
per_page: 100,
direction: this.options.ascending ? 'asc' : 'desc',
page
Expand Down
Loading