From 4c71d4f5e949050d37e588025ad1b59f226d5241 Mon Sep 17 00:00:00 2001 From: Olivier Dagenais Date: Wed, 4 Sep 2024 21:24:26 -0400 Subject: [PATCH] refactor: extract prefixForLinePathCommit() Two methods contained an identical/duplicated block of code. --- src/parsers/Bitbucket.ts | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/parsers/Bitbucket.ts b/src/parsers/Bitbucket.ts index 7b50a40..9701640 100644 --- a/src/parsers/Bitbucket.ts +++ b/src/parsers/Bitbucket.ts @@ -155,24 +155,29 @@ export class Bitbucket extends AbstractParser { repo: string, deepCommitUrlGroups: { [key: string]: string } ) { + const prefix = this.prefixForLinePathCommit(deepCommitUrlGroups); + const linkText = `${prefix}${project}/${repo}`; + const result: Link = { + text: linkText, + destination: url, + }; + return result; + } + + private prefixForLinePathCommit(groups: { [key: string]: string }): string { var prefix = ""; - const path = deepCommitUrlGroups.path; + const path = groups.path; if (path) { - const lineNumber = deepCommitUrlGroups.lineNumber; + const lineNumber = groups.lineNumber; if (lineNumber) { prefix += `line ${lineNumber} of `; } const decodedPath = decodeURIComponent(path); prefix += `${decodedPath} at `; } - const ref = this.getPrettyRef(deepCommitUrlGroups); + const ref = this.getPrettyRef(groups); prefix += `commit ${ref} in `; - const linkText = `${prefix}${project}/${repo}`; - const result: Link = { - text: linkText, - destination: url, - }; - return result; + return prefix; } private parsePullRequest( @@ -199,17 +204,7 @@ export class Bitbucket extends AbstractParser { const prExtraMatch = extra.match(prExtraRegex); if (prExtraMatch && prExtraMatch.groups) { const prExtraGroups = prExtraMatch.groups; - const path = prExtraGroups.path; - if (path) { - const lineNumber = prExtraGroups.lineNumber; - if (lineNumber) { - prefix += `line ${lineNumber} of `; - } - const decodedPath = decodeURIComponent(path); - prefix += `${decodedPath} at `; - } - const ref = this.getPrettyRef(prExtraGroups); - prefix += `commit ${ref} in `; + prefix = this.prefixForLinePathCommit(prExtraGroups); } }