Skip to content

Commit

Permalink
Improve comments (#323)
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Jocher <[email protected]>
Co-authored-by: UltralyticsAssistant <[email protected]>
  • Loading branch information
glenn-jocher and UltralyticsAssistant authored Dec 22, 2024
1 parent 1511dee commit 15bad22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
# ├── test_summarize_pr.py
# └── ...

__version__ = "0.0.28"
__version__ = "0.0.29"
31 changes: 15 additions & 16 deletions actions/summarize_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


def generate_merge_message(pr_author, contributors, pr_summary=None):
"""Generates an AI thank you message for merged PRs using OpenAI."""
"""Generates a thank-you message for merged PR contributors."""
contributors_str = ", ".join(f"@{c}" for c in contributors if c != pr_author)
mention_str = f"@{pr_author}"
if contributors_str:
Expand All @@ -38,38 +38,38 @@ def generate_merge_message(pr_author, contributors, pr_summary=None):
f"Context from PR:\n{pr_summary}\n\n"
f"Start with the exciting message that this PR is now merged, and weave in an inspiring quote "
f"from a famous figure in science, philosophy or stoicism. "
f"Make the message relevant to the specific contributions in this PR. "
f"We want them to feel their hard work is acknowledged and will make a difference in the world.",
f"Keep the message concise yet relevant to the specific contributions in this PR. "
f"We want the contributors to feel their effort is appreciated and will make a difference in the world.",
},
]
return get_completion(messages)


def post_merge_message(pr_number, pr_author, contributors, summary):
"""Posts AI-generated thank you message on PR after merge."""
"""Posts thank you message on PR after merge."""
message = generate_merge_message(pr_author, contributors, summary)
comment_url = f"{GITHUB_API_URL}/repos/{GITHUB_REPOSITORY}/issues/{pr_number}/comments"
response = requests.post(comment_url, json={"body": message}, headers=GITHUB_HEADERS)
return response.status_code == 201


def generate_issue_comment(pr_url, pr_summary):
"""Generates a personalized issue comment using AI based on the PR context."""
"""Generates a personalized issue comment using based on the PR context."""
messages = [
{
"role": "system",
"content": "You are an Ultralytics AI assistant. Generate friendly GitHub issue comments. No @ mentions or direct addressing.",
},
{
"role": "user",
"content": f"Write a comment for a GitHub issue where a potential fix has been merged in PR: {pr_url}\n\n"
"content": f"Write a GitHub issue comment announcing a potential fix has been merged in linked PR {pr_url}\n\n"
f"Context from PR:\n{pr_summary}\n\n"
f"Include:\n"
f"1. An explanation of key changes from the PR that may resolve this issue\n"
f"2. Testing options:\n"
f"2. Options for testing if PR changes have resolved this issue:\n"
f" - pip install git+https://github.com/ultralytics/ultralytics.git@main # test latest changes\n"
f" - or await next official PyPI release\n"
f"3. Request feedback on whether these changes resolve the issue\n"
f"3. Request feedback on whether the PR changes resolve the issue\n"
f"4. Thank 🙏 for reporting the issue and welcome any further feedback if the issue persists\n\n",
},
]
Expand Down Expand Up @@ -141,12 +141,12 @@ def label_fixed_issues(pr_number, pr_summary):
}
url
body
author { login }
author { login, __typename }
reviews(first: 50) {
nodes { author { login } }
nodes { author { login, __typename } }
}
comments(first: 50) {
nodes { author { login } }
nodes { author { login, __typename } }
}
}
}
Expand All @@ -163,19 +163,18 @@ def label_fixed_issues(pr_number, pr_summary):

try:
data = response.json()["data"]["repository"]["pullRequest"]
issues = data["closingIssuesReferences"]["nodes"]
comments = data["reviews"]["nodes"] | data["comments"]["nodes"]
author = data["author"]["login"]

# Get unique contributors from reviews and comments
contributors = {review["author"]["login"] for review in data["reviews"]["nodes"]}
contributors.update(comment["author"]["login"] for comment in data["comments"]["nodes"])
contributors = {x["author"]["login"] for x in comments if x["author"]["__typename"] != "Bot"}
contributors.discard(author) # Remove author from contributors list

# Generate personalized comment
comment = generate_issue_comment(pr_url=data["url"], pr_summary=pr_summary)

# Update linked issues
for issue in issues:
for issue in data["closingIssuesReferences"]["nodes"]:
issue_number = issue["number"]
# Add fixed label
label_url = f"{GITHUB_API_URL}/repos/{GITHUB_REPOSITORY}/issues/{issue_number}/labels"
Expand Down Expand Up @@ -208,7 +207,7 @@ def remove_todos_on_merge(pr_number):


def main():
"""Summarize a pull request and update its description with an AI-generated summary."""
"""Summarize a pull request and update its description with a summary."""
pr_number = PR["number"]

print(f"Retrieving diff for PR {pr_number}")
Expand Down

0 comments on commit 15bad22

Please sign in to comment.