-
Notifications
You must be signed in to change notification settings - Fork 0
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
Test19 #19
Closed
Test19 #19
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
5aeed7f
feat: git ignore
agis09 dc446df
debug:
agis09 e617560
fix:
agis09 7b0b2cc
debug:
agis09 a1722d0
debug:
agis09 4480f6a
fix:
agis09 4a01924
fix:
agis09 d0ac707
fix:
agis09 ef6123a
fix:
agis09 0316762
fix:
agis09 9a82834
fix:
agis09 0104ac8
fix:
agis09 e10a08a
fix:
agis09 7c05a27
debug:
agis09 67a409c
debug:
agis09 96af70e
debug:
agis09 6789d78
fix:
agis09 16d26a7
fix:
agis09 a1d66c5
fix:
agis09 0be6709
fix:
agis09 341cb80
fix:
agis09 bb9f554
fix:
agis09 cd67b91
fix:
agis09 dd5ceca
debug:
agis09 b23350f
debug:
agis09 7562bdd
debug:
agis09 7b265a6
debug:
agis09 80fc587
fix:
agis09 2655f61
debug:
agis09 71552dc
fix:
agis09 74ea348
debug:
agis09 e535c4a
fix:
agis09 4c405b9
fix:
agis09 f20d967
fix:
agis09 6f4caa4
fix:
agis09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: test | ||
run-name: ${{ github.actor }} runs test | ||
on: | ||
pull_request: | ||
types: [opened] | ||
jobs: | ||
check-bats-version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.12.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install poetry | ||
poetry install | ||
- name: Run review | ||
env: | ||
GIT_API_TOKEN: ${{ secrets.GIT_API_TOKEN }} | ||
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} | ||
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} | ||
COMMIT_ID: ${{ github.event.pull_request.head.sha }} | ||
PR_REPO_NAME: ${{ github.event.pull_request.head.repo.full_name }} | ||
PR_BRANCH_NAME: ${{ github.event.pull_request.head.ref }} | ||
BASE_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} | ||
run: poetry run python create_pr_comments.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import requests | ||
import json | ||
import os | ||
import logging | ||
from dotenv import load_dotenv | ||
from run_gemini import get_review | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(encoding="utf-8", level=logging.DEBUG) | ||
|
||
load_dotenv(override=True) | ||
|
||
|
||
def create_pull_request_comment( | ||
repository, pull_number, github_api_token, body, commit_id, path, line, side | ||
): | ||
|
||
pr_url = f"https://api.github.com/repos/{repository}/pulls/{pull_number}/comments" | ||
headers = { | ||
"Accept": "application/json", | ||
"Authorization": f"Bearer {github_api_token}", | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
} | ||
data = { | ||
"body": body, | ||
"commit_id": commit_id, | ||
"path": path, | ||
"line": int(line), | ||
"side": side, | ||
} | ||
|
||
logger.debug(data) | ||
|
||
response = requests.post(pr_url, headers=headers, json=data) | ||
try: | ||
response.raise_for_status() | ||
except: | ||
logger.exception(response) | ||
|
||
return response.json() | ||
|
||
|
||
def parse_comments(text): | ||
comments = [] | ||
lines = text.splitlines() | ||
for line in lines: | ||
if line[0] == "{" and line[-1] == "}": | ||
try: | ||
comment = json.loads(line) | ||
if not all(key in comment for key in ["body", "path", "line", "side"]): | ||
raise ValueError("Invalid format: Required key does not exist.") | ||
comments.append(comment) | ||
except json.JSONDecodeError: | ||
raise ValueError(f"Invalid format: {line}") | ||
return comments | ||
|
||
|
||
if __name__ == "__main__": | ||
git_api_token = os.environ["GIT_API_TOKEN"] | ||
pr_number = os.environ["PULL_REQUEST_NUMBER"] | ||
commit_id = os.environ["COMMIT_ID"] | ||
pr_repository = os.environ["PR_REPO_NAME"] | ||
pr_branch_name = os.environ["PR_BRANCH_NAME"] | ||
base_branch_name = os.environ["BASE_BRANCH_NAME"] | ||
google_api_key = os.environ["GOOGLE_API_KEY"] | ||
|
||
raw_review = get_review( | ||
google_api_key, pr_branch_name, f"{base_branch_name}", logger | ||
) | ||
review_comments = parse_comments(raw_review) | ||
|
||
for comment in review_comments: | ||
|
||
try: | ||
comment_data = create_pull_request_comment( | ||
pr_repository, | ||
pr_number, | ||
git_api_token, | ||
comment["body"], | ||
commit_id, | ||
comment["path"], | ||
comment["line"], | ||
comment["side"], | ||
) | ||
logger.info(comment_data) | ||
except: | ||
logger.exception(comment) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using the
google-api-python-client
library to interact with the GitHub API instead of directly usingrequests
. This library provides a more convenient and robust way to handle authentication and API requests.