Skip to content

Commit

Permalink
feat(logs): add more logs to debug the stale label removal
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Jun 3, 2021
1 parent 160d990 commit 95c9cca
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
64 changes: 53 additions & 11 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export class IssuesProcessor {
: Option.StaleIssueMessage;
}

private static _getCloseLabelUsedOptionName(
issue: Readonly<Issue>
): Option.ClosePrLabel | Option.CloseIssueLabel {
return issue.isPullRequest ? Option.ClosePrLabel : Option.CloseIssueLabel;
}

private readonly _logger: Logger = new Logger();
private readonly _operations: StaleOperations;
private readonly _statistics: Statistics | undefined;
Expand Down Expand Up @@ -565,31 +571,52 @@ export class IssuesProcessor {
`$$type has been updated: ${LoggerService.cyan(issueHasUpdate)}`
);

// should we un-stale this issue?
if (this._shouldRemoveStaleWhenUpdated(issue) && issueHasComments) {
const shouldRemoveStaleWhenUpdated: boolean = this._shouldRemoveStaleWhenUpdated(
issue
);

issueLogger.info(
`The option ${issueLogger.createOptionLink(
this._getRemoveStaleWhenUpdatedUsedOptionName(issue)
)} is: ${chalk.cyan(shouldRemoveStaleWhenUpdated)}`
);

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

// Should we un-stale this issue?
if (shouldRemoveStaleWhenUpdated && issueHasComments) {
issueLogger.info(
`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when updated`
);
await this._removeStaleLabel(issue, staleLabel);

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

return; // nothing to do because it is no longer stale
return; // Nothing to do because it is no longer stale
}

// now start closing logic
// Now start closing logic
if (daysBeforeClose < 0) {
return; // nothing to do because we aren't closing stale issues
return; // Nothing to do because we aren't closing stale issues
}

if (!issueHasComments && !issueHasUpdate) {
issueLogger.info(
`Closing $$type because it was last updated on! ${LoggerService.cyan(
`Closing $$type because it was last updated on: ${LoggerService.cyan(
issue.updated_at
)}`
);
await this._closeIssue(issue, closeMessage, closeLabel);

if (this.options.deleteBranch && issue.pull_request) {
issueLogger.info(
`Deleting the branch the option ${issueLogger.createOptionLink(
`Deleting the branch since the option ${issueLogger.createOptionLink(
Option.DeleteBranch
)} was specified`
);
Expand Down Expand Up @@ -945,7 +972,7 @@ export class IssuesProcessor {
issueLogger.info(
chalk.white('├──'),
`The ${issueLogger.createOptionLink(
this._getCloseLabelUsedOptionName(issue)
IssuesProcessor._getCloseLabelUsedOptionName(issue)
)} option was not set`
);
issueLogger.info(
Expand Down Expand Up @@ -1008,9 +1035,24 @@ export class IssuesProcessor {
: Option.DaysBeforePrStale;
}

private _getCloseLabelUsedOptionName(
private _getRemoveStaleWhenUpdatedUsedOptionName(
issue: Readonly<Issue>
): Option.ClosePrLabel | Option.CloseIssueLabel {
return issue.isPullRequest ? Option.ClosePrLabel : Option.CloseIssueLabel;
):
| Option.RemovePrStaleWhenUpdated
| Option.RemoveStaleWhenUpdated
| Option.RemoveIssueStaleWhenUpdated {
if (issue.isPullRequest) {
if (isBoolean(this.options.removePrStaleWhenUpdated)) {
return Option.RemovePrStaleWhenUpdated;
}

return Option.RemoveStaleWhenUpdated;
}

if (isBoolean(this.options.removeIssueStaleWhenUpdated)) {
return Option.RemoveIssueStaleWhenUpdated;
}

return Option.RemoveStaleWhenUpdated;
}
}
2 changes: 2 additions & 0 deletions src/enums/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export enum Option {
AnyOfLabels = 'any-of-labels',
OperationsPerRun = 'operations-per-run',
RemoveStaleWhenUpdated = 'remove-stale-when-updated',
RemoveIssueStaleWhenUpdated = 'remove-issue-stale-when-updated',
RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated',
DebugOnly = 'debug-only',
Ascending = 'ascending',
DeleteBranch = 'delete-branch',
Expand Down

0 comments on commit 95c9cca

Please sign in to comment.