Skip to content

Commit

Permalink
refactor: extract prefixForLinePathCommit()
Browse files Browse the repository at this point in the history
Two methods contained an identical/duplicated block of code.
  • Loading branch information
olivierdagenais committed Sep 6, 2024
1 parent b0df244 commit 4c71d4f
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/parsers/Bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 4c71d4f

Please sign in to comment.