From 65920a0bde51d0a4dc2a33ead5150507be508573 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Thu, 26 Jan 2023 21:19:56 +0100 Subject: [PATCH] Apply early exit strategy for better readability --- src/classes/issues-processor.ts | 54 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 75024b9c..c752d320 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -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}` + ); } }