Skip to content

Instantly share code, notes, and snippets.

@kfstorm
Forked from bveeramani/comment.py
Last active March 13, 2022 09:08
Show Gist options
  • Save kfstorm/03f3b1c01dac91251fdd6f211ca993da to your computer and use it in GitHub Desktop.
Save kfstorm/03f3b1c01dac91251fdd6f211ca993da to your computer and use it in GitHub Desktop.
Script to comment on all open Ray pull requests.
import time
import os
from github import Github
MESSAGE = """
## :bangbang: ACTION REQUIRED :bangbang:
We've updated our formatting configuration for C++ code. (see #22725)
This PR includes C++ code change. To prevent issues with merging your code, here's what you'll need to do:
1. Merge the latest changes from upstream/master branch into your branch.
```bash
git pull upstream master
git merge upstream/master
```
2. Resolve merge conflicts (if necessary).
After running these steps, you'll have the updated C++ formatting configuration.
3. Format changed files.
```bash
scripts/format.sh
```
4. Commit your changes.
```bash
git add --all
git commit -m "Format C++ code"
```
"""
ACCESS_TOKEN = ...
github_client = Github(ACCESS_TOKEN)
ray_repo = github_client.get_repo("ray-project/ray")
for pull_request in ray_repo.get_pulls(state="open"):
contains_cpp_change = False
for file in pull_request.get_files():
extension = os.path.splitext(file.filename)[1]
if extension in [".cc", ".h", ".cpp", ".c", ".hpp"]:
contains_cpp_change = True
break
print(f"Pull request {pull_request.html_url} includes C++ code changes: {'yes' if contains_cpp_change else 'no'}")
if contains_cpp_change:
print(f"Sending comment to {pull_request.html_url}")
pull_request.create_issue_comment(body=MESSAGE)
time.sleep(1) # To avoid rate limits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment