Apply early exit strategy for better readability

This commit is contained in:
Sergey Dolin 2023-01-26 21:19:56 +01:00
parent c4a13d8dca
commit 65920a0bde
1 changed files with 27 additions and 27 deletions

View File

@ -923,40 +923,40 @@ export class IssuesProcessor {
const branch = pullRequest.head.ref;
if (
pullRequest.head.repo === null ||
pullRequest.head.repo.full_name ===
`${context.repo.owner}/${context.repo.repo}`
pullRequest.head.repo?.full_name !==
`${context.repo.owner}/${context.repo.repo}`
) {
issueLogger.info(
`Deleting the branch "${LoggerService.cyan(branch)}" from closed $$type`
);
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementDeletedBranchesCount();
if (!this.options.debugOnly) {
await this.client.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branch}`
});
}
} catch (error) {
issueLogger.error(
`Error when deleting the branch "${LoggerService.cyan(
branch
)}" from $$type: ${error.message}`
);
}
} else {
issueLogger.warning(
`Deleting the branch "${LoggerService.cyan(
branch
)}" has skipped because it belongs to other repo ${
pullRequest.head.repo.full_name
pullRequest.head.repo!.full_name
}`
);
return;
}
issueLogger.info(
`Deleting the branch "${LoggerService.cyan(branch)}" from closed $$type`
);
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementDeletedBranchesCount();
if (!this.options.debugOnly) {
await this.client.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branch}`
});
}
} catch (error) {
issueLogger.error(
`Error when deleting the branch "${LoggerService.cyan(
branch
)}" from $$type: ${error.message}`
);
}
}