Skip to content

Commit

Permalink
feat(dry-run): display the logs and count the operations
Browse files Browse the repository at this point in the history
the dry-run checks were cancelling way sooner the workflow
the logs and the count of operations could not occur in dry run due to this
the goal of the dry run is just to skip some logic regarding the api calls to avoid altering the repos but the goal IMO is to also make them reflect the real world run so this change allow this
BTW it also allow now to test the consumed operations
Fixes #461
  • Loading branch information
C0ZEN committed Jun 3, 2021
1 parent 2242356 commit 160d990
Showing 1 changed file with 45 additions and 49 deletions.
94 changes: 45 additions & 49 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,20 +653,19 @@ export class IssuesProcessor {
const newUpdatedAtDate: Date = new Date();
issue.updated_at = newUpdatedAtDate.toString();

if (this.options.debugOnly) {
return;
}

if (!skipMessage) {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsComment(issue);
await this.client.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: staleMessage
});

if (!this.options.debugOnly) {
await this.client.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: staleMessage
});
}
} catch (error) {
issueLogger.error(`Error when creating a comment: ${error.message}`);
}
Expand Down Expand Up @@ -698,20 +697,19 @@ export class IssuesProcessor {
issueLogger.info(`Closing $$type for being stale`);
this.closedIssues.push(issue);

if (this.options.debugOnly) {
return;
}

if (closeMessage) {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsComment(issue);
await this.client.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: closeMessage
});

if (this.options.debugOnly) {
await this.client.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: closeMessage
});
}
} catch (error) {
issueLogger.error(`Error when creating a comment: ${error.message}`);
}
Expand Down Expand Up @@ -751,20 +749,19 @@ export class IssuesProcessor {
): Promise<IPullRequest | undefined | void> {
const issueLogger: IssueLogger = new IssueLogger(issue);

if (this.options.debugOnly) {
return;
}

try {
this._consumeIssueOperation(issue);
this._statistics?.incrementFetchedPullRequestsCount();
const pullRequest = await this.client.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});

return pullRequest.data;
if (this.options.debugOnly) {
const pullRequest = await this.client.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});

return pullRequest.data;
}
} catch (error) {
issueLogger.error(`Error when getting this $$type: ${error.message}`);
}
Expand All @@ -785,10 +782,6 @@ export class IssuesProcessor {
return;
}

if (this.options.debugOnly) {
return;
}

const branch = pullRequest.head.ref;
issueLogger.info(
`Deleting the branch "${LoggerService.cyan(branch)}" from closed $$type`
Expand All @@ -797,11 +790,14 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementDeletedBranchesCount();
await this.client.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branch}`
});

if (this.options.debugOnly) {
await this.client.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branch}`
});
}
} catch (error) {
issueLogger.error(
`Error when deleting the branch "${LoggerService.cyan(
Expand All @@ -826,19 +822,19 @@ export class IssuesProcessor {
);
this.removedLabelIssues.push(issue);

if (this.options.debugOnly) {
return;
}

try {
this._consumeIssueOperation(issue);
this._statistics?.incrementDeletedItemsLabelsCount(issue);
await this.client.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: label
});

if (!this.options.debugOnly) {
await this.client.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: label
});
}

issueLogger.info(
`${isSubStep ? chalk.white('└── ') : ''}The label "${LoggerService.cyan(
label
Expand Down

0 comments on commit 160d990

Please sign in to comment.