docs(stale-issue-comment): update the docs to remove that omitting the option will not send a message (#522)

* chore(assignees): add logs

* docs(stale-issue-comment): update the docs to remove that omitting will not send a message

To be sure, what would be even better is to add a test using the default config (because the main issue is that the default options of the specs are not matching the ones from the action).

Closes #521

* test(comment): add more coverage to test the stale issue message

* docs(readme): improve the wording

Co-authored-by: Luke Tomlinson <luketomlinson@github.com>

* refactor: simplify the code to use the stats for the specs

* chore(rebase): fix rebase issue

* chore(statistics): fix issue due to rebase

Co-authored-by: Luke Tomlinson <luketomlinson@github.com>
This commit is contained in:
Geoffrey Testelin
2021-09-22 15:18:19 +02:00
committed by GitHub
parent 9912fa74d1
commit b98591d49e
5 changed files with 258 additions and 176 deletions

View File

@@ -69,8 +69,9 @@ export class IssuesProcessor {
readonly deletedBranchIssues: Issue[] = [];
readonly removedLabelIssues: Issue[] = [];
readonly addedLabelIssues: Issue[] = [];
readonly addedCloseCommentIssues: Issue[] = [];
readonly statistics: Statistics | undefined;
private readonly _logger: Logger = new Logger();
private readonly _statistics: Statistics | undefined;
constructor(options: IIssuesProcessorOptions) {
this.options = options;
@@ -93,7 +94,7 @@ export class IssuesProcessor {
}
if (this.options.enableStatistics) {
this._statistics = new Statistics();
this.statistics = new Statistics();
}
}
@@ -105,7 +106,7 @@ export class IssuesProcessor {
this._logger.info(
LoggerService.green(`No more issues found to process. Exiting...`)
);
this._statistics
this.statistics
?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats();
@@ -158,7 +159,7 @@ export class IssuesProcessor {
'option which is currently set to'
)} ${LoggerService.cyan(this.options.operationsPerRun)}`
);
this._statistics
this.statistics
?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats();
@@ -180,7 +181,7 @@ export class IssuesProcessor {
labelsToAddWhenUnstale: Readonly<string>[],
labelsToRemoveWhenUnstale: Readonly<string>[]
): Promise<void> {
this._statistics?.incrementProcessedItemsCount(issue);
this.statistics?.incrementProcessedItemsCount(issue);
const issueLogger: IssueLogger = new IssueLogger(issue);
issueLogger.info(
@@ -515,7 +516,7 @@ export class IssuesProcessor {
// Find any comments since date on the given issue
try {
this.operations.consumeOperation();
this._statistics?.incrementFetchedItemsCommentsCount();
this.statistics?.incrementFetchedItemsCommentsCount();
const comments = await this.client.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
@@ -546,7 +547,7 @@ export class IssuesProcessor {
direction: this.options.ascending ? 'asc' : 'desc',
page
});
this._statistics?.incrementFetchedItemsCount(issueResult.data.length);
this.statistics?.incrementFetchedItemsCount(issueResult.data.length);
return issueResult.data.map(
(issue: Readonly<IIssue>): Issue => new Issue(this.options, issue)
@@ -568,7 +569,7 @@ export class IssuesProcessor {
issueLogger.info(`Checking for label on this $$type`);
this._consumeIssueOperation(issue);
this._statistics?.incrementFetchedItemsEventsCount();
this.statistics?.incrementFetchedItemsEventsCount();
const options = this.client.issues.listEvents.endpoint.merge({
owner: context.repo.owner,
repo: context.repo.repo,
@@ -598,7 +599,7 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementFetchedPullRequestsCount();
this.statistics?.incrementFetchedPullRequestsCount();
const pullRequest = await this.client.pulls.get({
owner: context.repo.owner,
@@ -771,7 +772,7 @@ export class IssuesProcessor {
if (!skipMessage) {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsComment(issue);
this.statistics?.incrementAddedItemsComment(issue);
if (!this.options.debugOnly) {
await this.client.issues.createComment({
@@ -788,8 +789,8 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsLabel(issue);
this._statistics?.incrementStaleItemsCount(issue);
this.statistics?.incrementAddedItemsLabel(issue);
this.statistics?.incrementStaleItemsCount(issue);
if (!this.options.debugOnly) {
await this.client.issues.addLabels({
@@ -818,7 +819,8 @@ export class IssuesProcessor {
if (closeMessage) {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsComment(issue);
this.statistics?.incrementAddedItemsComment(issue);
this.addedCloseCommentIssues.push(issue);
if (!this.options.debugOnly) {
await this.client.issues.createComment({
@@ -836,7 +838,7 @@ export class IssuesProcessor {
if (closeLabel) {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsLabel(issue);
this.statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) {
await this.client.issues.addLabels({
@@ -853,7 +855,7 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementClosedItemsCount(issue);
this.statistics?.incrementClosedItemsCount(issue);
if (!this.options.debugOnly) {
await this.client.issues.update({
@@ -872,7 +874,11 @@ export class IssuesProcessor {
private async _deleteBranch(issue: Issue): Promise<void> {
const issueLogger: IssueLogger = new IssueLogger(issue);
issueLogger.info(`Delete branch from closed $$type - ${issue.title}`);
issueLogger.info(`Delete
branch from closed $
$type
-
${issue.title}`);
const pullRequest: IPullRequest | undefined | void =
await this.getPullRequest(issue);
@@ -891,7 +897,7 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementDeletedBranchesCount();
this.statistics?.incrementDeletedBranchesCount();
if (!this.options.debugOnly) {
await this.client.git.deleteRef({
@@ -926,7 +932,7 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementDeletedItemsLabelsCount(issue);
this.statistics?.incrementDeletedItemsLabelsCount(issue);
if (!this.options.debugOnly) {
await this.client.issues.removeLabel({
@@ -1060,7 +1066,7 @@ export class IssuesProcessor {
try {
this.operations.consumeOperation();
this._statistics?.incrementAddedItemsLabel(issue);
this.statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) {
await this.client.issues.addLabels({
owner: context.repo.owner,
@@ -1087,7 +1093,7 @@ export class IssuesProcessor {
);
await this._removeLabel(issue, staleLabel);
this._statistics?.incrementUndoStaleItemsCount(issue);
this.statistics?.incrementUndoStaleItemsCount(issue);
}
private async _removeCloseLabel(
@@ -1124,7 +1130,7 @@ export class IssuesProcessor {
);
await this._removeLabel(issue, closeLabel, true);
this._statistics?.incrementDeletedCloseItemsLabelsCount(issue);
this.statistics?.incrementDeletedCloseItemsLabelsCount(issue);
} else {
issueLogger.info(
LoggerService.white('└──'),