Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bc97a6f

Browse filesBrowse files
committed
Do not create a PR if one exists
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parent a6e2f0c commit bc97a6f
Copy full SHA for bc97a6f

File tree

2 files changed

+20
-34
lines changed
Filter options

2 files changed

+20
-34
lines changed

‎buildbothammer/README.md

Copy file name to clipboardExpand all lines: buildbothammer/README.md
+1-32Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,6 @@ CPython project. It monitors Buildbot for failing builds, identifies the
55
commit that caused the failure, and creates a revert PR on GitHub. It also sends
66
notifications to Discord.
77

8-
## Prerequisites
9-
10-
- Python 3.11+
11-
- Git
12-
- A GitHub account with fork of the CPython repository
13-
- A Discord server with webhook set up (for notifications)
14-
15-
## Installation
16-
17-
1. Clone this repository:
18-
```
19-
git clone https://github.com/python/buildmasterconf.git
20-
cd buildmasterconf/buildbot-hammer
21-
```
22-
23-
2. Install the required Python packages:
24-
```
25-
pip install -e .
26-
```
27-
28-
3. Set up environment variables:
29-
```
30-
export GITHUB_TOKEN="your-github-personal-access-token"
31-
export DISCORD_WEBHOOK_URL="your-discord-webhook-url"
32-
```
33-
34-
4. Update the script with your GitHub username:
35-
Open the script and replace `FORK_OWNER` variable with your GitHub username.
36-
37-
5. (Optional) Update the `REPO_CLONE_DIR` path if you want to use a different location for the local CPython clone.
38-
398
## Usage
409

4110
Run the script with:
@@ -60,4 +29,4 @@ The script will:
6029
- `REPO_OWNER`: The owner of the main repository (default: "python")
6130
- `REPO_NAME`: The name of the repository (default: "cpython")
6231
- `FORK_OWNER`: Your GitHub username (default: "$REPO_OWNER")
63-
- `REPO_CLONE_DIR`: The directory for the local clone of the repository
32+
- `REPO_CLONE_PATH`: The directory for the local clone of the repository

‎buildbothammer/src/buildbothammer/__init__.py

Copy file name to clipboardExpand all lines: buildbothammer/src/buildbothammer/__init__.py
+19-2Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,31 @@ def ensure_repo_clone():
197197
run_command(["git", "reset", "--hard", "origin/main"], cwd=str(REPO_CLONE_DIR))
198198

199199

200+
def check_existing_pr(repo, branch_name):
201+
logger.info(f"Checking for existing PR for branch: {branch_name}")
202+
existing_prs = repo.get_pulls(state='open', head=f"{FORK_OWNER}:{branch_name}")
203+
return next(existing_prs, None)
204+
205+
200206
def create_revert_pr(commit_sha, builder, failing_build):
201207
logger.info(f"Creating revert PR for commit: {commit_sha}")
202208
g = Github(GITHUB_TOKEN)
203209

204210
try:
205211
main_repo = g.get_repo(f"{REPO_OWNER}/{REPO_NAME}")
206212

213+
branch_name = f"revert-{commit_sha[:7]}"
214+
215+
# Check for existing PR
216+
existing_pr = check_existing_pr(main_repo, branch_name)
217+
if existing_pr:
218+
logger.info(f"Existing PR found: {existing_pr.html_url}")
219+
return None, None
220+
221+
with FileLock(LOCK_FILE):
222+
ensure_repo_clone()
223+
224+
207225
with FileLock(LOCK_FILE):
208226
ensure_repo_clone()
209227

@@ -215,7 +233,6 @@ def create_revert_pr(commit_sha, builder, failing_build):
215233
cwd=str(REPO_CLONE_DIR),
216234
)
217235

218-
branch_name = f"revert-{commit_sha[:7]}"
219236
run_command(["git", "checkout", "-b", branch_name], cwd=str(REPO_CLONE_DIR))
220237
logger.info(f"Created and checked out new branch: {branch_name}")
221238

@@ -322,7 +339,7 @@ async def process_builder(session, builder, first_failing_build):
322339
pr_url, discord_message = create_revert_pr(
323340
commit_sha, builder, first_failing_build
324341
)
325-
if pr_url:
342+
if pr_url and discord_message:
326343
logger.info(f"Created revert PR for commit {commit_sha}: {pr_url}")
327344
await send_discord_notification(session, discord_message)
328345
else:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.