Skip to content

Commit c27c4d0

Browse files
authored
fix: Update agent PR creation logic to url encode parameters (#333)
I've seen issues where the "Create PR link" doesn't work because it ends up including a hash or other character that messes with the URL. Now we encode the url using python helpers *and* use markdown links to create a better presentation. Example result: zastrowm#16 Co-authored-by: Mackenzie Zastrow <[email protected]>
1 parent d17effa commit c27c4d0

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

.github/agent-sops/task-implementer.sop.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,9 @@ If all tests are passing, draft a conventional commit message, perform the git c
252252
- You MUST give an overview of the feature being implemented
253253
- You MUST include any notes on key implementation decisions, ambiguity, or other information as part of the pull request description
254254
- If the `create_pull_request` tool fails (excluding deferred responses):
255-
- You MUST create a PR creation link using GitHub's query parameters
256-
- You MUST post the link as a comment on the issue
257-
- You MUST use the format: `https://github.com/{owner}/{repo}/compare/{base}...{head}?quick_pull=1&title={url_encoded_title}&body={url_encoded_body}`
258-
- URL-encode the title and body parameters
259-
- Include "Resolves: #{issue_number}" in the body
255+
- The tool automatically handles fallback by posting a properly URL-encoded manual PR creation link as a comment on the specified fallback issue
256+
- You MUST verify the fallback comment was posted successfully by checking the tool's return message
257+
- You MUST NOT manually construct PR creation URLs since the tool handles URL encoding automatically
260258
- If PR creation succeeds or is deferred:
261259
- You MUST review your notes for any updates to provide on the pull request
262260
- You MAY use the `update_pull_request` tool to update the pull request body or title

.github/scripts/python/github_tools.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
from functools import wraps
6666
import json
6767
from typing import Any, TypedDict
68+
from urllib.parse import urlencode, quote
6869

6970
import requests
7071
from rich import box
@@ -363,9 +364,15 @@ def create_pull_request(title: str, head: str, base: str, body: str = "", repo:
363364
agent_message = "Failed to create pull request, commenting on issue instead."
364365
console.print(Panel(escape(agent_message), title="[bold yellow]Fallback", border_style="yellow"))
365366
repo_name = repo or os.environ.get("GITHUB_REPOSITORY", "")
366-
pr_link = f"https://github.com/{repo_name}/compare/{base}...{head}?quick_pull=1&title={title.replace(' ', '%20')}&body={body.replace(' ', '%20').replace('\n', '%0A')}"
367-
fallback_comment = f"Failed to create pull request, you can create it by clicking this link:\n\n{pr_link}"
368-
return add_issue_comment(fallback_issue_id, fallback_comment, repo)
367+
query_params = urlencode({
368+
'quick_pull': '1',
369+
'title': title,
370+
'body': body
371+
}, quote_via=quote)
372+
pr_link = f"https://github.com/{repo_name}/compare/{base}...{head}?{query_params}"
373+
fallback_comment = f"Unable to create pull request via API. You can create it manually by clicking [here]({pr_link})."
374+
add_issue_comment(fallback_issue_id, fallback_comment, repo)
375+
return f"Unable to create pull request via API - posted a manual creation link as a comment on issue #{fallback_issue_id}"
369376
else:
370377
error_msg = f"Error: {e!s}"
371378
console.print(Panel(escape(error_msg), title="[bold red]Error", border_style="red"))

0 commit comments

Comments
 (0)