Skip to content

Commit adfdb96

Browse files
authored
Merge branch 'main' into 909-ldap-user-group-confirmation
2 parents ed6a4ff + 37ccfb6 commit adfdb96

18 files changed

+1653
-46
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"build-lib": "./scripts/build-for-publish.sh",
1414
"restore-lib": "./scripts/undo-build.sh",
1515
"check-types": "tsc",
16-
"test": "NODE_ENV=test ts-mocha './test/*.js' --exit",
16+
"test": "NODE_ENV=test ts-mocha './test/**/*.test.js' --exit",
1717
"test-coverage": "nyc npm run test",
1818
"test-coverage-ci": "nyc --reporter=lcovonly --reporter=text npm run test",
1919
"prepare": "node ./scripts/prepare.js",

src/config/ConfigLoader.ts

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,8 @@ export class ConfigLoader extends EventEmitter {
196196
try {
197197
console.log(`Loading configuration from ${source.type} source`);
198198
return await this.loadFromSource(source);
199-
} catch (error: unknown) {
200-
if (error instanceof Error) {
201-
console.error(`Error loading from ${source.type} source:`, error.message);
202-
}
199+
} catch (error: any) {
200+
console.error(`Error loading from ${source.type} source:`, error.message);
203201
return null;
204202
}
205203
}),
@@ -234,7 +232,7 @@ export class ConfigLoader extends EventEmitter {
234232
} else {
235233
console.log('Configuration has not changed, no update needed');
236234
}
237-
} catch (error: unknown) {
235+
} catch (error: any) {
238236
console.error('Error reloading configuration:', error);
239237
this.emit('configurationError', error);
240238
} finally {
@@ -330,24 +328,18 @@ export class ConfigLoader extends EventEmitter {
330328
try {
331329
await execFileAsync('git', ['clone', source.repository, repoDir], execOptions);
332330
console.log('Repository cloned successfully');
333-
} catch (error: unknown) {
334-
if (error instanceof Error) {
335-
console.error('Failed to clone repository:', error.message);
336-
throw new Error(`Failed to clone repository: ${error.message}`);
337-
}
338-
throw error;
331+
} catch (error: any) {
332+
console.error('Failed to clone repository:', error.message);
333+
throw new Error(`Failed to clone repository: ${error.message}`);
339334
}
340335
} else {
341336
console.log(`Pulling latest changes from ${source.repository}`);
342337
try {
343338
await execFileAsync('git', ['pull'], { cwd: repoDir });
344339
console.log('Repository pulled successfully');
345-
} catch (error: unknown) {
346-
if (error instanceof Error) {
347-
console.error('Failed to pull repository:', error.message);
348-
throw new Error(`Failed to pull repository: ${error.message}`);
349-
}
350-
throw error;
340+
} catch (error: any) {
341+
console.error('Failed to pull repository:', error.message);
342+
throw new Error(`Failed to pull repository: ${error.message}`);
351343
}
352344
}
353345

@@ -357,12 +349,9 @@ export class ConfigLoader extends EventEmitter {
357349
try {
358350
await execFileAsync('git', ['checkout', source.branch], { cwd: repoDir });
359351
console.log(`Branch ${source.branch} checked out successfully`);
360-
} catch (error: unknown) {
361-
if (error instanceof Error) {
362-
console.error(`Failed to checkout branch ${source.branch}:`, error.message);
363-
throw new Error(`Failed to checkout branch ${source.branch}: ${error.message}`);
364-
}
365-
throw error;
352+
} catch (error: any) {
353+
console.error(`Failed to checkout branch ${source.branch}:`, error.message);
354+
throw new Error(`Failed to checkout branch ${source.branch}: ${error.message}`);
366355
}
367356
}
368357

@@ -382,12 +371,9 @@ export class ConfigLoader extends EventEmitter {
382371
const config = JSON.parse(content);
383372
console.log('Configuration loaded successfully from Git');
384373
return config;
385-
} catch (error: unknown) {
386-
if (error instanceof Error) {
387-
console.error('Failed to read or parse configuration file:', error.message);
388-
throw new Error(`Failed to read or parse configuration file: ${error.message}`);
389-
}
390-
throw error;
374+
} catch (error: any) {
375+
console.error('Failed to read or parse configuration file:', error.message);
376+
throw new Error(`Failed to read or parse configuration file: ${error.message}`);
391377
}
392378
}
393379

src/proxy/processors/push-action/checkAuthorEmails.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ import { Commit } from '../../actions/Action';
55
const commitConfig = getCommitConfig();
66

77
const isEmailAllowed = (email: string): boolean => {
8+
if (!email) {
9+
return false;
10+
}
11+
812
const [emailLocal, emailDomain] = email.split('@');
9-
console.log({ emailLocal, emailDomain });
1013

11-
// E-mail address is not a permissible domain name
14+
if (!emailLocal || !emailDomain) {
15+
return false;
16+
}
17+
1218
if (
1319
commitConfig.author.email.domain.allow &&
1420
!emailDomain.match(new RegExp(commitConfig.author.email.domain.allow, 'g'))
1521
) {
16-
console.log('Bad e-mail address domain...');
1722
return false;
1823
}
1924

20-
// E-mail username is not a permissible form
2125
if (
2226
commitConfig.author.email.local.block &&
2327
emailLocal.match(new RegExp(commitConfig.author.email.local.block, 'g'))
2428
) {
25-
console.log('Bad e-mail address username...');
2629
return false;
2730
}
2831

src/proxy/processors/push-action/getDiff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const exec = async (req: any, action: Action): Promise<Action> => {
1010
// https://stackoverflow.com/questions/40883798/how-to-get-git-diff-of-the-first-commit
1111
let commitFrom = `4b825dc642cb6eb9a060e54bf8d69288fbee4904`;
1212

13-
if (!action.commitData) {
13+
if (!action.commitData || action.commitData.length === 0) {
1414
throw new Error('No commit data found');
1515
}
1616

src/proxy/processors/push-action/gitleaks.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ const exec = async (req: any, action: Action): Promise<Action> => {
123123
return action;
124124
}
125125

126+
if (!config.enabled) {
127+
console.log('gitleaks is disabled, skipping');
128+
action.addStep(step);
129+
return action;
130+
}
131+
126132
const { commitFrom, commitTo } = action;
127133
const workingDir = `${action.proxyGitPath}/${action.repoName}`;
128134
console.log(`Scanning range with gitleaks: ${commitFrom}:${commitTo}`, workingDir);

0 commit comments

Comments
 (0)