Skip to content

Commit 78c8e35

Browse files
committed
update build config
1 parent ed0d0c5 commit 78c8e35

File tree

10 files changed

+185
-10
lines changed

10 files changed

+185
-10
lines changed

config/.crgpt.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
1+
output: 'console'
12
openai:
3+
endpoint: "https://api.openai.com/v1/chat/completions"
4+
apiKey: "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"
25
bitbucket:
3-
code:
6+
apiBaseUrl: "https://api.bitbucket.org/2.0/repositories"
7+
owner: "busker-media"
8+
projectKey: "BUS"
9+
apiKey: "ATATT3xFfGF0D5CT_V-f5syiMzYP4Wqpe1fjcYohmNnuUme3Kf2CKpB555uRCqBbnJYT2ntpnNpu5_eK5anqdUimEGL4_VoDL1RG7JmtHQO4SCzTaPuQQ-YsAMFu3ki_e_PJ2VVd8yIxjeOPqIOdhcWZE2BQrmdyObrwT5hTofnuIVW_YeWh1t0=030F1CE0"
10+
accessToken: "ATCTT3xFfGN0oxLuIA7sR3WQ5EJoR4IzhZdBS0fJU_Ngp4uek3r9UoDc9KjJ38RPFKHlbHLjPRFwCIPYjtOcXtLKl4EV3CapwQQ50zO8l3FkKa9sYVJA1GUQrxQrMXFiViYRI0gfk0O2HvXvHctWfAZRcE3QwNqtrB686wFitgRotrmeAi7goME=325FBD69"
11+
repoSlug: "busker-server"
12+
# username: "minhlvqs"
13+
username: "ccode-review"
14+
password: "ATBBnxahHvckTy76rNF4JxjBSueNE5057365"
15+
codeReview:
16+
prompt: |
17+
Your task is to act as a code reviewer and review a pull request by summarizing the changes made, identifying potential issues related to logic and runtime, and creating a bullet list of action items needed before the change can be approved. The output should focus on items mentioned in the given code review checklist.
18+
Instructions:
19+
- Review the output of git diff for the pull request
20+
- Summarize the overview of the changes made
21+
- Identify potential issues related to logic and runtime
22+
- Output as a markdown document, with the following sections:
23+
{output}
24+
- If there are no issues, output "None"
25+
- If there are no action items, output "None"
26+
- Create a bullet list of action items needed before the change can be approved
27+
- The response sentences are no longer than 16 words each
28+
- Keep the response sentences as short as possible
29+
- Focus on items mentioned in the given code review checklist:
30+
{checklist}
31+
output: |
32+
#### Overview of changes:
33+
- Summarize the overview of the changes made
34+
#### issues:
35+
- Identify potential issues related to logic and runtime
36+
- Identify issues mentioned in the code review checklist
37+
#### Action items:
38+
- Action items needed before the change can be approved
39+
checklist: |
40+
Code Structure
41+
- Is the codebase organized according to NestJS' recommended project structure?
42+
- Are there any unnecessary files, folders, or code modules?
43+
- Does the code follow the Single Responsibility Principle (SRP) and Don't Repeat Yourself (DRY) principle?
44+
Error Handling
45+
- Are all error scenarios covered in the code?
46+
- Are the error messages clear and helpful?
47+
- Is the code handling errors gracefully?
48+
Security
49+
- Are sensitive data and credentials stored securely?
50+
- Are all external libraries and packages up-to-date?
51+
- Is the code protected against common security vulnerabilities such as SQL injection and cross-site scripting (XSS)?
52+

package.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22
"name": "crgpt",
33
"version": "1.0.0",
44
"description": "CLI tool that leverages ChatGPT API to perform code reviews and providing suggestions for improving code quality.",
5-
"keywords": ["code-review", "code-quality", "chatgpt", "chatbot", "code-review-bot", "code-quality-bot"],
5+
"keywords": [
6+
"code-review",
7+
"code-quality",
8+
"chatgpt",
9+
"chatbot",
10+
"code-review-bot",
11+
"code-quality-bot"
12+
],
613
"main": "index.js",
714
"scripts": {
815
"test": "echo \"Error: no test specified\" && exit 1",
9-
"crgpt": "crgpt",
16+
"crgpt": "node ./dist/cli/crgpt.js",
17+
"build:clean": "tsc --build --clean",
1018
"build": "tsc"
11-
},
19+
},
1220
"bin": {
13-
"crgpt": "dist/cli.js"
21+
"crgpt": "dist/cli/crgpt.js"
1422
},
1523
"repository": {
1624
"type": "git",
@@ -28,8 +36,9 @@
2836
"typescript": "^5.0.2"
2937
},
3038
"dependencies": {
39+
"@types/node-fetch": "2",
3140
"commander": "^10.0.0",
3241
"js-yaml": "^4.1.0",
33-
"node-fetch": "^3.3.1"
42+
"node-fetch": "2"
3443
}
3544
}

src/cli/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { Config } from '../lib/types';
55
export async function readConfig(configFile: string): Promise<Config> {
66
try {
77
const fileContents = await fs.readFile(configFile, 'utf8');
8-
return yaml.load(fileContents) as Config;
8+
const config = yaml.load(fileContents) as Config;
9+
10+
if (!config) {
11+
throw new Error('Config file is empty');
12+
}
13+
14+
return config;
915
} catch (error) {
1016
throw new Error(`Error reading config file`);
1117
}

src/cli/cli.ts renamed to src/cli/crgpt.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ program
1515
.choices(['init', 'review', 'diff', 'desc'])
1616
.default('review', 'Code review')
1717
)
18+
.option('-o, --output <output>', 'output method')
1819
.option('-s, --source <source>', 'Source branch name')
1920
.option('-t, --target <target>', 'Target branch name')
2021
.option('-p, --prId [prId]', 'Pull request ID')

src/cli/init.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CrGPTCLIOptions } from './types';
55

66
export async function initCRGPT(configPath: string, options: CrGPTCLIOptions): Promise<void> {
77
const defaultConfig: Config = {
8+
output: 'console',
89
openai: {
910
endpoint: 'https://api.openai.com/v1/engines/davinci-codex/completions',
1011
apiKey: options.aiToken || '',

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib';

src/lib/crgpt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ async function postDiffToEndpoint(
6969
const apiKey = config.openai.apiKey;
7070
const promptTml = config.review.prompt;
7171
const checklist = config.review.checklist;
72-
const prompt = promptTml.replace('{checklist}', checklist);
72+
const summary = config.review.summary
73+
const prompt = promptTml.replace('{checklist}', checklist).replace('{output}', summary);
7374

7475
const response = await fetch(endpointUrl, {
7576
method: 'POST',

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type Config = {
2+
output: 'console';
23
bitbucket?: {
34
repoSlug: string;
45
accessToken: string;

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212

1313
/* Language and Environment */
14-
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
14+
"target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
"lib": ["es6"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
1717
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
@@ -55,7 +55,7 @@
5555
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
5656
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
5757
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58-
"outDir": "build", /* Specify an output folder for all emitted files. */
58+
"outDir": "dist", /* Specify an output folder for all emitted files. */
5959
// "removeComments": true, /* Disable emitting comments. */
6060
// "noEmit": true, /* Disable emitting files from a compilation. */
6161
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */

yarn.lock

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@types/js-yaml@^4.0.5":
6+
version "4.0.5"
7+
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.5.tgz#738dd390a6ecc5442f35e7f03fa1431353f7e138"
8+
integrity sha512-FhpRzf927MNQdRZP0J5DLIdTXhjLYzeUTmLAu69mnVksLH9CJY3IuSeEgbKUki7GQZm0WqDkGzyxju2EZGD2wA==
9+
10+
"@types/node-fetch@2":
11+
version "2.6.3"
12+
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.3.tgz#175d977f5e24d93ad0f57602693c435c57ad7e80"
13+
integrity sha512-ETTL1mOEdq/sxUtgtOhKjyB2Irra4cjxksvcMUR5Zr4n+PxVhsCD9WS46oPbHL3et9Zde7CNRr+WUNlcHvsX+w==
14+
dependencies:
15+
"@types/node" "*"
16+
form-data "^3.0.0"
17+
18+
"@types/node@*", "@types/node@^18.15.11":
19+
version "18.15.11"
20+
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.11.tgz#b3b790f09cb1696cffcec605de025b088fa4225f"
21+
integrity sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==
22+
23+
argparse@^2.0.1:
24+
version "2.0.1"
25+
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
26+
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
27+
28+
asynckit@^0.4.0:
29+
version "0.4.0"
30+
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
31+
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
32+
33+
combined-stream@^1.0.8:
34+
version "1.0.8"
35+
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
36+
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
37+
dependencies:
38+
delayed-stream "~1.0.0"
39+
40+
commander@^10.0.0:
41+
version "10.0.0"
42+
resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.0.tgz#71797971162cd3cf65f0b9d24eb28f8d303acdf1"
43+
integrity sha512-zS5PnTI22FIRM6ylNW8G4Ap0IEOyk62fhLSD0+uHRT9McRCLGpkVNvao4bjimpK/GShynyQkFFxHhwMcETmduA==
44+
45+
delayed-stream@~1.0.0:
46+
version "1.0.0"
47+
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
48+
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
49+
50+
form-data@^3.0.0:
51+
version "3.0.1"
52+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
53+
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
54+
dependencies:
55+
asynckit "^0.4.0"
56+
combined-stream "^1.0.8"
57+
mime-types "^2.1.12"
58+
59+
js-yaml@^4.1.0:
60+
version "4.1.0"
61+
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
62+
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
63+
dependencies:
64+
argparse "^2.0.1"
65+
66+
67+
version "1.52.0"
68+
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
69+
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
70+
71+
mime-types@^2.1.12:
72+
version "2.1.35"
73+
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
74+
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
75+
dependencies:
76+
mime-db "1.52.0"
77+
78+
node-fetch@2:
79+
version "2.6.9"
80+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.9.tgz#7c7f744b5cc6eb5fd404e0c7a9fec630a55657e6"
81+
integrity sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==
82+
dependencies:
83+
whatwg-url "^5.0.0"
84+
85+
tr46@~0.0.3:
86+
version "0.0.3"
87+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
88+
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
89+
90+
typescript@^5.0.2:
91+
version "5.0.3"
92+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.3.tgz#fe976f0c826a88d0a382007681cbb2da44afdedf"
93+
integrity sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==
94+
95+
webidl-conversions@^3.0.0:
96+
version "3.0.1"
97+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
98+
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==
99+
100+
whatwg-url@^5.0.0:
101+
version "5.0.0"
102+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
103+
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
104+
dependencies:
105+
tr46 "~0.0.3"
106+
webidl-conversions "^3.0.0"

0 commit comments

Comments
 (0)