Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 21 additions & 34 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# Pull Request Description

## What
<!-- Describe what the change is doing, including behavior before and after the change -->
## What and why?
<!-- Briefly describe what changed and why — include behavior before and after if helpful -->
<!-- Frontend: Add screenshots or videos showing before/after -->

## Why
<!-- Explain why the change is being made and needed -->

## How to Test
## How to test
<!-- Describe how the change has been tested, and how a reviewer can test the change locally -->

## What needs special review?
<!-- Optional: Call out specific areas needing detailed review -->

## Dependencies, breaking changes, and deployment notes
<!-- A list of links to pull requests that are depend on or are dependencies of this PR -->
<!-- Any special deployment considerations? -->
<!-- List any breaking changes -->

## Release notes
<!--- REPLACE THIS COMMENT WITH YOUR DESCRIPTION --->

<!--
PR instructions for release notes:

Expand All @@ -25,36 +34,14 @@ PR instructions for release notes:
2. In the next section, describe the changes so that an external user can understand them. Keep it simple and link to the docs with [Learn more ...](<relative-link>), if available.
-->

## Pull Request Dependencies

<!-- A list of links to pull requests that are depend on or are dependencies of this PR -->

## External Release Notes
<!--- REPLACE THIS COMMENT WITH YOUR DESCRIPTION --->

## Deployment Notes
<!-- Any special deployment considerations? -->

## Breaking Changes
<!-- List any breaking changes -->

## Screenshots/Videos (Frontend Only)
<!-- Add screenshots or videos showing before/after -->

## Checklist
- [ ] PR body describes what, why, and how to test
- [ ] Release notes written
- [ ] Deployment notes written
- [ ] Breaking changes identified
- [ ] What and why
- [ ] Screenshots or videos (Frontend)
- [ ] How to test
- [ ] What needs special review
- [ ] Dependencies, breaking changes, and deployment notes
- [ ] Labels applied
- [ ] PR linked to Shortcut
- [ ] Screenshots/videos added (Frontend)
- [ ] Unit tests added (Backend)
- [ ] Tested locally
- [ ] Documentation updated (if required)

## Areas Needing Special Review
<!-- Optional: Call out specific areas needing detailed review -->

## Additional Notes
<!-- Any other information that would be helpful to reviewers -->
- [ ] Documentation updated (if required)
4 changes: 2 additions & 2 deletions .github/scripts/release_notes_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def ci_check(pr_number, access_token):
labels = [label.name for label in pr.labels]
description = pr.body

# Check for the presence of 'internal' label
if 'internal' in labels:
# Check for the presence of 'internal' or 'dependencies' label
if 'internal' in labels or 'dependencies' in labels:
return True

required_labels = ['highlight', 'enhancement', 'bug', 'deprecation', 'documentation']
Expand Down
36 changes: 16 additions & 20 deletions .github/workflows/ai_explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from openai import OpenAI
from github import Github
from tiktoken import encoding_for_model

# Initialize GitHub and OpenAI clients
github_token = os.getenv("GITHUB_TOKEN")
Expand All @@ -28,13 +27,15 @@

diff = "\n\n".join(diffs)

# Add a unique marker at the start of the comment to find comments by the bot
COMMENT_MARKER = "<!-- AI-EXPLAIN-COMMENT -->"

# Fetch existing AI explanation comment
existing_explanation_comment = None
comments = sorted(pr.get_issue_comments(), key=lambda x: x.created_at, reverse=True)
existing_explanation_comments = []
comments = pr.get_issue_comments()
for comment in comments:
if comment.user.login == "github-actions[bot]":
existing_explanation_comment = comment
break
if comment.user.login == "github-actions[bot]" and COMMENT_MARKER in comment.body:
existing_explanation_comments.append(comment)

# OpenAI prompt template
prompt_template = """
Expand Down Expand Up @@ -70,35 +71,25 @@
# Prepare OpenAI prompt
prompt = prompt_template.format(diff=diff)

# check number of tokens
encoding = encoding_for_model("gpt-4o-mini")
tokens = encoding.encode(prompt)
print(f"Number of tokens: {len(tokens)}")
# 128k is max tokens for gpt-4o-mini
num_output_tokens = 1000
if len(tokens) > 128000 - num_output_tokens:
tokens = tokens[: 128000 - num_output_tokens]
prompt = encoding.decode(tokens)

# Call OpenAI API
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
model="o3-mini",
response_format={"type": "json_object"},
messages=[
{
"role": "user",
"content": prompt,
}
],
temperature=0,
)

# Parse OpenAI response
ai_response = json.loads(response.choices[0].message.content.strip())

# Create a new comment and delete the existing explanation comment
new_comment = pr.create_issue_comment(
f"{COMMENT_MARKER}\n"
f"{ai_response['summary']}\n\n"
f"## Test Suggestions\n"
f"- " + "\n- ".join(ai_response["test_suggestions"])
Expand All @@ -117,5 +108,10 @@
)
)
)
if existing_explanation_comment:
existing_explanation_comment.delete()

# Delete all previous AI explain comments
for comment in existing_explanation_comments:
try:
comment.delete()
except Exception as e:
print(f"Failed to delete comment: {str(e)}")
7 changes: 3 additions & 4 deletions .github/workflows/ai_explain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install openai
pip install tiktoken
pip install PyGithub

- name: Explain PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_PR_SUMMARY_KEY }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF: ${{ github.ref }}
run: python .github/workflows/ai_explain.py
2 changes: 1 addition & 1 deletion .github/workflows/release_notes_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

permissions:
contents: read
pull-requests: write
pull-requests: read

jobs:
ci_check:
Expand Down