Apply early exit strategy for better readability
This commit is contained in:
parent
c4a13d8dca
commit
65920a0bde
|
@ -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}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue