Skip to content

Commit 33cf19f

Browse files
authored
Merge branch 'main' into fix-dos-when-pushing-unkown-repo
2 parents 46b3a67 + 4956b73 commit 33cf19f

File tree

94 files changed

+2918
-2084
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+2918
-2084
lines changed

.github/workflows/unused-dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
node-version: '22.x'
2222
- name: 'Run depcheck'
2323
run: |
24-
npx depcheck --skip-missing --ignores="tsx,@babel/*,@commitlint/*,eslint,eslint-*,husky,mocha,ts-mocha,ts-node,concurrently,nyc,prettier,typescript,tsconfig-paths,vite-tsconfig-paths"
24+
npx depcheck --skip-missing --ignores="tsx,@babel/*,@commitlint/*,eslint,eslint-*,husky,mocha,ts-mocha,ts-node,concurrently,nyc,prettier,typescript,tsconfig-paths,vite-tsconfig-paths,history,@types/domutils"
2525
echo $?
2626
if [[ $? == 1 ]]; then
2727
echo "Unused dependencies or devDependencies found"

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@
7979
To create a production bundle, use `npm run build` or `yarn build`.
8080
-->
8181
</body>
82-
<script type="module" src="/src/index.jsx"></script>
82+
<script type="module" src="/src/index.tsx"></script>
8383
</html>

package-lock.json

Lines changed: 96 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@finos/git-proxy",
3-
"version": "1.18.2",
3+
"version": "1.19.1",
44
"description": "Deploy custom push protections and policies on top of Git.",
55
"scripts": {
66
"cli": "node ./packages/git-proxy-cli/index.js",
7-
"client": "vite --config vite.config.js",
7+
"client": "vite --config vite.config.ts",
88
"clientinstall": "npm install --prefix client",
99
"server": "tsx index.ts",
1010
"start": "concurrently \"npm run server\" \"npm run client\"",
@@ -88,14 +88,17 @@
8888
"@babel/preset-react": "^7.22.5",
8989
"@commitlint/cli": "^19.0.0",
9090
"@commitlint/config-conventional": "^19.0.0",
91+
"@types/domutils": "^1.7.8",
9192
"@types/express": "^5.0.1",
9293
"@types/express-http-proxy": "^1.6.6",
9394
"@types/lodash": "^4.17.15",
9495
"@types/mocha": "^10.0.10",
9596
"@types/node": "^22.13.5",
97+
"@types/react-dom": "^17.0.11",
98+
"@types/react-html-parser": "^2.0.7",
9699
"@types/yargs": "^17.0.33",
97-
"@typescript-eslint/eslint-plugin": "^8.26.1",
98-
"@typescript-eslint/parser": "^8.26.1",
100+
"@typescript-eslint/eslint-plugin": "^8.29.0",
101+
"@typescript-eslint/parser": "^8.29.0",
99102
"@vitejs/plugin-react": "^4.0.2",
100103
"chai": "^4.2.0",
101104
"chai-http": "^4.3.0",

src/ui/views/RepoList/Components/RepoOverview.jsx renamed to src/constants/languageColors.ts

Lines changed: 2 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import React, { useEffect } from 'react';
2-
import { Snackbar, TableCell, TableRow } from '@material-ui/core';
3-
import GridContainer from '../../../components/Grid/GridContainer';
4-
import GridItem from '../../../components/Grid/GridItem';
5-
import { CodeReviewIcon, LawIcon, PeopleIcon } from '@primer/octicons-react';
1+
// src/constants/languageColors.ts
62

7-
const colors = {
3+
export const languageColors: Record<string, string> = {
84
'1C Enterprise': '#814CCC',
95
'2-Dimensional Array': '#38761D',
106
'4D': '#004289',
@@ -563,125 +559,3 @@ const colors = {
563559
ZIL: '#dc75e5',
564560
Zimpl: '#d67711',
565561
};
566-
567-
import axios from 'axios';
568-
import moment from 'moment';
569-
import CodeActionButton from '../../../components/CustomButtons/CodeActionButton';
570-
571-
export default function Repositories(props) {
572-
const [github, setGitHub] = React.useState({});
573-
574-
const [errorMessage, setErrorMessage] = React.useState('');
575-
const [snackbarOpen, setSnackbarOpen] = React.useState(false);
576-
577-
useEffect(() => {
578-
getGitHubRepository();
579-
}, [props.data.project, props.data.name]);
580-
581-
const getGitHubRepository = async () => {
582-
await axios
583-
.get(`https://api.github.com/repos/${props.data.project}/${props.data.name}`)
584-
.then((res) => {
585-
setGitHub(res.data);
586-
})
587-
.catch((error) => {
588-
setErrorMessage(`Error fetching GitHub repository ${props.data.project}/${props.data.name}: ${error}`);
589-
setSnackbarOpen(true);
590-
});
591-
};
592-
593-
const { project: org, name, proxyURL } = props?.data || {};
594-
const cloneURL = `${proxyURL}/${org}/${name}.git`;
595-
596-
return (
597-
<TableRow>
598-
<TableCell>
599-
<div style={{ padding: '15px' }}>
600-
<a href={`/dashboard/repo/${props.data.name}`}>
601-
<span style={{ fontSize: '17px' }}>
602-
{props.data.project}/{props.data.name}
603-
</span>
604-
</a>
605-
{github.parent && (
606-
<span
607-
style={{
608-
fontSize: '11.5px',
609-
display: 'block',
610-
opacity: 0.8,
611-
}}
612-
>
613-
Forked from{' '}
614-
<a
615-
style={{
616-
fontWeight: 'normal',
617-
color: 'inherit',
618-
}}
619-
href={github.parent.html_url}
620-
>
621-
{github.parent.full_name}
622-
</a>
623-
</span>
624-
)}
625-
{github.description && <p style={{ maxWidth: '80%' }}>{github.description}</p>}
626-
<GridContainer>
627-
{github.language && (
628-
<GridItem>
629-
<span
630-
style={{
631-
height: '12px',
632-
width: '12px',
633-
backgroundColor: `${colors[github.language]}`,
634-
borderRadius: '50px',
635-
display: 'inline-block',
636-
marginRight: '5px',
637-
}}
638-
></span>
639-
{github.language}
640-
</GridItem>
641-
)}
642-
{github.license && (
643-
<GridItem>
644-
<LawIcon size='small' />{' '}
645-
<span style={{ marginLeft: '5px' }}>{github.license.spdx_id}</span>
646-
</GridItem>
647-
)}
648-
<GridItem>
649-
<PeopleIcon size='small' />{' '}
650-
<span style={{ marginLeft: '5px' }}>{props.data.users?.canPush?.length || 0}</span>
651-
</GridItem>
652-
<GridItem>
653-
<CodeReviewIcon size='small' />{' '}
654-
<span style={{ marginLeft: '5px' }}>
655-
{props.data.users?.canAuthorise?.length || 0}
656-
</span>
657-
</GridItem>
658-
{(github.created_at || github.updated_at || github.pushed_at) && (
659-
<GridItem>
660-
Last updated{' '}
661-
{moment
662-
.max([
663-
moment(github.created_at),
664-
moment(github.updated_at),
665-
moment(github.pushed_at),
666-
])
667-
.fromNow()}
668-
</GridItem>
669-
)}
670-
</GridContainer>
671-
</div>
672-
</TableCell>
673-
<TableCell align='right'>
674-
<div style={{ padding: '15px' }}>
675-
<CodeActionButton cloneURL={cloneURL} />
676-
</div>
677-
</TableCell>
678-
<Snackbar
679-
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
680-
open={snackbarOpen}
681-
autoHideDuration={6000}
682-
onClose={() => setSnackbarOpen(false)}
683-
message={errorMessage}
684-
/>
685-
</TableRow>
686-
);
687-
}

src/context.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/context.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createContext } from 'react';
2+
import { UserContextType } from './ui/views/RepoDetails/RepoDetails';
3+
4+
export const UserContext = createContext<UserContextType>({
5+
user: {
6+
admin: false,
7+
},
8+
});

src/db/file/pushes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import _ from 'lodash';
33
import Datastore from '@seald-io/nedb';
44
import { Action } from '../../proxy/actions/Action';
5-
import { toClass } from '../helper';
5+
import { toClass, trimTrailingDotGit } from '../helper';
66
import * as repo from './repo';
77
import { PushQuery } from '../types';
88

@@ -138,7 +138,7 @@ export const canUserCancelPush = async (id: string, user: string) => {
138138
return;
139139
}
140140

141-
const repoName = pushDetail.repoName.replace('.git', '');
141+
const repoName = trimTrailingDotGit(pushDetail.repoName);
142142
const isAllowed = await repo.isUserPushAllowed(repoName, user);
143143

144144
if (isAllowed) {
@@ -156,7 +156,8 @@ export const canUserApproveRejectPush = async (id: string, user: string) => {
156156
resolve(false);
157157
return;
158158
}
159-
const repoName = action.repoName.replace('.git', '');
159+
160+
const repoName = trimTrailingDotGit(action.repoName);
160161
const isAllowed = await repo.canUserApproveRejectPushRepo(repoName, user);
161162

162163
resolve(isAllowed);

src/db/helper.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,21 @@ export const toClass = function (obj: any, proto: any) {
33
obj.__proto__ = proto;
44
return obj;
55
};
6+
7+
export const trimTrailingDotGit = (str: string): string => {
8+
const target = '.git';
9+
if (str.endsWith(target)) {
10+
// extract string from 0 to the end minus the length of target
11+
return str.slice(0, -target.length);
12+
}
13+
return str;
14+
};
15+
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/db/mongo/pushes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { connect, findDocuments, findOneDocument } from './helper';
22
import { Action } from '../../proxy/actions';
3-
import { toClass } from '../helper';
3+
import { toClass, trimTrailingDotGit } from '../helper';
44
import * as repo from './repo';
55
import { Push, PushQuery } from '../types';
66

@@ -108,7 +108,7 @@ export const canUserApproveRejectPush = async (id: string, user: string) => {
108108
return;
109109
}
110110

111-
const repoName = action.repoName.replace('.git', '');
111+
const repoName = trimTrailingDotGit(action.repoName);
112112
const isAllowed = await repo.canUserApproveRejectPushRepo(repoName, user);
113113

114114
resolve(isAllowed);
@@ -123,7 +123,7 @@ export const canUserCancelPush = async (id: string, user: string) => {
123123
return;
124124
}
125125

126-
const repoName = pushDetail.repoName.replace('.git', '');
126+
const repoName = trimTrailingDotGit(pushDetail.repoName);
127127
const isAllowed = await repo.isUserPushAllowed(repoName, user);
128128

129129
if (isAllowed) {

0 commit comments

Comments
 (0)