Skip to content

Commit

Permalink
fix(logs): fix logs regarding updates and comments
Browse files Browse the repository at this point in the history
Fixes #503
  • Loading branch information
C0ZEN committed Jun 18, 2021
1 parent 07423be commit 473ca4b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ permissions:
issues: read
pull-requests: read
```

In addition, based on the provided configuration, the action could require more permission(s) (e.g.: add label, remove label, comment, close, etc.).
You can find more information about the required permissions under the corresponding options that you wish to use.
However, if don't want to bother, you can use these permissions:
Expand Down
50 changes: 26 additions & 24 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,36 +579,34 @@ class IssuesProcessor {
issueLogger.info(`$$type has been updated: ${logger_service_1.LoggerService.cyan(issueHasUpdate)}`);
const shouldRemoveStaleWhenUpdated = this._shouldRemoveStaleWhenUpdated(issue);
issueLogger.info(`The option ${issueLogger.createOptionLink(this._getRemoveStaleWhenUpdatedUsedOptionName(issue))} is: ${logger_service_1.LoggerService.cyan(shouldRemoveStaleWhenUpdated)}`);
if (shouldRemoveStaleWhenUpdated) {
if (!shouldRemoveStaleWhenUpdated) {
issueLogger.info(`The stale label should not be removed due to an update`);
}
else {
issueLogger.info(`The stale label should be removed if all conditions met`);
}
const shouldRemoveStaleWhenCommented = this._shouldRemoveStaleWhenCommented(issue);
issueLogger.info(`The option ${issueLogger.createOptionLink(this._getRemoveStaleWhenCommentedUsedOptionName(issue))} is: ${logger_service_1.LoggerService.cyan(shouldRemoveStaleWhenCommented)}`);
if (shouldRemoveStaleWhenCommented) {
if (!shouldRemoveStaleWhenCommented) {
issueLogger.info(`The stale label should not be removed due to a comment`);
}
else {
issueLogger.info(`The stale label should be removed if all conditions met`);
}
issueLogger.info(`Checking if the stale label should be removed...`);
// Should we un-stale this issue?
if (shouldRemoveStaleWhenUpdated && issueHasUpdate) {
issueLogger.info(`Remove the stale label since the $$type has an update and the workflow should remove the stale label when updated`);
yield this._removeStaleLabel(issue, staleLabel);
issueLogger.info(`Skipping the process since the $$type is now un-stale`);
issueLogger.info(logger_service_1.LoggerService.white('├── '), `Remove the stale label since the $$type has an update and the workflow should remove the stale label when updated`);
yield this._removeStaleLabel(issue, staleLabel, true);
issueLogger.info(logger_service_1.LoggerService.white('└── '), `Skipping the process since the $$type is now un-stale`);
return; // Nothing to do because it is no longer stale
}
else if (shouldRemoveStaleWhenCommented && issueHasComments) {
issueLogger.info(`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when commented`);
yield this._removeStaleLabel(issue, staleLabel);
issueLogger.info(logger_service_1.LoggerService.white('├── '), `Remove the stale label since the $$type has a comment and the workflow should remove the stale label when commented`);
yield this._removeStaleLabel(issue, staleLabel, true);
issueLogger.info(logger_service_1.LoggerService.white('└── '), `Skipping the process since the $$type is now un-stale`);
// Are there labels to remove or add when an issue is no longer stale?
yield this._removeLabelsWhenUnstale(issue, labelsToRemoveWhenUnstale);
yield this._addLabelsWhenUnstale(issue, labelsToAddWhenUnstale);
issueLogger.info(`Skipping the process since the $$type is now un-stale`);
return; // Nothing to do because it is no longer stale
}
else {
issueLogger.info(logger_service_1.LoggerService.white('└── '), `The stale label should not be removed`);
}
// Now start closing logic
if (daysBeforeClose < 0) {
return; // Nothing to do because we aren't closing stale issues
Expand Down Expand Up @@ -650,8 +648,8 @@ class IssuesProcessor {
const issueLogger = new issue_logger_1.IssueLogger(issue);
issueLogger.info(`Marking this $$type as stale`);
this.staleIssues.push(issue);
// if the issue is being marked stale, the updated date should be changed to right now
// so that close calculations work correctly
// If the issue is being marked stale, the updated date should be changed to right now
// So that close calculations work correctly
const newUpdatedAtDate = new Date();
issue.updated_at = newUpdatedAtDate.toString();
if (!skipMessage) {
Expand Down Expand Up @@ -796,11 +794,11 @@ class IssuesProcessor {
});
}
// Remove a label from an issue or a pull request
_removeLabel(issue, label, isSubStep = false) {
_removeLabel(issue, label, stepType = 'normal') {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const issueLogger = new issue_logger_1.IssueLogger(issue);
issueLogger.info(`${isSubStep ? logger_service_1.LoggerService.white('├── ') : ''}Removing the label "${logger_service_1.LoggerService.cyan(label)}" from this $$type...`);
issueLogger.info(`${stepType !== 'normal' ? logger_service_1.LoggerService.white('├── ') : ''}Removing the label "${logger_service_1.LoggerService.cyan(label)}" from this $$type...`);
this.removedLabelIssues.push(issue);
try {
this._consumeIssueOperation(issue);
Expand All @@ -813,10 +811,14 @@ class IssuesProcessor {
name: label
});
}
issueLogger.info(`${isSubStep ? logger_service_1.LoggerService.white('└── ') : ''}The label "${logger_service_1.LoggerService.cyan(label)}" was removed`);
issueLogger.info(`${stepType !== 'normal'
? logger_service_1.LoggerService.white(stepType === 'last' ? '└── ' : '├── ')
: ''}The label "${logger_service_1.LoggerService.cyan(label)}" was removed`);
}
catch (error) {
issueLogger.error(`${isSubStep ? logger_service_1.LoggerService.white('└── ') : ''}Error when removing the label: "${logger_service_1.LoggerService.cyan(error.message)}"`);
issueLogger.error(`${stepType !== 'normal'
? logger_service_1.LoggerService.white(stepType === 'last' ? '└── ' : '├── ')
: ''}Error when removing the label: "${logger_service_1.LoggerService.cyan(error.message)}"`);
}
});
}
Expand Down Expand Up @@ -928,12 +930,12 @@ class IssuesProcessor {
}
return this.options.removeStaleWhenCommented;
}
_removeStaleLabel(issue, staleLabel) {
_removeStaleLabel(issue, staleLabel, isSubStep = false) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const issueLogger = new issue_logger_1.IssueLogger(issue);
issueLogger.info(`The $$type is no longer stale. Removing the stale label...`);
yield this._removeLabel(issue, staleLabel);
issueLogger.info(`${isSubStep ? logger_service_1.LoggerService.white('├── ') : ''}The $$type is no longer stale. Removing the stale label...`);
yield this._removeLabel(issue, staleLabel, 'sub');
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementUndoStaleItemsCount(issue);
});
}
Expand All @@ -949,7 +951,7 @@ class IssuesProcessor {
}
if (is_labeled_1.isLabeled(issue, closeLabel)) {
issueLogger.info(logger_service_1.LoggerService.white('├──'), `The $$type has a close label "${logger_service_1.LoggerService.cyan(closeLabel)}". Removing the close label...`);
yield this._removeLabel(issue, closeLabel, true);
yield this._removeLabel(issue, closeLabel, 'last');
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedCloseItemsLabelsCount(issue);
}
else {
Expand Down
64 changes: 39 additions & 25 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,14 +615,10 @@ export class IssuesProcessor {
)} is: ${LoggerService.cyan(shouldRemoveStaleWhenUpdated)}`
);

if (shouldRemoveStaleWhenUpdated) {
if (!shouldRemoveStaleWhenUpdated) {
issueLogger.info(
`The stale label should not be removed due to an update`
);
} else {
issueLogger.info(
`The stale label should be removed if all conditions met`
);
}

const shouldRemoveStaleWhenCommented: boolean =
Expand All @@ -634,39 +630,50 @@ export class IssuesProcessor {
)} is: ${LoggerService.cyan(shouldRemoveStaleWhenCommented)}`
);

if (shouldRemoveStaleWhenCommented) {
if (!shouldRemoveStaleWhenCommented) {
issueLogger.info(
`The stale label should not be removed due to a comment`
);
} else {
issueLogger.info(
`The stale label should be removed if all conditions met`
);
}

issueLogger.info(`Checking if the stale label should be removed...`);

// Should we un-stale this issue?
if (shouldRemoveStaleWhenUpdated && issueHasUpdate) {
issueLogger.info(
LoggerService.white('├── '),
`Remove the stale label since the $$type has an update and the workflow should remove the stale label when updated`
);
await this._removeStaleLabel(issue, staleLabel);
await this._removeStaleLabel(issue, staleLabel, true);

issueLogger.info(`Skipping the process since the $$type is now un-stale`);
issueLogger.info(
LoggerService.white('└── '),
`Skipping the process since the $$type is now un-stale`
);

return; // Nothing to do because it is no longer stale
} else if (shouldRemoveStaleWhenCommented && issueHasComments) {
issueLogger.info(
LoggerService.white('├── '),
`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when commented`
);
await this._removeStaleLabel(issue, staleLabel);
await this._removeStaleLabel(issue, staleLabel, true);

issueLogger.info(
LoggerService.white('└── '),
`Skipping the process since the $$type is now un-stale`
);

// Are there labels to remove or add when an issue is no longer stale?
await this._removeLabelsWhenUnstale(issue, labelsToRemoveWhenUnstale);
await this._addLabelsWhenUnstale(issue, labelsToAddWhenUnstale);

issueLogger.info(`Skipping the process since the $$type is now un-stale`);

return; // Nothing to do because it is no longer stale
} else {
issueLogger.info(
LoggerService.white('└── '),
`The stale label should not be removed`
);
}

// Now start closing logic
Expand Down Expand Up @@ -743,8 +750,8 @@ export class IssuesProcessor {
issueLogger.info(`Marking this $$type as stale`);
this.staleIssues.push(issue);

// if the issue is being marked stale, the updated date should be changed to right now
// so that close calculations work correctly
// If the issue is being marked stale, the updated date should be changed to right now
// So that close calculations work correctly
const newUpdatedAtDate: Date = new Date();
issue.updated_at = newUpdatedAtDate.toString();

Expand Down Expand Up @@ -913,13 +920,13 @@ export class IssuesProcessor {
private async _removeLabel(
issue: Issue,
label: string,
isSubStep: Readonly<boolean> = false
stepType: Readonly<'normal' | 'sub' | 'last'> = 'normal'
): Promise<void> {
const issueLogger: IssueLogger = new IssueLogger(issue);

issueLogger.info(
`${
isSubStep ? LoggerService.white('├── ') : ''
stepType !== 'normal' ? LoggerService.white('├── ') : ''
}Removing the label "${LoggerService.cyan(label)}" from this $$type...`
);
this.removedLabelIssues.push(issue);
Expand All @@ -939,13 +946,17 @@ export class IssuesProcessor {

issueLogger.info(
`${
isSubStep ? LoggerService.white('└── ') : ''
stepType !== 'normal'
? LoggerService.white(stepType === 'last' ? '└── ' : '├── ')
: ''
}The label "${LoggerService.cyan(label)}" was removed`
);
} catch (error) {
issueLogger.error(
`${
isSubStep ? LoggerService.white('└── ') : ''
stepType !== 'normal'
? LoggerService.white(stepType === 'last' ? '└── ' : '├── ')
: ''
}Error when removing the label: "${LoggerService.cyan(error.message)}"`
);
}
Expand Down Expand Up @@ -1094,15 +1105,18 @@ export class IssuesProcessor {

private async _removeStaleLabel(
issue: Issue,
staleLabel: Readonly<string>
staleLabel: Readonly<string>,
isSubStep: Readonly<boolean> = false
): Promise<void> {
const issueLogger: IssueLogger = new IssueLogger(issue);

issueLogger.info(
`The $$type is no longer stale. Removing the stale label...`
`${
isSubStep ? LoggerService.white('├── ') : ''
}The $$type is no longer stale. Removing the stale label...`
);

await this._removeLabel(issue, staleLabel);
await this._removeLabel(issue, staleLabel, 'sub');
this._statistics?.incrementUndoStaleItemsCount(issue);
}

Expand Down Expand Up @@ -1139,7 +1153,7 @@ export class IssuesProcessor {
)}". Removing the close label...`
);

await this._removeLabel(issue, closeLabel, true);
await this._removeLabel(issue, closeLabel, 'last');
this._statistics?.incrementDeletedCloseItemsLabelsCount(issue);
} else {
issueLogger.info(
Expand Down

0 comments on commit 473ca4b

Please sign in to comment.