From 2f9c1825a3b52ddcc6e0538bdd935ce1d85ab365 Mon Sep 17 00:00:00 2001 From: seoyeonson Date: Mon, 21 Apr 2025 17:32:59 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20Gemini=20=EA=B8=B0=EB=B0=98=20?= =?UTF-8?q?=EC=9E=90=EB=8F=99=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gemini-code-review.yml | 104 +++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 .github/workflows/gemini-code-review.yml diff --git a/.github/workflows/gemini-code-review.yml b/.github/workflows/gemini-code-review.yml new file mode 100644 index 0000000..5e48faa --- /dev/null +++ b/.github/workflows/gemini-code-review.yml @@ -0,0 +1,104 @@ +name: Gemini Code Review + +on: + push: + branches: [ feature/gemini ] + paths: + - 'backend/**' + pull_request: + types: [opened, synchronize] + +jobs: + code-review: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Node + uses: actions/setup-node@v3 + + - name: Install GoogleGenerativeAI + run: | + npm install @google/generative-ai + + # PR 이벤트에서의 변경사항 처리 + - name: Get git diff for PR + if: github.event_name == 'pull_request' + run: | + git fetch origin "${{ github.event.pull_request.base.ref }}" + git fetch origin "${{ github.event.pull_request.head.ref }}" + git diff --unified=0 "origin/${{ github.event.pull_request.base.ref }}" > "diff.txt" + echo "EVENT_TYPE=pull_request" >> $GITHUB_ENV + + # Push 이벤트에서의 변경사항 처리 + - name: Get git diff for Push + if: github.event_name == 'push' + run: | + git diff --unified=0 HEAD^ HEAD > "diff.txt" + echo "EVENT_TYPE=push" >> $GITHUB_ENV + + # Gemini를 사용한 코드 분석 + - name: Run Gemini-1.5-flash + id: gemini_review + uses: actions/github-script@v7 + with: + script: | + const fs = require("fs"); + const diff_output = fs.readFileSync("diff.txt",'utf8'); + + const { GoogleGenerativeAI } = require("@google/generative-ai"); + const genAI = new GoogleGenerativeAI("${{ secrets.GEMINI_API_KEY }}"); + const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash"}); + + // PR과 Push에 따라 다른 프롬프트 사용 + let prompt; + if (process.env.EVENT_TYPE === 'pull_request') { + prompt = `Explain in korean. You are a senior software engineer and need to perform a code review based on the results of a given git diff. Review the changed code from different perspectives and let us know if there are any changes that need to be made. If you see any code that needs to be fixed in the result of the git diff, you need to calculate the exact line number by referring to the "@@ -0,0 +0,0 @@" part. The output format is \[{"path":"{ filepath }", "line": { line }, "text": { review comment }, "side": "RIGHT"}\] format must be respected.\n${diff_output}`; + } else { + prompt = `Explain in korean. You are a senior software engineer and need to perform a code review based on the results of a given git diff. Provide a detailed review of the code changes, focusing on code quality, readability, performance, and security. Format your response in Markdown with clear headings for each file reviewed.\n${diff_output}`; + } + + const result = await model.generateContent(prompt); + const response = await result.response; + const text = response.text(); + + fs.writeFileSync('review_result.txt', text); + console.log('Review results saved!'); + + # PR 이벤트: 라인별 리뷰 코멘트 추가 + - name: Format and add PR review comments + if: env.EVENT_TYPE == 'pull_request' + id: store + run: | + COMMENT=$(sed '/^```/d' review_result.txt | jq -c .) + echo "comment=$COMMENT" >> $GITHUB_OUTPUT + + - name: Add Pull Request Review Comment + if: env.EVENT_TYPE == 'pull_request' + uses: nbaztec/add-pr-review-comment@v1.0.7 + with: + comments: ${{ steps.store.outputs.comment }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + repo-token-user-login: 'github-actions[bot]' + allow-repeats: false + + # Push 이벤트: 액션 로그에 리뷰 결과 출력 및 아티팩트 업로드 + - name: Display review results in workflow log + if: env.EVENT_TYPE == 'push' + run: | + echo "===== Gemini Code Review Results =====" + cat review_result.txt + echo "======================================" + + - name: Upload review results as artifact + if: env.EVENT_TYPE == 'push' + uses: actions/upload-artifact@v4 + with: + name: gemini-code-review + path: review_result.txt \ No newline at end of file From ec28c926395f21d33193197a09b8cc355f7c77ba Mon Sep 17 00:00:00 2001 From: seoyeonson Date: Mon, 21 Apr 2025 17:42:59 +0900 Subject: [PATCH 2/4] fix: brance name fix --- .github/workflows/gemini-code-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gemini-code-review.yml b/.github/workflows/gemini-code-review.yml index 5e48faa..61a3e89 100644 --- a/.github/workflows/gemini-code-review.yml +++ b/.github/workflows/gemini-code-review.yml @@ -2,7 +2,7 @@ name: Gemini Code Review on: push: - branches: [ feature/gemini ] + branches: [ feat/gemini ] paths: - 'backend/**' pull_request: From f9fbe1465115d994dca1e05a9ee818ee191c6edf Mon Sep 17 00:00:00 2001 From: seoyeonson Date: Mon, 21 Apr 2025 17:46:58 +0900 Subject: [PATCH 3/4] =?UTF-8?q?rename=20:=20terraform=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EC=A0=95=EB=A6=AC"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {ec2 => terraform/ec2}/main.tf | 0 {ec2 => terraform/ec2}/variables.tf | 0 {s3 => terraform/s3}/main.tf | 0 {s3 => terraform/s3}/variables.tf | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {ec2 => terraform/ec2}/main.tf (100%) rename {ec2 => terraform/ec2}/variables.tf (100%) rename {s3 => terraform/s3}/main.tf (100%) rename {s3 => terraform/s3}/variables.tf (100%) diff --git a/ec2/main.tf b/terraform/ec2/main.tf similarity index 100% rename from ec2/main.tf rename to terraform/ec2/main.tf diff --git a/ec2/variables.tf b/terraform/ec2/variables.tf similarity index 100% rename from ec2/variables.tf rename to terraform/ec2/variables.tf diff --git a/s3/main.tf b/terraform/s3/main.tf similarity index 100% rename from s3/main.tf rename to terraform/s3/main.tf diff --git a/s3/variables.tf b/terraform/s3/variables.tf similarity index 100% rename from s3/variables.tf rename to terraform/s3/variables.tf From 5261719fb9d82c9e4f7a8c0c64b701f22dfac11e Mon Sep 17 00:00:00 2001 From: seoyeonson Date: Mon, 21 Apr 2025 18:09:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?test:=20gemini=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cmf/commitField/domain/admin/notice/entity/Notice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/cmf/commitField/domain/admin/notice/entity/Notice.java b/src/main/java/cmf/commitField/domain/admin/notice/entity/Notice.java index ece12b7..bb84ee2 100644 --- a/src/main/java/cmf/commitField/domain/admin/notice/entity/Notice.java +++ b/src/main/java/cmf/commitField/domain/admin/notice/entity/Notice.java @@ -13,6 +13,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PROTECTED) public class Notice extends BaseEntity { + // 관리자 공지사항 private String title; private String content; }