Skip to content

Commit b5cd038

Browse files
committed
chore: extended prettier format command to package/git-proxy-cli and ran it
1 parent ddcc149 commit b5cd038

Some content is hidden

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

41 files changed

+268
-262
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"prepare": "node ./scripts/prepare.js",
1717
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx,json}\" \"test/**/*.{js,jsx,ts,tsx,json}\"",
1818
"lint:fix": "eslint --fix \"src/**/*.{js,jsx,ts,tsx,json}\" \"test/**/*.{js,jsx,ts,tsx,json}\"",
19-
"format": "prettier --write src/**/*.{js,jsx,ts,tsx,css,md,json,scss} test/**/*.{js,jsx,ts,tsx,json} --config ./.prettierrc",
19+
"format": "prettier --write src/**/*.{js,jsx,ts,tsx,css,md,json,scss} test/**/*.{js,jsx,ts,tsx,json} packages/git-proxy-cli/test/**/*.{js,jsx,ts,tsx,json} packages/git-proxy-cli/index.js --config ./.prettierrc",
2020
"gen-schema-doc": "node ./scripts/doc-schema.js",
2121
"cypress:run": "cypress run"
2222
},

packages/git-proxy-cli/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const util = require('util');
77

88
const GIT_PROXY_COOKIE_FILE = 'git-proxy-cookie';
99
// GitProxy UI HOST and PORT (configurable via environment variable)
10-
const { GIT_PROXY_UI_HOST: uiHost = 'http://localhost', GIT_PROXY_UI_PORT: uiPort = 8080 } = process.env;
10+
const { GIT_PROXY_UI_HOST: uiHost = 'http://localhost', GIT_PROXY_UI_PORT: uiPort = 8080 } =
11+
process.env;
1112

1213
const baseUrl = `${uiHost}:${uiPort}`;
1314

packages/git-proxy-cli/test/testCli.proxy.config.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"tempPassword": {
33
"sendEmail": false,
4-
"emailConfig": {
5-
}
4+
"emailConfig": {}
65
},
76
"authorisedList": [
87
{
@@ -22,9 +21,9 @@
2221
{
2322
"type": "mongo",
2423
"connectionString": "mongodb://localhost:27017/gitproxy",
25-
"options": {
24+
"options": {
2625
"useUnifiedTopology": true
27-
},
26+
},
2827
"enabled": false
2928
}
3029
],

src/config/env.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const {
99
GIT_PROXY_SERVER_PORT = 8000,
1010
GIT_PROXY_HTTPS_SERVER_PORT = 8443,
1111
GIT_PROXY_UI_HOST = 'http://localhost',
12-
GIT_PROXY_UI_PORT = 8080
12+
GIT_PROXY_UI_PORT = 8080,
1313
} = process.env;
1414

1515
export const serverConfig: ServerConfig = {
1616
GIT_PROXY_SERVER_PORT,
1717
GIT_PROXY_HTTPS_SERVER_PORT,
1818
GIT_PROXY_UI_HOST,
19-
GIT_PROXY_UI_PORT
19+
GIT_PROXY_UI_PORT,
2020
};

src/db/mongo/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const connect = async (collectionName: string): Promise<Collection> => {
2525
export const findDocuments = async <T>(
2626
collectionName: string,
2727
filter: Filter<Document> = {},
28-
options: FindOptions<Document> = {}
28+
options: FindOptions<Document> = {},
2929
): Promise<T[]> => {
3030
const collection = await connect(collectionName);
3131
return collection.find(filter, options).toArray() as Promise<T[]>;
@@ -34,7 +34,7 @@ export const findDocuments = async <T>(
3434
export const findOneDocument = async <T>(
3535
collectionName: string,
3636
filter: Filter<Document> = {},
37-
options: FindOptions<Document> = {}
37+
options: FindOptions<Document> = {},
3838
): Promise<T | null> => {
3939
const collection = await connect(collectionName);
4040
return (await collection.findOne(filter, options)) as T | null;

src/db/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export type PushQuery = {
22
error: boolean;
3-
blocked: boolean,
4-
allowPush: boolean,
5-
authorised: boolean
3+
blocked: boolean;
4+
allowPush: boolean;
5+
authorised: boolean;
66
};
77

88
export type UserRole = 'canPush' | 'canAuthorise';

src/plugin.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ function isCompatiblePlugin(obj: any, propertyName: string = 'isGitProxyPlugin')
1515
// valid plugin objects will have the appropriate property set to true
1616
// if the prototype chain is exhausted, return false
1717
while (obj != null) {
18-
if (Object.prototype.hasOwnProperty.call(obj, propertyName) &&
18+
if (
19+
Object.prototype.hasOwnProperty.call(obj, propertyName) &&
1920
obj.isGitProxyPlugin &&
20-
Object.keys(obj).includes('exec')) {
21+
Object.keys(obj).includes('exec')
22+
) {
2123
return true;
2224
}
2325
obj = Object.getPrototypeOf(obj);
@@ -55,42 +57,48 @@ class PluginLoader {
5557
*/
5658
async load(): Promise<void> {
5759
try {
58-
const modulePromises = this.targets.map(target =>
59-
this._loadPluginModule(target).catch(error => {
60+
const modulePromises = this.targets.map((target) =>
61+
this._loadPluginModule(target).catch((error) => {
6062
console.error(`Failed to load plugin: ${error}`); // TODO: log.error()
6163
return Promise.reject(error); // Or return an error object to handle it later
62-
})
64+
}),
6365
);
6466

6567
const moduleResults = await Promise.allSettled(modulePromises);
6668
const loadedModules = moduleResults
67-
.filter((result): result is PromiseFulfilledResult<any> => result.status === 'fulfilled' && result.value !== null)
68-
.map(result => result.value);
69+
.filter(
70+
(result): result is PromiseFulfilledResult<any> =>
71+
result.status === 'fulfilled' && result.value !== null,
72+
)
73+
.map((result) => result.value);
6974

7075
console.log(`Found ${loadedModules.length} plugin modules`); // TODO: log.debug()
7176

72-
const pluginTypeResultPromises = loadedModules.map(mod =>
73-
this._getPluginObjects(mod).catch(error => {
77+
const pluginTypeResultPromises = loadedModules.map((mod) =>
78+
this._getPluginObjects(mod).catch((error) => {
7479
console.error(`Failed to cast plugin objects: ${error}`); // TODO: log.error()
7580
return Promise.reject(error); // Or return an error object to handle it later
76-
})
81+
}),
7782
);
7883

7984
const settledPluginTypeResults = await Promise.allSettled(pluginTypeResultPromises);
8085
/**
8186
* @type {PluginTypeResult[]} List of resolved PluginTypeResult objects
8287
*/
8388
const pluginTypeResults = settledPluginTypeResults
84-
.filter((result): result is PromiseFulfilledResult<any> => result.status === 'fulfilled' && result.value !== null)
85-
.map(result => result.value);
89+
.filter(
90+
(result): result is PromiseFulfilledResult<any> =>
91+
result.status === 'fulfilled' && result.value !== null,
92+
)
93+
.map((result) => result.value);
8694

8795
for (const result of pluginTypeResults) {
88-
this.pushPlugins.push(...result.pushAction)
89-
this.pullPlugins.push(...result.pullAction)
96+
this.pushPlugins.push(...result.pushAction);
97+
this.pullPlugins.push(...result.pullAction);
9098
}
9199

92100
const combinedPlugins = [...this.pushPlugins, ...this.pullPlugins];
93-
combinedPlugins.forEach(plugin => {
101+
combinedPlugins.forEach((plugin) => {
94102
console.log(`Loaded plugin: ${plugin.constructor.name}`);
95103
});
96104
} catch (error) {
@@ -128,15 +136,17 @@ class PluginLoader {
128136
console.log('found pull plugin', potentialModule.constructor.name);
129137
plugins.pullAction.push(potentialModule);
130138
} else {
131-
console.error(`Error: Object ${potentialModule.constructor.name} does not seem to be a compatible plugin type`);
139+
console.error(
140+
`Error: Object ${potentialModule.constructor.name} does not seem to be a compatible plugin type`,
141+
);
132142
}
133143
}
134144

135145
// handles the default export case
136146
// `module.exports = new ProxyPlugin()` in CJS or `exports default new ProxyPlugin()` in ESM
137147
// the "module" is a single object that could be a plugin
138148
if (isCompatiblePlugin(pluginModule)) {
139-
handlePlugin(pluginModule)
149+
handlePlugin(pluginModule);
140150
} else {
141151
// handle the typical case of a module which exports multiple objects
142152
// module.exports = { x, y } (CJS) or multiple `export ...` statements (ESM)
@@ -173,11 +183,11 @@ class PushActionPlugin extends ProxyPlugin {
173183
* Wrapper class which contains at least one function executed as part of the action chain for git push operations.
174184
* The function must be called `exec` and take in two parameters: an Express Request (req) and the current Action
175185
* executed in the chain (action). This function should return a Promise that resolves to an Action.
176-
*
186+
*
177187
* Optionally, child classes which extend this can simply define the `exec` function as their own property.
178188
* This is the preferred implementation when a custom plugin (subclass) has its own state or additional methods
179189
* that are required.
180-
*
190+
*
181191
* @param {function} exec - A function that:
182192
* - Takes in an Express Request object as the first parameter (`req`).
183193
* - Takes in an Action object as the second parameter (`action`).
@@ -201,11 +211,11 @@ class PullActionPlugin extends ProxyPlugin {
201211
* Wrapper class which contains at least one function executed as part of the action chain for git pull operations.
202212
* The function must be called `exec` and take in two parameters: an Express Request (req) and the current Action
203213
* executed in the chain (action). This function should return a Promise that resolves to an Action.
204-
*
214+
*
205215
* Optionally, child classes which extend this can simply define the `exec` function as their own property.
206216
* This is the preferred implementation when a custom plugin (subclass) has its own state or additional methods
207217
* that are required.
208-
*
218+
*
209219
* @param {function} exec - A function that:
210220
* - Takes in an Express Request object as the first parameter (`req`).
211221
* - Takes in an Action object as the second parameter (`action`).
@@ -218,9 +228,4 @@ class PullActionPlugin extends ProxyPlugin {
218228
}
219229
}
220230

221-
export {
222-
PluginLoader,
223-
PushActionPlugin,
224-
PullActionPlugin,
225-
isCompatiblePlugin,
226-
}
231+
export { PluginLoader, PushActionPlugin, PullActionPlugin, isCompatiblePlugin };

src/proxy/actions/Action.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getProxyUrl } from "../../config";
2-
import { Step } from "./Step";
1+
import { getProxyUrl } from '../../config';
2+
import { Step } from './Step';
33

44
/**
55
* Represents a commit.
@@ -62,15 +62,15 @@ class Action {
6262
this.type = type;
6363
this.method = method;
6464
this.timestamp = timestamp;
65-
this.project = repo.split("/")[0];
66-
this.repoName = repo.split("/")[1];
65+
this.project = repo.split('/')[0];
66+
this.repoName = repo.split('/')[1];
6767
this.url = `${getProxyUrl()}/${repo}`;
6868
this.repo = repo;
6969
}
7070

7171
/**
7272
* Add a step to the action.
73-
* @param {Step} step
73+
* @param {Step} step
7474
*/
7575
addStep(step: Step): void {
7676
this.steps.push(step);

src/proxy/actions/Step.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from "uuid";
1+
import { v4 as uuidv4 } from 'uuid';
22

33
/** Class representing a Push Step. */
44
class Step {
@@ -17,7 +17,7 @@ class Step {
1717
errorMessage: string | null = null,
1818
blocked: boolean = false,
1919
blockedMessage: string | null = null,
20-
content: any = null
20+
content: any = null,
2121
) {
2222
this.id = uuidv4();
2323
this.stepName = stepName;
@@ -35,12 +35,12 @@ class Step {
3535
}
3636

3737
setContent(content: any): void {
38-
this.log("setting content");
38+
this.log('setting content');
3939
this.content = content;
4040
}
4141

4242
setAsyncBlock(message: string): void {
43-
this.log("setting blocked");
43+
this.log('setting blocked');
4444
this.blocked = true;
4545
this.blockedMessage = message;
4646
}

src/proxy/actions/autoActions.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,4 @@ const attemptAutoRejection = async (action: Action) => {
3333
}
3434
};
3535

36-
export {
37-
attemptAutoApproval,
38-
attemptAutoRejection,
39-
};
36+
export { attemptAutoApproval, attemptAutoRejection };

0 commit comments

Comments
 (0)