From d0378d69e07dedb0db0f72f8841f8da24a7bd234 Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 16:10:55 -0800 Subject: [PATCH 01/11] [github] code review using open api [github] code review using open api [github] code review using open api --- .github/workflows/code_review.yml | 28 ++++++++++++++++++++++++++++ .github/workflows/sonarcloud.yml | 6 ++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/code_review.yml diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml new file mode 100644 index 0000000..86a7bf9 --- /dev/null +++ b/.github/workflows/code_review.yml @@ -0,0 +1,28 @@ +name: "Code Review Workflow" + +on: + pull_request: + branches: + - develop + +jobs: + code-review: + runs-on: ubuntu-latest + + steps: + - name: "Fetch pull request information" + id: pr-info + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GH_TOKEN }} + script: | + const pr = context.payload.pull_request; + console.log(` Pull request information: ${JSON.stringify(pr)}`); + + - name: "Run OpenAI code review" + id: code-review + uses: openai/action-chat-gpt@v1 + with: + prompt: "Please provide a code review of the following Pull Request: ${{ steps.pr-info.outputs.pull_request }}" + model: text-davinci-002 + api_key: ${{ secrets.OPENAI_API_KEY }} diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 7f4a883..6979dbc 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -2,10 +2,12 @@ name: "SonarCloud" on: push: - branches: ["main"] + branches: + - main pull_request: - branches: ["main"] + branches: + - main workflow_dispatch: From 3af6cc2068c1b55baa7adfa30b263a4e69a9bc7c Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 16:48:49 -0800 Subject: [PATCH 02/11] [github] code review using open api --- .github/workflows/code_review.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index 86a7bf9..78f2bfe 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -2,8 +2,7 @@ name: "Code Review Workflow" on: pull_request: - branches: - - develop + types: [opened, synchronize, reopened] jobs: code-review: From e659a2a8010afc001c93c7d259209ca1facc1aab Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 16:51:17 -0800 Subject: [PATCH 03/11] [github] code review using open api - fetch [github] code review using open api - fetch [github] code review using open api - fetch [github] code review using open api - develop only [github] using node version 16 [github] using node version 16 --- .github/workflows/code_review.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index 78f2bfe..2c50676 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -3,12 +3,22 @@ name: "Code Review Workflow" on: pull_request: types: [opened, synchronize, reopened] + branches: + - develop jobs: code-review: runs-on: ubuntu-latest steps: + - name: "Checkout code" + uses: actions/checkout@v3 + + - name: "Run Node.js script" + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: "Fetch pull request information" id: pr-info uses: actions/github-script@v3 @@ -17,11 +27,3 @@ jobs: script: | const pr = context.payload.pull_request; console.log(` Pull request information: ${JSON.stringify(pr)}`); - - - name: "Run OpenAI code review" - id: code-review - uses: openai/action-chat-gpt@v1 - with: - prompt: "Please provide a code review of the following Pull Request: ${{ steps.pr-info.outputs.pull_request }}" - model: text-davinci-002 - api_key: ${{ secrets.OPENAI_API_KEY }} From 6e3c6f5569ba96f44be75597c23d5e3192e0be1f Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 17:19:11 -0800 Subject: [PATCH 04/11] [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 --- .github/workflows/code_review.yml | 79 +++++++++++++++++++++++++++---- .github/workflows/sonarcloud.yml | 2 - package.json | 1 + yarn.lock | 58 +++++++++++++++++++++++ 4 files changed, 130 insertions(+), 10 deletions(-) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index 2c50676..65e65d1 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -1,13 +1,45 @@ -name: "Code Review Workflow" +name: "Code Review with OpenAI" on: + push: + branches: + - main + pull_request: - types: [opened, synchronize, reopened] branches: - - develop + - main + +env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Set up Node.js environment + uses: actions/setup-node@v2 + with: + node-version: 14 + registry-url: https://npm.pkg.github.com + + - name: Install dependencies + run: | + npm install openai + + - name: Code review using ChatGPT + uses: actions/github-script@v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + script: | + const openai = require("openai"); + openai.prompt(`What is the capital of France?`).then((answer) => { + console.log(answer); + }); + code-review: + name: "Code Review" runs-on: ubuntu-latest steps: @@ -19,11 +51,42 @@ jobs: with: node-version: 16 - - name: "Fetch pull request information" - id: pr-info + - name: "Install dependencies" + run: npm install openai + + - name: "Send code to OpenAI for review" + id: code-review uses: actions/github-script@v3 + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} with: - github-token: ${{ secrets.GH_TOKEN }} script: | - const pr = context.payload.pull_request; - console.log(` Pull request information: ${JSON.stringify(pr)}`); + const openai = require("openai"); + openai.prompt( + { + model: "text-davinci-002", + prompt: "Please review the code in this pull request and provide feedback", + maxTokens: 100, + temperature: 0.5, + topP: 1 + }, + function(error, response) { + if (error) { + throw new Error(error); + } + const review = response.choices[0].text; + const pull_request_number = context.payload.pull_request.number; + const pull_request_body = context.payload.pull_request.body; + const new_body = pull_request_body + "\n\n" + "Code Review: " + review; + octokit.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pull_request_number, + body: new_body + }).then(() => { + console.log("Code review successfully added to the pull request!"); + }).catch((error) => { + throw new Error(error); + }); + } + ); diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 6979dbc..c258f55 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -9,8 +9,6 @@ on: branches: - main - workflow_dispatch: - permissions: pull-requests: read # allows SonarCloud to decorate PRs with analysis results diff --git a/package.json b/package.json index fe6f5fe..0fe07ae 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "jest-watcher": "^29.3.1", "jest-worker": "^29.3.1", "load-tsconfig": "^0.2.3", + "openai": "^3.1.0", "source-map": "^0.6.1", "source-map-support": "^0.5.13", "ts-node": "^10.9.1" diff --git a/yarn.lock b/yarn.lock index ddbef2c..9a25c1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -954,6 +954,18 @@ array.prototype.flat@^1.2.5: es-abstract "^1.20.4" es-shim-unscopables "^1.0.0" +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== + +axios@^0.26.0: + version "0.26.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9" + integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA== + dependencies: + follow-redirects "^1.14.8" + babel-jest@^29.3.1: version "29.3.1" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-29.3.1.tgz#05c83e0d128cd48c453eea851482a38782249f44" @@ -1173,6 +1185,13 @@ color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + concat-map@0.0.1: version "0.0.1" 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: has-property-descriptors "^1.0.0" object-keys "^1.1.1" +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== + detect-newline@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651" @@ -1697,6 +1721,20 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787" integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== +follow-redirects@^1.14.8: + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== + +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -2622,6 +2660,18 @@ micromatch@^4.0.4: braces "^3.0.2" picomatch "^2.3.1" +mime-db@1.52.0: + version "1.52.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" + integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== + +mime-types@^2.1.12: + version "2.1.35" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" + integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== + dependencies: + mime-db "1.52.0" + mimic-fn@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" @@ -2729,6 +2779,14 @@ onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" +openai@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/openai/-/openai-3.1.0.tgz#13bfb228cf777155b882c2deb3a03bc5094cb7b3" + integrity sha512-v5kKFH5o+8ld+t0arudj833Mgm3GcgBnbyN9946bj6u7bvel4Yg6YFz2A4HLIYDzmMjIo0s6vSG9x73kOwvdCg== + dependencies: + axios "^0.26.0" + form-data "^4.0.0" + optionator@^0.9.1: version "0.9.1" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499" From 29dfc27eb953666c2c49b9da02b08c7c44a70b61 Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 20:02:12 -0800 Subject: [PATCH 05/11] [github] open ai --- .github/workflows/code_review.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index 65e65d1..7136e62 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -24,8 +24,8 @@ jobs: registry-url: https://npm.pkg.github.com - name: Install dependencies - run: | - npm install openai + run: npm install -g yarn + - run: yarn add openai - name: Code review using ChatGPT uses: actions/github-script@v3 From baf55d08460973c125f4b3d23a3f947b0f2e09f2 Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 20:43:14 -0800 Subject: [PATCH 06/11] [github] open ai --- .github/workflows/code_review.yml | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index 7136e62..d46e7a4 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -13,31 +13,6 @@ env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} jobs: - test: - runs-on: ubuntu-latest - - steps: - - name: Set up Node.js environment - uses: actions/setup-node@v2 - with: - node-version: 14 - registry-url: https://npm.pkg.github.com - - - name: Install dependencies - run: npm install -g yarn - - run: yarn add openai - - - name: Code review using ChatGPT - uses: actions/github-script@v3 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - script: | - const openai = require("openai"); - openai.prompt(`What is the capital of France?`).then((answer) => { - console.log(answer); - }); - code-review: name: "Code Review" runs-on: ubuntu-latest @@ -52,7 +27,10 @@ jobs: node-version: 16 - name: "Install dependencies" - run: npm install openai + run: npm ci + + - name: "Install OpenAI package" + run: npm i openai - name: "Send code to OpenAI for review" id: code-review From 62bba6dcb7d7540bc6eb4265db92ab813ab56b12 Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 20:45:00 -0800 Subject: [PATCH 07/11] [github] open ai --- .github/workflows/code_review.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index d46e7a4..e05930b 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -27,10 +27,10 @@ jobs: node-version: 16 - name: "Install dependencies" - run: npm ci + run: npm i -g yarn - name: "Install OpenAI package" - run: npm i openai + run: yarn add openai - name: "Send code to OpenAI for review" id: code-review From 1bc011d814e7aadba843739329be829cc679281e Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 20:52:52 -0800 Subject: [PATCH 08/11] [github] open ai --- .github/workflows/code_review.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index e05930b..58e0ef5 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -32,6 +32,12 @@ jobs: - name: "Install OpenAI package" run: yarn add openai + - name: "Use OpenAI package" + run: | + echo "Running OpenAI code..." + const openai = require("openai"); + console.log(openai); + - name: "Send code to OpenAI for review" id: code-review uses: actions/github-script@v3 From 598e5a69785cfc6bbcf3e3a30107947f79978192 Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 20:56:02 -0800 Subject: [PATCH 09/11] [github] open ai --- .github/workflows/code_review.yml | 39 +------------------------------ 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index 58e0ef5..b22e752 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -36,41 +36,4 @@ jobs: run: | echo "Running OpenAI code..." const openai = require("openai"); - console.log(openai); - - - name: "Send code to OpenAI for review" - id: code-review - uses: actions/github-script@v3 - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - with: - script: | - const openai = require("openai"); - openai.prompt( - { - model: "text-davinci-002", - prompt: "Please review the code in this pull request and provide feedback", - maxTokens: 100, - temperature: 0.5, - topP: 1 - }, - function(error, response) { - if (error) { - throw new Error(error); - } - const review = response.choices[0].text; - const pull_request_number = context.payload.pull_request.number; - const pull_request_body = context.payload.pull_request.body; - const new_body = pull_request_body + "\n\n" + "Code Review: " + review; - octokit.pulls.update({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: pull_request_number, - body: new_body - }).then(() => { - console.log("Code review successfully added to the pull request!"); - }).catch((error) => { - throw new Error(error); - }); - } - ); + console.log(`OpenAI version: ${openai.version}`); From da806c58034e303712d0ef388348b082f8ae3136 Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 20:58:32 -0800 Subject: [PATCH 10/11] [github] open ai --- .github/workflows/code_review.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index b22e752..43a44c6 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -35,5 +35,3 @@ jobs: - name: "Use OpenAI package" run: | echo "Running OpenAI code..." - const openai = require("openai"); - console.log(`OpenAI version: ${openai.version}`); From 1405889d0a16c0cd8e90644d9ad00b19a0b46397 Mon Sep 17 00:00:00 2001 From: Jakub Jirous Date: Sun, 5 Feb 2023 20:59:30 -0800 Subject: [PATCH 11/11] [github] open ai --- .github/workflows/code_review.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code_review.yml b/.github/workflows/code_review.yml index 43a44c6..05d4884 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/code_review.yml @@ -34,4 +34,6 @@ jobs: - name: "Use OpenAI package" run: | - echo "Running OpenAI code..." + echo "Running OpenAI code..."; + const openai = require("openai"); + console.log(`OpenAI version: ${openai.version}`);