From f1017f33dd159ea51366375120c3e6981d7c3097 Mon Sep 17 00:00:00 2001 From: Geoffrey Testelin Date: Thu, 10 Jun 2021 16:14:45 +0200 Subject: [PATCH] fix(dry-run): forbid mutations in dry-run (#500) Bring back the dry-run by default for the tests - bad idea to disable it sorry Fix bad documentation array format Fixes #499 --- README.md | 4 +- .../constants/default-processor-options.ts | 2 +- dist/index.js | 56 ++++++++++-------- src/classes/issues-processor.ts | 59 +++++++++++-------- 4 files changed, 66 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 84357971..fa8d2c91 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ Every argument is optional. | [remove-stale-when-updated](#remove-stale-when-updated) | Remove stale label from issues/PRs on updates/comments | `true` | | [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | | | [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | | -| [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | | -| [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | | +| [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | | +| [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | | | [debug-only](#debug-only) | Dry-run | `false` | | [ascending](#ascending) | Order to get issues/PRs | `false` | | [start-date](#start-date) | Skip stale action for issues/PRs created before it | | diff --git a/__tests__/constants/default-processor-options.ts b/__tests__/constants/default-processor-options.ts index d598775c..6f3cc5d8 100644 --- a/__tests__/constants/default-processor-options.ts +++ b/__tests__/constants/default-processor-options.ts @@ -25,7 +25,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({ anyOfIssueLabels: '', anyOfPrLabels: '', operationsPerRun: 100, - debugOnly: false, + debugOnly: true, removeStaleWhenUpdated: false, removeIssueStaleWhenUpdated: undefined, removePrStaleWhenUpdated: undefined, diff --git a/dist/index.js b/dist/index.js index 859c6a8b..66468492 100644 --- a/dist/index.js +++ b/dist/index.js @@ -661,12 +661,14 @@ class IssuesProcessor { this._consumeIssueOperation(issue); (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue); (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementStaleItemsCount(issue); - yield this.client.issues.addLabels({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issue.number, - labels: [staleLabel] - }); + if (!this.options.debugOnly) { + yield this.client.issues.addLabels({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issue.number, + labels: [staleLabel] + }); + } } catch (error) { issueLogger.error(`Error when adding a label: ${error.message}`); @@ -701,12 +703,14 @@ class IssuesProcessor { try { this._consumeIssueOperation(issue); (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue); - yield this.client.issues.addLabels({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issue.number, - labels: [closeLabel] - }); + if (!this.options.debugOnly) { + yield this.client.issues.addLabels({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issue.number, + labels: [closeLabel] + }); + } } catch (error) { issueLogger.error(`Error when adding a label: ${error.message}`); @@ -715,12 +719,14 @@ class IssuesProcessor { try { this._consumeIssueOperation(issue); (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementClosedItemsCount(issue); - yield this.client.issues.update({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - issue_number: issue.number, - state: 'closed' - }); + if (!this.options.debugOnly) { + yield this.client.issues.update({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + issue_number: issue.number, + state: 'closed' + }); + } } catch (error) { issueLogger.error(`Error when updating this $$type: ${error.message}`); @@ -734,14 +740,12 @@ class IssuesProcessor { try { this._consumeIssueOperation(issue); (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedPullRequestsCount(); - if (!this.options.debugOnly) { - const pullRequest = yield this.client.pulls.get({ - owner: github_1.context.repo.owner, - repo: github_1.context.repo.repo, - pull_number: issue.number - }); - return pullRequest.data; - } + const pullRequest = yield this.client.pulls.get({ + owner: github_1.context.repo.owner, + repo: github_1.context.repo.repo, + pull_number: issue.number + }); + return pullRequest.data; } catch (error) { issueLogger.error(`Error when getting this $$type: ${error.message}`); diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 2ca165a4..6acc00db 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -740,12 +740,15 @@ export class IssuesProcessor { this._consumeIssueOperation(issue); this._statistics?.incrementAddedItemsLabel(issue); this._statistics?.incrementStaleItemsCount(issue); - await this.client.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - labels: [staleLabel] - }); + + if (!this.options.debugOnly) { + await this.client.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + labels: [staleLabel] + }); + } } catch (error) { issueLogger.error(`Error when adding a label: ${error.message}`); } @@ -784,12 +787,15 @@ export class IssuesProcessor { try { this._consumeIssueOperation(issue); this._statistics?.incrementAddedItemsLabel(issue); - await this.client.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - labels: [closeLabel] - }); + + if (!this.options.debugOnly) { + await this.client.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + labels: [closeLabel] + }); + } } catch (error) { issueLogger.error(`Error when adding a label: ${error.message}`); } @@ -798,12 +804,15 @@ export class IssuesProcessor { try { this._consumeIssueOperation(issue); this._statistics?.incrementClosedItemsCount(issue); - await this.client.issues.update({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - state: 'closed' - }); + + if (!this.options.debugOnly) { + await this.client.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + state: 'closed' + }); + } } catch (error) { issueLogger.error(`Error when updating this $$type: ${error.message}`); } @@ -818,15 +827,13 @@ export class IssuesProcessor { this._consumeIssueOperation(issue); this._statistics?.incrementFetchedPullRequestsCount(); - if (!this.options.debugOnly) { - const pullRequest = await this.client.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: issue.number - }); + const pullRequest = await this.client.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: issue.number + }); - return pullRequest.data; - } + return pullRequest.data; } catch (error) { issueLogger.error(`Error when getting this $$type: ${error.message}`); }