Skip to content

Commit f14d937

Browse files
committed
fix: cli type import error
1 parent ef15d58 commit f14d937

File tree

2 files changed

+85
-67
lines changed

2 files changed

+85
-67
lines changed

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@
2020
"require": "./dist/src/db/index.js",
2121
"types": "./dist/src/db/index.d.ts"
2222
},
23+
"./plugin": {
24+
"import": "./dist/src/plugin.js",
25+
"require": "./dist/src/plugin.js",
26+
"types": "./dist/src/plugin.d.ts"
27+
},
2328
"./proxy": {
2429
"import": "./dist/src/proxy/index.js",
2530
"require": "./dist/src/proxy/index.js",
2631
"types": "./dist/src/proxy/index.d.ts"
2732
},
28-
"./types": {
29-
"import": "./dist/src/types/models.js",
30-
"require": "./dist/src/types/models.js",
31-
"types": "./dist/src/types/models.d.ts"
33+
"./proxy/actions": {
34+
"import": "./dist/src/proxy/actions/index.js",
35+
"require": "./dist/src/proxy/actions/index.js",
36+
"types": "./dist/src/proxy/actions/index.d.ts"
3237
},
33-
"./plugin": {
34-
"import": "./dist/src/plugin.js",
35-
"require": "./dist/src/plugin.js",
36-
"types": "./dist/src/plugin.d.ts"
38+
"./ui": {
39+
"import": "./dist/src/ui/index.js",
40+
"require": "./dist/src/ui/index.js",
41+
"types": "./dist/src/ui/index.d.ts"
3742
}
3843
},
3944
"scripts": {

packages/git-proxy-cli/index.ts

Lines changed: 72 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { hideBin } from 'yargs/helpers';
55
import fs from 'fs';
66
import util from 'util';
77

8-
import { CommitData, PushData } from '@finos/git-proxy/types';
98
import { PushQuery } from '@finos/git-proxy/db';
9+
import { Action } from '@finos/git-proxy/proxy/actions';
1010

1111
const GIT_PROXY_COOKIE_FILE = 'git-proxy-cookie';
1212
// GitProxy UI HOST and PORT (configurable via environment variable)
@@ -88,73 +88,86 @@ async function getGitPushes(filters: Partial<PushQuery>) {
8888

8989
try {
9090
const cookies = JSON.parse(fs.readFileSync(GIT_PROXY_COOKIE_FILE, 'utf8'));
91-
92-
const response = await axios.get(`${baseUrl}/api/v1/push/`, {
91+
const { data } = await axios.get<Action[]>(`${baseUrl}/api/v1/push/`, {
9392
headers: { Cookie: cookies },
9493
params: filters,
9594
});
9695

97-
const records: PushData[] = [];
98-
response.data.forEach((push: PushData) => {
99-
const record: PushData = {
100-
id: push.id,
101-
repo: push.repo,
102-
branch: push.branch,
103-
commitFrom: push.commitFrom,
104-
commitTo: push.commitTo,
105-
commitData: push.commitData,
106-
diff: push.diff,
107-
error: push.error,
108-
canceled: push.canceled,
109-
rejected: push.rejected,
110-
blocked: push.blocked,
111-
authorised: push.authorised,
112-
attestation: push.attestation,
113-
autoApproved: push.autoApproved,
114-
timestamp: push.timestamp,
115-
url: push.url,
116-
allowPush: push.allowPush,
96+
const records = data.map((push: Action) => {
97+
const {
98+
id,
99+
repo,
100+
branch,
101+
commitFrom,
102+
commitTo,
103+
commitData,
104+
error,
105+
canceled,
106+
rejected,
107+
blocked,
108+
authorised,
109+
attestation,
110+
autoApproved,
111+
timestamp,
112+
url,
113+
allowPush,
114+
lastStep,
115+
} = push;
116+
117+
return {
118+
id,
119+
repo,
120+
branch,
121+
commitFrom,
122+
commitTo,
123+
commitData: commitData?.map(
124+
({
125+
message,
126+
committer,
127+
committerEmail,
128+
author,
129+
authorEmail,
130+
commitTimestamp,
131+
tree,
132+
parent,
133+
}) => ({
134+
message,
135+
committer,
136+
committerEmail,
137+
author,
138+
authorEmail,
139+
commitTimestamp,
140+
tree,
141+
parent,
142+
}),
143+
),
144+
error,
145+
canceled,
146+
rejected,
147+
blocked,
148+
authorised,
149+
attestation,
150+
autoApproved,
151+
timestamp,
152+
url,
153+
allowPush,
154+
lastStep: lastStep && {
155+
id: lastStep.id,
156+
content: lastStep.content,
157+
logs: lastStep.logs,
158+
stepName: lastStep.stepName,
159+
error: lastStep.error,
160+
errorMessage: lastStep.errorMessage,
161+
blocked: lastStep.blocked,
162+
blockedMessage: lastStep.blockedMessage,
163+
},
117164
};
118-
119-
if (push.lastStep) {
120-
record.lastStep = {
121-
id: push.lastStep?.id,
122-
content: push.lastStep?.content,
123-
logs: push.lastStep?.logs,
124-
stepName: push.lastStep?.stepName,
125-
error: push.lastStep?.error,
126-
errorMessage: push.lastStep?.errorMessage,
127-
blocked: push.lastStep?.blocked,
128-
blockedMessage: push.lastStep?.blockedMessage,
129-
};
130-
}
131-
132-
if (push.commitData) {
133-
const commitData: CommitData[] = [];
134-
push.commitData.forEach((pushCommitDataRecord: CommitData) => {
135-
commitData.push({
136-
message: pushCommitDataRecord.message,
137-
committer: pushCommitDataRecord.committer,
138-
committerEmail: pushCommitDataRecord.committerEmail,
139-
author: pushCommitDataRecord.author,
140-
authorEmail: pushCommitDataRecord.authorEmail,
141-
commitTimestamp: pushCommitDataRecord.commitTimestamp,
142-
tree: pushCommitDataRecord.tree,
143-
parent: pushCommitDataRecord.parent,
144-
});
145-
});
146-
record.commitData = commitData;
147-
}
148-
149-
records.push(record);
150165
});
151166

152-
console.log(`${util.inspect(records, false, null, false)}`);
167+
console.log(util.inspect(records, false, null, false));
153168
} catch (error: any) {
154-
// default error
155-
const errorMessage = `Error: List: '${error.message}'`;
169+
console.error(`Error: List: '${error.message}'`);
156170
process.exitCode = 2;
157-
console.error(errorMessage);
158171
}
159172
}
160173

0 commit comments

Comments
 (0)