-
Notifications
You must be signed in to change notification settings - Fork 0
feat: update_issue + update_pull_request (close/reopen) #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -233,3 +233,55 @@ async def get_pull_request_checks( | |||||||||||||
| "skipped": skipped, | ||||||||||||||
| "passed": passed, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| async def update_pull_request( | ||||||||||||||
| owner: str | None, | ||||||||||||||
| repo: str, | ||||||||||||||
| pull_number: int, | ||||||||||||||
| state: str | None = None, | ||||||||||||||
| title: str | None = None, | ||||||||||||||
| body: str | None = None, | ||||||||||||||
| ) -> dict[str, Any]: | ||||||||||||||
| """Update a pull request — including closing or reopening it. | ||||||||||||||
|
|
||||||||||||||
| Note: this does NOT merge. Set state="closed" to close a PR without merging. | ||||||||||||||
|
|
||||||||||||||
| Args: | ||||||||||||||
| owner: Repository owner (defaults to GITHUB_DEFAULT_ORG if unset) | ||||||||||||||
| repo: Repository name | ||||||||||||||
| pull_number: Pull request number | ||||||||||||||
| state: "open" or "closed" (set "closed" to close the PR) | ||||||||||||||
| title: New title (optional) | ||||||||||||||
| body: New body (optional) | ||||||||||||||
|
|
||||||||||||||
| Returns: | ||||||||||||||
| Updated PR details (number, state, html_url, title) | ||||||||||||||
| """ | ||||||||||||||
| owner = resolve_owner(owner) | ||||||||||||||
| repo = validate_name(repo, "repo") | ||||||||||||||
| pull_number = validate_positive_int(pull_number, "pull_number") | ||||||||||||||
|
|
||||||||||||||
| json_data: dict[str, Any] = {} | ||||||||||||||
| if state is not None: | ||||||||||||||
| if state not in ("open", "closed"): | ||||||||||||||
| raise ValidationError("state must be 'open' or 'closed'") | ||||||||||||||
| json_data["state"] = state | ||||||||||||||
| if title is not None: | ||||||||||||||
| json_data["title"] = title | ||||||||||||||
|
Comment on lines
+270
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When updating a pull request, we should validate that the
Suggested change
|
||||||||||||||
| if body is not None: | ||||||||||||||
| json_data["body"] = body | ||||||||||||||
| if not json_data: | ||||||||||||||
| raise ValidationError("no fields to update") | ||||||||||||||
|
|
||||||||||||||
| client = get_client() | ||||||||||||||
| result = await client.patch( | ||||||||||||||
| f"/repos/{owner}/{repo}/pulls/{pull_number}", | ||||||||||||||
| json_data=json_data, | ||||||||||||||
| ) | ||||||||||||||
| return { | ||||||||||||||
| "number": result.get("number"), | ||||||||||||||
| "state": result.get("state"), | ||||||||||||||
| "html_url": result.get("html_url"), | ||||||||||||||
| "title": result.get("title"), | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When updating an issue, we should validate that the
titleis not empty or just whitespace if it is provided. This prevents sending invalid requests to the GitHub API, which would result in a 422 Unprocessable Entity error. Additionally, we should strip leading and trailing whitespace from the title for consistency withcreate_issue.