Skip to content

Commit 9cd186a

Browse files
seer-by-sentry[bot]ntindleBentlybro
authored
fix(backend): Improve GitHub PR URL validation and API URL generation (#10317)
### Changes 🏗️ Fixes [AUTOGPT-SERVER-4EN](https://sentry.io/organizations/significant-gravitas/issues/6731949478/). The issue was that: Issue URL passed to PR file reader, regex failed, leading to issue API call, returning object iterated as keys, causing AttributeError. - Refactor `prepare_pr_api_url` to improve validation of GitHub PR URLs. - Update regex to specifically target github.com URLs. - Raise ValueError with a descriptive message for invalid URLs. - Correctly construct the API URL using the extracted repository path. This fix was generated by Seer in Sentry, triggered automatically. 👁️ Run ID: 265077 Not quite right? [Click here to continue debugging with Seer.](https://sentry.io/organizations/significant-gravitas/issues/6731949478/?seerDrawer=true) ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: <!-- Put your test plan here: --> - [x] Test plan: - [x] Provide an invalid GitHub PR URL and verify that a ValueError is raised with a descriptive message. - [x] Provide a valid GitHub PR URL and verify that the API URL is correctly constructed. --------- Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com> Co-authored-by: Nicholas Tindle <[email protected]> Co-authored-by: Bently <[email protected]>
1 parent dcf26bd commit 9cd186a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

autogpt_platform/backend/backend/blocks/github/pull_requests.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,12 @@ async def run(
553553

554554

555555
def prepare_pr_api_url(pr_url: str, path: str) -> str:
556-
# Pattern to capture the base repository URL and the pull request number
557-
pattern = r"^(?:https?://)?([^/]+/[^/]+/[^/]+)/pull/(\d+)"
556+
pattern = r"^(?:https?://)?github\.com/([^/]+/[^/]+)/pull/(\d+)"
558557
match = re.match(pattern, pr_url)
559558
if not match:
560-
return pr_url
559+
raise ValueError(
560+
f"Invalid GitHub PR URL: {pr_url}. URL must be a valid pull request URL, e.g., https://github.com/owner/repo/pull/123"
561+
)
561562

562-
base_url, pr_number = match.groups()
563-
return f"{base_url}/pulls/{pr_number}/{path}"
563+
repo_path, pr_number = match.groups()
564+
return f"{repo_path}/pulls/{pr_number}/{path}"

0 commit comments

Comments
 (0)