Skip to content
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;
}
// 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 (!(0, should_mark_when_stale_1.shouldMarkWhenStale)(this._getDaysBeforeIssueStale()) &&
!(0, should_mark_when_stale_1.shouldMarkWhenStale)(this._getDaysBeforePrStale()) &&
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