Skip to content

Commit dd725ec

Browse files
authored
Merge pull request #25 from brandonxiang/feat-hello
chore: update readme
2 parents fedf8f9 + b329b5b commit dd725ec

File tree

7 files changed

+100
-20
lines changed

7 files changed

+100
-20
lines changed

.github/workflows/cr.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
name: Automated Ollama Code Review
1+
name: Code Review
2+
3+
permissions:
4+
contents: read
5+
pull-requests: write
26

37
on:
48
pull_request:
5-
branches:
6-
- main
9+
types: [opened, reopened, synchronize]
710

811
jobs:
9-
ollama_review:
12+
test:
13+
# if: ${{ contains(github.event.*.labels.*.name, 'gpt review') }} # Optional; to run only when a label is attached
1014
runs-on: ubuntu-latest
11-
name: Ollama Code Review Job
1215
steps:
13-
- name: Checkout Repository
14-
uses: actions/checkout@v2
15-
16-
- name: Ollama Code Review
17-
uses: ./.github/actions/ollama-code-review
18-
with:
19-
llm-model: 'codegemma'
16+
- uses: anc95/ChatGPT-CodeReview@main
2017
env:
21-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
20+
# Optional
21+
LANGUAGE: Chinese
22+
OPENAI_API_ENDPOINT: https://api.openai.com/v1
23+
MODEL: gpt-3.5-turbo # https://platform.openai.com/docs/models
24+
PROMPT: # example: Please check if there are any confusions or irregularities in the following code diff:
25+
top_p: 1 # https://platform.openai.com/docs/api-reference/chat/create#chat/create-top_p
26+
temperature: 1 # https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature
27+
max_tokens: 10000
28+
MAX_PATCH_LENGTH: 10000 # if the patch/diff length is large than MAX_PATCH_LENGTH, will be ignored and won't review. By default, with no MAX_PATCH_LENGTH set, there is also no limit for the patch/diff length.

packages/core/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ message MyRequest {
7070

7171
const ts = parseProto(source, {
7272
// Options
73+
outputType,
74+
mode,
7375
});
7476
```
7577
@@ -101,4 +103,5 @@ message MyRequest {
101103
`;
102104
103105
const ts = parseProto(source);
106+
104107
```

packages/core/src/node/io.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'node:fs';
22
import path from 'node:path';
33
import { handleError } from '../utils/log.js';
44
import { parseProtoFiles } from '../core.js';
5+
import { defaultFilename } from '../constant.js';
56

67
const { mkdirSync, readdirSync, writeFileSync } = fs;
78

@@ -28,6 +29,10 @@ export function transformProtoFiles(options) {
2829
if (!res) return;
2930

3031
mkdirSync(outputDir, { recursive: true });
32+
33+
if(res.has(defaultFilename)) {
34+
res.delete(defaultFilename);
35+
}
3136

3237
res.forEach((value, key) => {
3338
const outputFile = path.join(outputDir, key);

packages/core/src/print/gen-enum.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import MagicString from 'magic-string';
22
import { indentPrefix, OUTPUT_TYPE } from '../constant.js';
3+
import protobuf from 'protobufjs';
4+
5+
const { Type } = protobuf;
36

47
/**
58
* generate typescript files from proto info
@@ -8,7 +11,7 @@ import { indentPrefix, OUTPUT_TYPE } from '../constant.js';
811
* @returns
912
*/
1013
export function genEnum(proto, options) {
11-
const { values, comments, name } = proto;
14+
const { values, comments, name, parent } = proto;
1215

1316
const items = Object.keys(values)
1417
.map((key) => ({
@@ -21,17 +24,24 @@ export function genEnum(proto, options) {
2124
const result = new MagicString('');
2225

2326
items.forEach((s) => {
24-
if(s.comment) {
27+
if (s.comment) {
2528
result.append(`//${s.comment}\n`);
2629
}
2730
result.append(`${s.name} = ${s.id},\n`);
2831
});
2932

3033
const prefix = options.outputType === OUTPUT_TYPE.definition ? '' : 'export ';
3134

35+
let interfaceName = name;
36+
37+
// deal with nested type conflict problem
38+
if (parent && parent instanceof Type && parent.name) {
39+
interfaceName = parent.name + interfaceName;
40+
}
41+
3242
result
3343
.indent(indentPrefix)
34-
.prepend(`${prefix}enum ${name} {\n`)
44+
.prepend(`${prefix}enum ${interfaceName} {\n`)
3545
.append('}\n\n');
3646

3747
return {
@@ -60,7 +70,7 @@ export function getJsdocEnum(proto, options) {
6070
const result = new MagicString('');
6171

6272
items.forEach((s) => {
63-
if(s.comment) {
73+
if (s.comment) {
6474
result.append(`//${s.comment}\n`);
6575
}
6676
result.append(`${s.name} = ${s.id},\n`);

packages/core/src/print/gen-service.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export function genService(proto, options) {
5252
const prefix = options.outputType === OUTPUT_TYPE.definition ? '' : 'export ';
5353

5454
if (item.comment) {
55-
result.append(`//${item.comment}\n`);
55+
item.comment.split('\n').forEach((line) => {
56+
result.append(`//${line} \n`);
57+
})
5658
}
5759

5860
result.append(

packages/core/tests/comment/index.spec.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { test } from 'uvu';
44
import * as assert from 'uvu/assert';
55

66

7-
const source = `
7+
const sample1 = `
88
99
message UpdateHostBankAccWalletInfoResp {
1010
// 0:成功  非0:错误码   
@@ -19,12 +19,43 @@ message UpdateHostBankAccWalletInfoResp {
1919
`;
2020

2121
test('Comment of Field type should be converted', () => {
22-
const ts = parseProto(source);
22+
const ts = parseProto(sample1);
2323

2424
assert.match(ts, '//50010 bank account already exist');
2525
assert.match(ts, '//50011: bank account number already exist');
2626
assert.match(ts, '//50012 bank account mismatch the one on');
2727
});
2828

29+
const sample2 = `
30+
syntax = "proto3";
31+
32+
service Greeter {
33+
//hello
34+
//hello1
35+
rpc SayHello (HelloRequest) returns (HelloReply) {}
36+
}
37+
38+
message HelloRequest {
39+
string name = 1;
40+
}
41+
42+
message Teacher {
43+
string name = 1;
44+
}
45+
46+
message HelloReply {
47+
string message = 1;
48+
int32 test = 2;
49+
Teacher teacher = 3;
50+
}
51+
`;
52+
53+
test('Comment of function type should be converted', () => {
54+
const ts = parseProto(sample2);
55+
56+
assert.match(ts, '//hello');
57+
assert.match(ts, '//hello1');
58+
});
59+
2960

3061
test.run();

packages/core/tests/print/nest.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,27 @@ test('nest type6 should be converted', () => {
140140
assert.match(ts, '@typedef {Object} Message1');
141141
});
142142

143+
144+
test('nest type7 should be converted', () => {
145+
const source = `
146+
syntax = "proto3";
147+
message UpdateUserRoleReq {
148+
enum Type {
149+
PLATFORM = 0;
150+
PROJECT = 1;
151+
MODULE = 2;
152+
PLUGIN = 3;
153+
}
154+
int32 user_id = 1;
155+
int32 role_id = 2;
156+
Type type = 3;
157+
}
158+
`;
159+
160+
const ts = parseProto(source);
161+
assert.match(ts, 'type?: UpdateUserRoleReqType;');
162+
assert.match(ts, 'enum UpdateUserRoleReqType');
163+
})
164+
143165
test.run();
144166

0 commit comments

Comments
 (0)