Skip to content

Commit 814455c

Browse files
committed
fix: trim ref/heads/ only from the prefix
Do the same for the trailing .git for the ref/heads/ prefix to be safe and clean things up.
1 parent 74d5081 commit 814455c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/db/helper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ export const trimTrailingDotGit = (str: string): string => {
1313
return str;
1414
};
1515

16+
export const trimPrefixRefsHeads = (str: string): string => {
17+
const target = 'refs/heads/';
18+
if (str.startsWith(target)) {
19+
// extract string from the end of the target to the end of str
20+
return str.slice(target.length);
21+
}
22+
return str;
23+
};

src/ui/views/OpenPushRequests/components/PushesTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { KeyboardArrowRight } from '@material-ui/icons';
1616
import Search from '../../../components/Search/Search';
1717
import Pagination from '../../../components/Pagination/Pagination';
1818
import { PushData } from '../../../../types/models';
19-
import { trimTrailingDotGit } from '../../../../db/helper';
19+
import { trimPrefixRefsHeads, trimTrailingDotGit } from '../../../../db/helper';
2020

2121
interface PushesTableProps {
2222
[key: string]: any;
@@ -102,7 +102,7 @@ const PushesTable: React.FC<PushesTableProps> = (props) => {
102102
<TableBody>
103103
{[...currentItems].reverse().map((row) => {
104104
const repoFullName = trimTrailingDotGit(row.repo);
105-
const repoBranch = row.branch.replace('refs/heads/', '');
105+
const repoBranch = trimPrefixRefsHeads(row.branch);
106106
const commitTimestamp =
107107
row.commitData[0]?.commitTs || row.commitData[0]?.commitTimestamp;
108108

src/ui/views/PushDetails/PushDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { CheckCircle, Visibility, Cancel, Block } from '@material-ui/icons';
2323
import Snackbar from '@material-ui/core/Snackbar';
2424
import Tooltip from '@material-ui/core/Tooltip';
2525
import { PushData } from '../../../types/models';
26-
import { trimTrailingDotGit } from '../../../db/helper';
26+
import { trimPrefixRefsHeads, trimTrailingDotGit } from '../../../db/helper';
2727

2828
const Dashboard: React.FC = () => {
2929
const { id } = useParams<{ id: string }>();
@@ -107,7 +107,7 @@ const Dashboard: React.FC = () => {
107107
}
108108

109109
const repoFullName = trimTrailingDotGit(data.repo);
110-
const repoBranch = data.branch.replace('refs/heads/', '');
110+
const repoBranch = trimPrefixRefsHeads(data.branch);
111111

112112
const generateIcon = (title: string) => {
113113
switch (title) {

0 commit comments

Comments
 (0)