From 0ec40d315049c52594d58d0209fe3ad8d63f694f Mon Sep 17 00:00:00 2001 From: Spencer Krum Date: Tue, 13 May 2025 10:16:39 -0500 Subject: [PATCH] chore: reposync 24662 --- .github/pull_request_template.md | 55 +++++++++------------- .github/scripts/release_notes_check.py | 4 +- .github/workflows/ai_explain.py | 36 +++++++------- .github/workflows/ai_explain.yaml | 7 ++- .github/workflows/release_notes_check.yaml | 2 +- 5 files changed, 43 insertions(+), 61 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index f298bfe24..9b97ff132 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,14 +1,23 @@ # Pull Request Description -## What - +## What and why? + + -## Why - - -## How to Test +## How to test +## What needs special review? + + +## Dependencies, breaking changes, and deployment notes + + + + +## Release notes + + -## Pull Request Dependencies - - - -## External Release Notes - - -## Deployment Notes - - -## Breaking Changes - - -## Screenshots/Videos (Frontend Only) - - ## 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 - - -## Additional Notes - +- [ ] Documentation updated (if required) \ No newline at end of file diff --git a/.github/scripts/release_notes_check.py b/.github/scripts/release_notes_check.py index 62b91c0c3..1ec9e9d81 100644 --- a/.github/scripts/release_notes_check.py +++ b/.github/scripts/release_notes_check.py @@ -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'] diff --git a/.github/workflows/ai_explain.py b/.github/workflows/ai_explain.py index 2e6150c7a..3945d5182 100644 --- a/.github/workflows/ai_explain.py +++ b/.github/workflows/ai_explain.py @@ -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") @@ -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 = "" + # 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 = """ @@ -70,20 +71,10 @@ # 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=[ { @@ -91,7 +82,6 @@ "content": prompt, } ], - temperature=0, ) # Parse OpenAI response @@ -99,6 +89,7 @@ # 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"]) @@ -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)}") diff --git a/.github/workflows/ai_explain.yaml b/.github/workflows/ai_explain.yaml index 80209abec..587ff35ac 100644 --- a/.github/workflows/ai_explain.yaml +++ b/.github/workflows/ai_explain.yaml @@ -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 diff --git a/.github/workflows/release_notes_check.yaml b/.github/workflows/release_notes_check.yaml index 38bb167e6..792697140 100644 --- a/.github/workflows/release_notes_check.yaml +++ b/.github/workflows/release_notes_check.yaml @@ -6,7 +6,7 @@ on: permissions: contents: read - pull-requests: write + pull-requests: read jobs: ci_check: