Skip to content

Commit 6e3c6f5

Browse files
author
Jakub Jirous
committed
[github] open ai
[github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai
1 parent e659a2a commit 6e3c6f5

File tree

4 files changed

+130
-10
lines changed

4 files changed

+130
-10
lines changed

.github/workflows/code_review.yml

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
1-
name: "Code Review Workflow"
1+
name: "Code Review with OpenAI"
22

33
on:
4+
push:
5+
branches:
6+
- main
7+
48
pull_request:
5-
types: [opened, synchronize, reopened]
69
branches:
7-
- develop
10+
- main
11+
12+
env:
13+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
814

915
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Set up Node.js environment
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: 14
24+
registry-url: https://npm.pkg.github.com
25+
26+
- name: Install dependencies
27+
run: |
28+
npm install openai
29+
30+
- name: Code review using ChatGPT
31+
uses: actions/github-script@v3
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
with:
35+
script: |
36+
const openai = require("openai");
37+
openai.prompt(`What is the capital of France?`).then((answer) => {
38+
console.log(answer);
39+
});
40+
1041
code-review:
42+
name: "Code Review"
1143
runs-on: ubuntu-latest
1244

1345
steps:
@@ -19,11 +51,42 @@ jobs:
1951
with:
2052
node-version: 16
2153

22-
- name: "Fetch pull request information"
23-
id: pr-info
54+
- name: "Install dependencies"
55+
run: npm install openai
56+
57+
- name: "Send code to OpenAI for review"
58+
id: code-review
2459
uses: actions/github-script@v3
60+
env:
61+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
2562
with:
26-
github-token: ${{ secrets.GH_TOKEN }}
2763
script: |
28-
const pr = context.payload.pull_request;
29-
console.log(` Pull request information: ${JSON.stringify(pr)}`);
64+
const openai = require("openai");
65+
openai.prompt(
66+
{
67+
model: "text-davinci-002",
68+
prompt: "Please review the code in this pull request and provide feedback",
69+
maxTokens: 100,
70+
temperature: 0.5,
71+
topP: 1
72+
},
73+
function(error, response) {
74+
if (error) {
75+
throw new Error(error);
76+
}
77+
const review = response.choices[0].text;
78+
const pull_request_number = context.payload.pull_request.number;
79+
const pull_request_body = context.payload.pull_request.body;
80+
const new_body = pull_request_body + "\n\n" + "Code Review: " + review;
81+
octokit.pulls.update({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
pull_number: pull_request_number,
85+
body: new_body
86+
}).then(() => {
87+
console.log("Code review successfully added to the pull request!");
88+
}).catch((error) => {
89+
throw new Error(error);
90+
});
91+
}
92+
);

.github/workflows/sonarcloud.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ on:
99
branches:
1010
- main
1111

12-
workflow_dispatch:
13-
1412
permissions:
1513
pull-requests: read # allows SonarCloud to decorate PRs with analysis results
1614

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"jest-watcher": "^29.3.1",
5959
"jest-worker": "^29.3.1",
6060
"load-tsconfig": "^0.2.3",
61+
"openai": "^3.1.0",
6162
"source-map": "^0.6.1",
6263
"source-map-support": "^0.5.13",
6364
"ts-node": "^10.9.1"

yarn.lock

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,18 @@ array.prototype.flat@^1.2.5:
954954
es-abstract "^1.20.4"
955955
es-shim-unscopables "^1.0.0"
956956

957+
asynckit@^0.4.0:
958+
version "0.4.0"
959+
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
960+
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
961+
962+
axios@^0.26.0:
963+
version "0.26.1"
964+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
965+
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
966+
dependencies:
967+
follow-redirects "^1.14.8"
968+
957969
babel-jest@^29.3.1:
958970
version "29.3.1"
959971
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-29.3.1.tgz#05c83e0d128cd48c453eea851482a38782249f44"
@@ -1173,6 +1185,13 @@ color-name@~1.1.4:
11731185
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
11741186
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
11751187

1188+
combined-stream@^1.0.8:
1189+
version "1.0.8"
1190+
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
1191+
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
1192+
dependencies:
1193+
delayed-stream "~1.0.0"
1194+
11761195
concat-map@0.0.1:
11771196
version "0.0.1"
11781197
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -1246,6 +1265,11 @@ define-properties@^1.1.3, define-properties@^1.1.4:
12461265
has-property-descriptors "^1.0.0"
12471266
object-keys "^1.1.1"
12481267

1268+
delayed-stream@~1.0.0:
1269+
version "1.0.0"
1270+
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
1271+
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
1272+
12491273
detect-newline@^3.0.0:
12501274
version "3.1.0"
12511275
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
@@ -1697,6 +1721,20 @@ flatted@^3.1.0:
16971721
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
16981722
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==
16991723

1724+
follow-redirects@^1.14.8:
1725+
version "1.15.2"
1726+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
1727+
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
1728+
1729+
form-data@^4.0.0:
1730+
version "4.0.0"
1731+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
1732+
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
1733+
dependencies:
1734+
asynckit "^0.4.0"
1735+
combined-stream "^1.0.8"
1736+
mime-types "^2.1.12"
1737+
17001738
fs.realpath@^1.0.0:
17011739
version "1.0.0"
17021740
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -2622,6 +2660,18 @@ micromatch@^4.0.4:
26222660
braces "^3.0.2"
26232661
picomatch "^2.3.1"
26242662

2663+
mime-db@1.52.0:
2664+
version "1.52.0"
2665+
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
2666+
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
2667+
2668+
mime-types@^2.1.12:
2669+
version "2.1.35"
2670+
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
2671+
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
2672+
dependencies:
2673+
mime-db "1.52.0"
2674+
26252675
mimic-fn@^2.1.0:
26262676
version "2.1.0"
26272677
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
@@ -2729,6 +2779,14 @@ onetime@^5.1.2:
27292779
dependencies:
27302780
mimic-fn "^2.1.0"
27312781

2782+
openai@^3.1.0:
2783+
version "3.1.0"
2784+
resolved "https://registry.yarnpkg.com/openai/-/openai-3.1.0.tgz#13bfb228cf777155b882c2deb3a03bc5094cb7b3"
2785+
integrity sha512-v5kKFH5o+8ld+t0arudj833Mgm3GcgBnbyN9946bj6u7bvel4Yg6YFz2A4HLIYDzmMjIo0s6vSG9x73kOwvdCg==
2786+
dependencies:
2787+
axios "^0.26.0"
2788+
form-data "^4.0.0"
2789+
27322790
optionator@^0.9.1:
27332791
version "0.9.1"
27342792
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499"

0 commit comments

Comments
 (0)