Skip to content

chore: update readme #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions .github/workflows/cr.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
name: Automated Ollama Code Review
name: Code Review

permissions:
contents: read
pull-requests: write

on:
pull_request:
branches:
- main
types: [opened, reopened, synchronize]

jobs:
ollama_review:
test:
# if: ${{ contains(github.event.*.labels.*.name, 'gpt review') }} # Optional; to run only when a label is attached
runs-on: ubuntu-latest
name: Ollama Code Review Job
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Ollama Code Review
uses: ./.github/actions/ollama-code-review
with:
llm-model: 'codegemma'
- uses: anc95/ChatGPT-CodeReview@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
# Optional
LANGUAGE: Chinese
OPENAI_API_ENDPOINT: https://api.openai.com/v1
MODEL: gpt-3.5-turbo # https://platform.openai.com/docs/models
PROMPT: # example: Please check if there are any confusions or irregularities in the following code diff:
top_p: 1 # https://platform.openai.com/docs/api-reference/chat/create#chat/create-top_p
temperature: 1 # https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature
max_tokens: 10000
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.
3 changes: 3 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ message MyRequest {

const ts = parseProto(source, {
// Options
outputType,
mode,
});
```

Expand Down Expand Up @@ -101,4 +103,5 @@ message MyRequest {
`;

const ts = parseProto(source);

```
5 changes: 5 additions & 0 deletions packages/core/src/node/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs';
import path from 'node:path';
import { handleError } from '../utils/log.js';
import { parseProtoFiles } from '../core.js';
import { defaultFilename } from '../constant.js';

const { mkdirSync, readdirSync, writeFileSync } = fs;

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

mkdirSync(outputDir, { recursive: true });

if(res.has(defaultFilename)) {
res.delete(defaultFilename);
}

res.forEach((value, key) => {
const outputFile = path.join(outputDir, key);
Expand Down
18 changes: 14 additions & 4 deletions packages/core/src/print/gen-enum.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import MagicString from 'magic-string';
import { indentPrefix, OUTPUT_TYPE } from '../constant.js';
import protobuf from 'protobufjs';

const { Type } = protobuf;

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

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

items.forEach((s) => {
if(s.comment) {
if (s.comment) {
result.append(`//${s.comment}\n`);
}
result.append(`${s.name} = ${s.id},\n`);
});

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

let interfaceName = name;

// deal with nested type conflict problem
if (parent && parent instanceof Type && parent.name) {
interfaceName = parent.name + interfaceName;
}

result
.indent(indentPrefix)
.prepend(`${prefix}enum ${name} {\n`)
.prepend(`${prefix}enum ${interfaceName} {\n`)
.append('}\n\n');

return {
Expand Down Expand Up @@ -60,7 +70,7 @@ export function getJsdocEnum(proto, options) {
const result = new MagicString('');

items.forEach((s) => {
if(s.comment) {
if (s.comment) {
result.append(`//${s.comment}\n`);
}
result.append(`${s.name} = ${s.id},\n`);
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/print/gen-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export function genService(proto, options) {
const prefix = options.outputType === OUTPUT_TYPE.definition ? '' : 'export ';

if (item.comment) {
result.append(`//${item.comment}\n`);
item.comment.split('\n').forEach((line) => {
result.append(`//${line} \n`);
})
}

result.append(
Expand Down
35 changes: 33 additions & 2 deletions packages/core/tests/comment/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { test } from 'uvu';
import * as assert from 'uvu/assert';


const source = `
const sample1 = `

message UpdateHostBankAccWalletInfoResp {
// 0:成功  非0:错误码   
Expand All @@ -19,12 +19,43 @@ message UpdateHostBankAccWalletInfoResp {
`;

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

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

const sample2 = `
syntax = "proto3";

service Greeter {
//hello
//hello1
rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
string name = 1;
}

message Teacher {
string name = 1;
}

message HelloReply {
string message = 1;
int32 test = 2;
Teacher teacher = 3;
}
`;

test('Comment of function type should be converted', () => {
const ts = parseProto(sample2);

assert.match(ts, '//hello');
assert.match(ts, '//hello1');
});


test.run();
22 changes: 22 additions & 0 deletions packages/core/tests/print/nest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,27 @@ test('nest type6 should be converted', () => {
assert.match(ts, '@typedef {Object} Message1');
});


test('nest type7 should be converted', () => {
const source = `
syntax = "proto3";
message UpdateUserRoleReq {
enum Type {
PLATFORM = 0;
PROJECT = 1;
MODULE = 2;
PLUGIN = 3;
}
int32 user_id = 1;
int32 role_id = 2;
Type type = 3;
}
`;

const ts = parseProto(source);
assert.match(ts, 'type?: UpdateUserRoleReqType;');
assert.match(ts, 'enum UpdateUserRoleReqType');
})

test.run();

Loading