-
Notifications
You must be signed in to change notification settings - Fork 123
Commit 9d37ec0
Create standalone version of Get PR Comments script for use in other repos, with added features. (#1742)
* Feat: Create standalone get_pr_review_comments script
- Creates a new script `get_pr_review_comments_standalone.py`.
- Inlines necessary functions from `firebase_github.py` to make it standalone.
- Adds functionality to auto-determine GitHub owner/repo from git remote origin.
- Allows specifying repository via `--url` or `--owner`/`--repo` arguments.
- Prioritizes URL > owner/repo args > git remote detection.
- Improves argument parsing and error handling for repository specification.
* Fix: Remove deprecated nested argument group
- Removes the deprecated nested `add_argument_group` for owner/repo.
- `--owner` and `--repo` are now top-level arguments.
- Implements manual validation logic after parsing to ensure correct argument pairing and exclusivity with `--url`.
- This addresses the DeprecationWarning while maintaining the intended argument behavior.
* Feat: Auto-detect PR number from current git branch
- Makes the --pull_number argument optional.
- If --pull_number is not provided, the script now attempts to:
1. Determine the current git branch.
2. Fetch open pull requests for this branch using the GitHub API.
3. Select the most recently created open PR.
- If a PR cannot be determined either way, an error is shown.
- Incorporates the `list_pull_requests` function from the original
`firebase_github.py` to support this feature.
- Adds error handling for git operations and API calls related to PR detection.
* Fix: Resolve conflicting --pull_number argument definition
Removes the duplicate argparse definition for `--pull_number`,
resolving the `argparse.ArgumentError`. The `--pull_number` argument
is now correctly defined once as an optional argument, with the
script falling back to auto-detection if it's not provided.
* Refactor: Refine error reporting for auto-detection failures
- Removes `parser.print_help()` calls for specific auto-detection failures:
- When the repository owner/name cannot be determined automatically and is not specified by the user.
- When the current git branch cannot be determined (and --pull_number is not provided).
- The script will still print a targeted error message and exit with an error code in these scenarios.
- Other error conditions (e.g., invalid explicit arguments, or no PR found for a valid detected branch) will continue to print full usage information.
* Refactor: Standardize error reporting for argument failures
- Removes `parser.print_help()` calls from all error exit paths related to missing or invalid script arguments.
- Appends a consistent ' (use --help for more details)' note to these error messages.
- This provides more concise error output while still guiding the user to help if needed.
- Affects errors for token, URL, owner/repo specification, and PR number determination.
* Style: Remove extraneous comments
Performs a thorough pass on `get_pr_review_comments_standalone.py`
to remove comments that are redundant, obvious restatements of code,
obsolete placeholders, or no longer accurate due to prior changes.
Retains comments that clarify complex or non-obvious logic,
provide essential context, or document important decisions (such as
compatibility shims or API-specific formatting).
This change aims to improve code clarity and maintainability by
reducing comment clutter.
* Refactor: Set default logging verbosity to WARNING
Changes the default `absl.logging` verbosity level from INFO to WARNING.
This reduces the amount of log output during normal operation, as INFO-level
messages detailing each API call page fetch will no longer be displayed
by default. WARNING and ERROR level logs will still be shown.
Users needing to debug API calls can temporarily change the verbosity
level back to INFO in the script.
* Feat: Include top-level PR review summaries in output
- Adds functionality to fetch overall pull request reviews (e.g., approval/changes requested summaries).
- Introduces `get_pull_request_reviews()` to call the relevant GitHub API endpoint.
- In `main()`:
- Fetches these overall reviews.
- Filters them to exclude 'DISMISSED' states.
- Applies the `--since` argument to filter reviews based on their `submitted_at` timestamp (client-side filtering).
- Sorts the filtered reviews chronologically (oldest first).
- Prints these overall review summaries under a new "# Overall Review Summaries" header before printing line-specific comments.
- Output includes reviewer, submission time, state, review body (if any), and a link to the review.
- Handles errors during the fetching of overall reviews separately.
- Ensures that the `--since` argument continues to apply independently to line-specific comments based on their `updated_at` timestamp.
* Refine: Exclude empty 'COMMENTED' overall reviews from output
Further refines the display of top-level pull request review summaries.
Overall reviews that have a state of "COMMENTED" and an empty (or whitespace-only) body are now filtered out and not displayed.
This helps to reduce noise from review submissions that don't contain
a summary message, while still showing approvals, changes requested, or
commented reviews that do have content.
* Feat: Enhance 'next command' suggestion with overall review timestamps
Improves the accuracy and applicability of the suggested next command
for fetching subsequent comments.
- The script now tracks the latest `submitted_at` timestamp from
overall PR reviews, in addition to the latest `updated_at` timestamp
from line-specific comments.
- The `--since` value in the suggested next command is now based on the
globally latest timestamp found across both overall reviews and line
comments.
- This ensures that a 'next command' suggestion can be provided even if
only overall reviews (or only line comments) were found, and that the
timestamp used is the most recent activity of either type.
* Feat: Create print_github_reviews.py script and add features
This commit culminates a series of enhancements to create a standalone script
for printing GitHub pull request review information.
Key changes from the original `get_pr_review_comments.py` and subsequent iterations include:
- Renamed script to `scripts/print_github_reviews.py` (from `scripts/gha/get_pr_review_comments_standalone.py`).
- Made script standalone by inlining necessary GitHub API interaction functions.
- Auto-detection of repository owner/name from git remote.
- Auto-detection of PR number from the current git branch if not specified.
- Added support for fetching and displaying top-level PR review summaries (e.g., Approve, Comment, Changes Requested) in addition to line comments.
- Top-level reviews are filtered for 'DISMISSED' state and by `--since` timestamp.
- Empty-bodied 'COMMENTED' top-level reviews are also filtered out.
- Enhanced the 'next command' suggestion to use the latest timestamp from either overall reviews or line comments.
- Numerous bug fixes and refinements to argument parsing, error handling, and output formatting:
- Resolved `UnboundLocalError` for timestamp tracking.
- Addressed `argparse` conflict for `--pull_number`.
- Removed deprecated nested argument groups.
- Standardized error messages to be more concise and suggest `--help`.
- Conditional printing of section headers.
- Default logging verbosity set to WARNING.
- Removed extraneous comments.
* Fix: Resolve UnboundLocalError and remove absl-py dependency
- Fixes an `UnboundLocalError` for `latest_overall_review_activity_dt`
by ensuring it and related timestamp-tracking variables are initialized
at the beginning of the `main()` function scope before potential use.
- Removes the `absl-py` dependency from the script:
- Deletes the `absl` import and `logging.set_verbosity()` call.
- All `logging.info()` calls (previously used for API call details)
have been removed to reduce verbosity.
- `logging.error()` calls have been replaced with direct writes to
`sys.stderr`, prefixed with "Error:".
This simplifies dependencies and resolves the runtime error, while ensuring
important error messages are still reported.
* Fix: Definitively resolve UnboundLocalError for timestamp tracking
- Addresses a persistent `UnboundLocalError` related to `latest_overall_review_activity_dt`.
- While the variable was initialized at the top of `main()`, to ensure robust scoping within the loop that processes overall reviews, a temporary variable (`temp_latest_overall_review_dt`) is now used for accumulating the latest timestamp within that specific loop.
- The main `latest_overall_review_activity_dt` is then updated from this temporary variable if any overall review timestamps were processed.
- This change ensures the variable is always defined before use in the conditional check that was causing the error.
(This commit also includes prior changes for removing the absl-py dependency and refactoring logging, which were part of the same active development session.)
* Fix: Ensure 'next command' suggestion considers overall reviews timestamps
- Corrects the logic for generating the 'next command' suggestion to ensure
it appears even if only overall PR reviews (and no line comments) are present.
- The script now reliably uses the latest timestamp from either overall review
`submitted_at` or line comment `updated_at` fields.
- Removed a premature `return` that bypassed the suggestion logic when line
comments were empty but overall reviews might have had timestamps.
This also includes a pass for final extraneous comment removal.
* Fix: Resolve UnboundLocalError for processed_comments_count
- Ensures `processed_comments_count` is initialized to 0 at the
beginning of the `main()` function scope, alongside other tracking
variables like `latest_overall_review_activity_dt` and
`latest_line_comment_activity_dt`.
- This prevents an `UnboundLocalError` when the script attempts to print
the number of processed line comments in scenarios where the line
comment processing loop is skipped (e.g., if no line comments are fetched).
This commit finalizes fixes for variable initialization and scoping issues.
* Style: Final comment cleanup and text refinements
- Removes the unused `TIMEOUT_LONG` constant.
- Adds a blank line after imports for PEP 8 compliance.
- Changes the output heading for overall review bodies from
"### Summary Comment:" to "### Comment:".
- Performs a final pass to remove extraneous, obsolete, or
iteration-related comments throughout the script, while retaining
comments that explain non-obvious logic or important context.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>1 parent 5ea2a16 commit 9d37ec0Copy full SHA for 9d37ec0
File tree
Expand file treeCollapse file tree
1 file changed
+598
-0
lines changedFilter options
- scripts
Expand file treeCollapse file tree
1 file changed
+598
-0
lines changed
0 commit comments