mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-11-12 19:07:28 -10:00
## Summary This PR adds a new `pull_request` output to `GithubReadPullRequestBlock` that carries the full, raw pull request object returned by the GitHub API — including head/base refs (with fork repo and branch name for cross-repo PRs), mergeability, and draft state — without touching any of the block's existing outputs. ### Why / What / How **Why:** The block's existing outputs (`title`, `body`, `author`, `changes`) don't expose fork/branch info, mergeability, or draft state. [OPEN-2780](https://github.com/Significant-Gravitas/AutoGPT/issues/11115) specifically asked for the PR's fork URL and branch name; rather than whitelist just those two fields, this exposes the whole object so any future need (draft state, review counts, labels, etc.) is covered without another block change. **What:** Adds a `pull_request: dict` output field with a description documenting its contents, and yields the raw PR JSON alongside the existing outputs. Nothing else in the block's input/output schema changes. **How:** `GithubReadPullRequestBlock.read_pr` fetches from the `/issues/{n}` endpoint (title/body/author only — it omits head/base/mergeability). The new `read_pr_full_object` static method fetches `/pulls/{n}` directly, which is the endpoint that actually carries the full object, and returns the response body unmodified. This follows the precedent set by `GithubGetUserInfoBlock.user` in [#13634](https://github.com/Significant-Gravitas/AutoGPT/pull/13634): yield the raw API object with a descriptive `SchemaField`, rather than hand-picking fields. ### Changes 🏗️ - `GithubReadPullRequestBlock`: new `pull_request` output (raw PR object from `GET /pulls/{n}`); new `read_pr_full_object` static method; existing `title`/`body`/`author`/`changes` outputs and their behavior are unchanged. - Regenerated block docs (`docs/integrations/`) to reflect the new output. Resolves [#11115](https://github.com/Significant-Gravitas/AutoGPT/issues/11115) ### 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: - [x] Extended `backend/blocks/github/test_github_blocks.py` with unit tests for `read_pr_full_object` (hits the `/pulls/{n}` endpoint, not `/issues/{n}`; returns the raw response body) — ran, pass. - [x] Ran the full `backend/blocks/github/test_github_blocks.py` suite (127 tests) — pass. - [x] Ran `test_available_blocks[GithubReadPullRequestBlock]` (the generic block-schema/test_output/test_mock harness) — pass. - [x] Ran `generate_block_docs.py --check` before and after regenerating — confirms it was out of sync, confirms a second run is idempotent, confirms `--check` now exits 0. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
285 lines
12 KiB
Markdown
285 lines
12 KiB
Markdown
# GitHub Pull Requests
|
|
<!-- MANUAL: file_description -->
|
|
Blocks for managing GitHub pull requests including creating, reading, listing PRs, and assigning or unassigning reviewers.
|
|
<!-- END MANUAL -->
|
|
|
|
## Github Assign PR Reviewer
|
|
|
|
### What it is
|
|
This block assigns a reviewer to a specified GitHub pull request.
|
|
|
|
### How it works
|
|
<!-- MANUAL: how_it_works -->
|
|
This block requests a code review from a specific user on a GitHub pull request. It uses the GitHub API to add the specified username to the list of requested reviewers, triggering a notification to that user.
|
|
|
|
The reviewer must have access to the repository. Organization members can typically be assigned as reviewers on any repository they have at least read access to.
|
|
<!-- END MANUAL -->
|
|
|
|
### Inputs
|
|
|
|
| Input | Description | Type | Required |
|
|
|-------|-------------|------|----------|
|
|
| pr_url | URL of the GitHub pull request | str | Yes |
|
|
| reviewer | Username of the reviewer to assign | str | Yes |
|
|
|
|
### Outputs
|
|
|
|
| Output | Description | Type |
|
|
|--------|-------------|------|
|
|
| error | Error message if the reviewer assignment failed | str |
|
|
| status | Status of the reviewer assignment operation | str |
|
|
|
|
### Possible use case
|
|
<!-- MANUAL: use_case -->
|
|
**Automated Code Review Assignment**: Automatically assign reviewers based on the files changed or the PR author.
|
|
|
|
**Round-Robin Reviews**: Distribute code review load evenly across team members.
|
|
|
|
**Expertise-Based Routing**: Assign reviewers who are experts in the specific area of code being modified.
|
|
<!-- END MANUAL -->
|
|
|
|
---
|
|
|
|
## Github List PR Reviewers
|
|
|
|
### What it is
|
|
This block lists the requested reviewers for a specified GitHub pull request, optionally including users who have already submitted a review.
|
|
|
|
### How it works
|
|
<!-- MANUAL: how_it_works -->
|
|
This block retrieves the list of requested reviewers for a GitHub pull request. It queries the GitHub API to fetch all users who have been requested to review the PR, returning their usernames and profile URLs.
|
|
|
|
This includes both pending review requests and users who have already submitted reviews.
|
|
<!-- END MANUAL -->
|
|
|
|
### Inputs
|
|
|
|
| Input | Description | Type | Required |
|
|
|-------|-------------|------|----------|
|
|
| pr_url | URL of the GitHub pull request | str | Yes |
|
|
| include_past_reviewers | Also include users who have already submitted a review, in addition to users whose review request is pending | bool | No |
|
|
|
|
### Outputs
|
|
|
|
| Output | Description | Type |
|
|
|--------|-------------|------|
|
|
| error | Error message if listing reviewers failed | str |
|
|
| reviewer | Reviewers with their username, profile URL, and review status. | Reviewer |
|
|
| reviewers | List of reviewers with their username, profile URL, and review status | List[ReviewerItem] |
|
|
|
|
### Possible use case
|
|
<!-- MANUAL: use_case -->
|
|
**Review Status Monitoring**: Check which reviewers have been assigned to a PR and send reminders to those who haven't responded.
|
|
|
|
**Workflow Validation**: Verify that required reviewers have been assigned before a PR can be merged.
|
|
|
|
**Team Dashboard**: Display reviewer assignments across multiple PRs for team visibility.
|
|
<!-- END MANUAL -->
|
|
|
|
---
|
|
|
|
## Github List Pull Requests
|
|
|
|
### What it is
|
|
This block lists all pull requests for a specified GitHub repository.
|
|
|
|
### How it works
|
|
<!-- MANUAL: how_it_works -->
|
|
This block fetches all open pull requests from a GitHub repository. It queries the GitHub API and returns a list of PRs with their titles and URLs, outputting both individual PRs and a complete list.
|
|
|
|
The block returns open pull requests by default, allowing you to monitor pending code changes in a repository.
|
|
<!-- END MANUAL -->
|
|
|
|
### Inputs
|
|
|
|
| Input | Description | Type | Required |
|
|
|-------|-------------|------|----------|
|
|
| repo_url | URL of the GitHub repository | str | Yes |
|
|
| state | Only include pull requests in this state | "open" \| "closed" \| "all" | No |
|
|
| base | Only include pull requests targeting this base branch | str | No |
|
|
| limit | Maximum number of pull requests to fetch | int | No |
|
|
| head | Only include pull requests from this head branch. Format: 'user:branch' or 'org:branch'. | str | No |
|
|
| sort | What to sort the pull requests by | "created" \| "updated" \| "popularity" \| "long-running" | No |
|
|
| direction | Sort direction | "asc" \| "desc" | No |
|
|
|
|
### Outputs
|
|
|
|
| Output | Description | Type |
|
|
|--------|-------------|------|
|
|
| error | Error message if listing pull requests failed | str |
|
|
| pull_request | PRs with their title and URL | Pull Request |
|
|
| pull_requests | List of pull requests with their title and URL | List[PRItem] |
|
|
|
|
### Possible use case
|
|
<!-- MANUAL: use_case -->
|
|
**PR Dashboard**: Create a dashboard showing all open pull requests across your repositories.
|
|
|
|
**Merge Queue Monitoring**: Track pending PRs to prioritize code reviews and identify bottlenecks.
|
|
|
|
**Stale PR Detection**: List PRs to identify those that have been open too long and need attention.
|
|
<!-- END MANUAL -->
|
|
|
|
---
|
|
|
|
## Github Make Pull Request
|
|
|
|
### What it is
|
|
This block creates a new pull request on a specified GitHub repository.
|
|
|
|
### How it works
|
|
<!-- MANUAL: how_it_works -->
|
|
This block creates a new pull request on a GitHub repository. It uses the GitHub API to submit a PR from your source branch (head) to the target branch (base), with the specified title and description.
|
|
|
|
For cross-repository PRs, format the head branch as "username:branch". The branches must exist and have divergent commits for the PR to be created successfully.
|
|
<!-- END MANUAL -->
|
|
|
|
### Inputs
|
|
|
|
| Input | Description | Type | Required |
|
|
|-------|-------------|------|----------|
|
|
| repo_url | URL of the GitHub repository | str | Yes |
|
|
| title | Title of the pull request | str | Yes |
|
|
| body | Body of the pull request | str | Yes |
|
|
| head | The name of the branch where your changes are implemented. For cross-repository pull requests in the same network, namespace head with a user like this: username:branch. | str | Yes |
|
|
| base | The name of the branch you want the changes pulled into. | str | Yes |
|
|
|
|
### Outputs
|
|
|
|
| Output | Description | Type |
|
|
|--------|-------------|------|
|
|
| error | Error message if the pull request creation failed | str |
|
|
| number | Number of the created pull request | int |
|
|
| url | URL of the created pull request | str |
|
|
|
|
### Possible use case
|
|
<!-- MANUAL: use_case -->
|
|
**Automated Releases**: Create PRs automatically when a release branch is ready to merge to main.
|
|
|
|
**Dependency Updates**: Programmatically create PRs for dependency updates after testing passes.
|
|
|
|
**Feature Flags**: Automatically create PRs to enable feature flags in configuration files.
|
|
<!-- END MANUAL -->
|
|
|
|
---
|
|
|
|
## Github Merge Pull Request
|
|
|
|
### What it is
|
|
This block merges a pull request using merge, squash, or rebase.
|
|
|
|
### How it works
|
|
<!-- MANUAL: how_it_works -->
|
|
This block merges a pull request using the GitHub Merge API. It supports three merge methods: regular merge commit, squash merge (combines all commits into one), and rebase merge (replays commits on top of the base branch).
|
|
|
|
You can optionally provide a custom commit title and message for merge and squash methods. The block returns the merge commit SHA and confirmation of success.
|
|
<!-- END MANUAL -->
|
|
|
|
### Inputs
|
|
|
|
| Input | Description | Type | Required |
|
|
|-------|-------------|------|----------|
|
|
| pr_url | URL of the GitHub pull request | str | Yes |
|
|
| merge_method | Merge method to use: merge, squash, or rebase | "merge" \| "squash" \| "rebase" | No |
|
|
| commit_title | Title for the merge commit (optional, used for merge and squash) | str | No |
|
|
| commit_message | Message for the merge commit (optional, used for merge and squash) | str | No |
|
|
|
|
### Outputs
|
|
|
|
| Output | Description | Type |
|
|
|--------|-------------|------|
|
|
| error | Error message if the merge failed | str |
|
|
| sha | SHA of the merge commit | str |
|
|
| merged | Whether the PR was merged | bool |
|
|
| message | Merge status message | str |
|
|
|
|
### Possible use case
|
|
<!-- MANUAL: use_case -->
|
|
**CI/CD Pipeline**: Automatically merge PRs after all checks pass and required approvals are received.
|
|
|
|
**Release Automation**: Merge release branches into main using squash for clean commit history.
|
|
|
|
**Dependency Updates**: Auto-merge bot-created PRs for minor dependency updates after tests pass.
|
|
<!-- END MANUAL -->
|
|
|
|
---
|
|
|
|
## Github Read Pull Request
|
|
|
|
### What it is
|
|
This block reads the body, title, user, changes, and full raw object of a specified GitHub pull request.
|
|
|
|
### How it works
|
|
<!-- MANUAL: how_it_works -->
|
|
This block fetches the pull request object from the `pulls/{number}` GitHub API endpoint and emits it unmodified as `pull_request`, while also pulling out `title`, `body`, `author`, `head_branch`, and `target_branch` as discrete outputs for convenience — if any of those fields are missing from the response, they fall back to placeholder strings (`"No title found"`, etc., or an empty string for the branch names) rather than failing the block. Because this uses the pulls endpoint rather than the issues endpoint, a fine-grained personal access token needs `Pull requests: read`; the default OAuth `repo` scope already covers this.
|
|
|
|
When `include_pr_changes` is enabled, the block makes a second call to fetch the diff of every changed file and joins them into one `changes` string, prefixed with `--- <old path>` / `+++ <new path>` headers similar to a unified diff — useful for feeding a PR's full changeset to code review automation.
|
|
<!-- END MANUAL -->
|
|
|
|
### Inputs
|
|
|
|
| Input | Description | Type | Required |
|
|
|-------|-------------|------|----------|
|
|
| pr_url | URL of the GitHub pull request | str | Yes |
|
|
| include_pr_changes | Whether to include the changes made in the pull request | bool | No |
|
|
|
|
### Outputs
|
|
|
|
| Output | Description | Type |
|
|
|--------|-------------|------|
|
|
| error | Error message if reading the pull request failed | str |
|
|
| title | Title of the pull request | str |
|
|
| body | Body of the pull request | str |
|
|
| author | User who created the pull request | str |
|
|
| changes | Changes made in the pull request | str |
|
|
| pull_request | The full pull request object from the API, including head/base refs (with fork repo and branch name for cross-repo PRs), mergeability (mergeable, mergeable_state, rebaseable), draft state, review/comment counts, labels, milestone, and diff/commit stats. | Dict[str, Any] |
|
|
| head_branch | Name of the branch the PR is created from (the head branch). For cross-repo PRs, this branch lives in the fork — see pull_request.head.repo for the fork's URL. | str |
|
|
| target_branch | Name of the branch the PR targets (the base branch) | str |
|
|
|
|
### Possible use case
|
|
<!-- MANUAL: use_case -->
|
|
**Automated Code Review**: Read PR content and changes to perform automated code analysis or send to AI for review.
|
|
|
|
**Changelog Generation**: Extract PR titles and descriptions to automatically compile release notes.
|
|
|
|
**PR Summarization**: Read PR details to generate summaries for stakeholder updates.
|
|
<!-- END MANUAL -->
|
|
|
|
---
|
|
|
|
## Github Unassign PR Reviewer
|
|
|
|
### What it is
|
|
This block unassigns a reviewer from a specified GitHub pull request.
|
|
|
|
### How it works
|
|
<!-- MANUAL: how_it_works -->
|
|
This block removes a reviewer from a GitHub pull request's review request list. It uses the GitHub API to remove the specified user from pending reviewers, which stops further review notifications to that user.
|
|
|
|
This is useful for reassigning reviews or removing reviewers who are unavailable.
|
|
<!-- END MANUAL -->
|
|
|
|
### Inputs
|
|
|
|
| Input | Description | Type | Required |
|
|
|-------|-------------|------|----------|
|
|
| pr_url | URL of the GitHub pull request | str | Yes |
|
|
| reviewer | Username of the reviewer to unassign | str | Yes |
|
|
|
|
### Outputs
|
|
|
|
| Output | Description | Type |
|
|
|--------|-------------|------|
|
|
| error | Error message if the reviewer unassignment failed | str |
|
|
| status | Status of the reviewer unassignment operation | str |
|
|
|
|
### Possible use case
|
|
<!-- MANUAL: use_case -->
|
|
**Reviewer Reassignment**: Remove unavailable reviewers and replace them with available team members.
|
|
|
|
**Load Balancing**: Unassign reviewers who have too many pending reviews.
|
|
|
|
**Vacation Coverage**: Automatically remove reviewers who are out of office.
|
|
<!-- END MANUAL -->
|
|
|
|
---
|