-
Notifications
You must be signed in to change notification settings - Fork 23
fix(docs): make Agent docs review the only gate #688
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/usr/bin/env python3 | ||
| """Print stale GitHub Actions change-request review IDs, one per line.""" | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import sys | ||
| from pathlib import Path | ||
| from typing import Iterable, Mapping, Optional | ||
|
|
||
|
|
||
| def stale_review_ids( | ||
| reviews: Iterable[Mapping[str, object]], | ||
| head_sha: str, | ||
| reviewer_login: str = "github-actions[bot]", | ||
| ) -> list[int]: | ||
| """Select only prior blocking reviews published by the automation account.""" | ||
| stale_ids: list[int] = [] | ||
| for review in reviews: | ||
| author = review.get("user") | ||
| login = author.get("login") if isinstance(author, Mapping) else None | ||
| if ( | ||
| login == reviewer_login | ||
| and review.get("state") == "CHANGES_REQUESTED" | ||
| and review.get("commit_id") != head_sha | ||
| and isinstance(review.get("id"), int) | ||
| ): | ||
| stale_ids.append(review["id"]) | ||
| return stale_ids | ||
|
|
||
|
|
||
| def main(argv: Optional[list[str]] = None) -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--reviews", required=True, type=Path) | ||
| parser.add_argument("--head-sha", required=True) | ||
| parser.add_argument("--reviewer-login", default="github-actions[bot]") | ||
| args = parser.parse_args(argv) | ||
| try: | ||
| reviews = json.loads(args.reviews.read_text(encoding="utf-8")) | ||
| except (OSError, json.JSONDecodeError) as exc: | ||
| print(f"error: {exc}", file=sys.stderr) | ||
| return 1 | ||
| if not isinstance(reviews, list): | ||
| print("error: reviews JSON must be an array", file=sys.stderr) | ||
| return 1 | ||
| for review_id in stale_review_ids( | ||
| reviews, args.head_sha, args.reviewer_login | ||
| ): | ||
| print(review_id) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/usr/bin/env python3 | ||
| """Unit tests for stale_review_requests.py.""" | ||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| import sys | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| _HERE = Path(__file__).resolve().parent | ||
| _spec = importlib.util.spec_from_file_location( | ||
| "stale_review_requests", _HERE / "stale_review_requests.py" | ||
| ) | ||
| srr = importlib.util.module_from_spec(_spec) | ||
| sys.modules[_spec.name] = srr | ||
| _spec.loader.exec_module(srr) | ||
|
|
||
|
|
||
| class TestStaleReviewIds(unittest.TestCase): | ||
| def test_selects_only_prior_automated_change_requests(self): | ||
| reviews = [ | ||
| { | ||
| "id": 1, | ||
| "state": "CHANGES_REQUESTED", | ||
| "commit_id": "old-sha", | ||
| "user": {"login": "github-actions[bot]"}, | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "state": "CHANGES_REQUESTED", | ||
| "commit_id": "current-sha", | ||
| "user": {"login": "github-actions[bot]"}, | ||
| }, | ||
| { | ||
| "id": 3, | ||
| "state": "APPROVED", | ||
| "commit_id": "old-sha", | ||
| "user": {"login": "github-actions[bot]"}, | ||
| }, | ||
| { | ||
| "id": 4, | ||
| "state": "CHANGES_REQUESTED", | ||
| "commit_id": "old-sha", | ||
| "user": {"login": "reviewer"}, | ||
| }, | ||
| ] | ||
|
|
||
| self.assertEqual(srr.stale_review_ids(reviews, "current-sha"), [1]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,20 @@ jobs: | |
| 4. Emit one [SIGNAL:pr-review] JSON record with this head SHA, verdict, severity | ||
| counts, and top categories. Set reviewer_login to `github-actions[bot]`, the | ||
| runner account that will publish the review. | ||
| - name: Dismiss stale automated change requests | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews?per_page=100" > /tmp/reviews.json | ||
| python3 .agents/skills/doc_quality_policy/stale_review_requests.py \ | ||
| --reviews /tmp/reviews.json \ | ||
| --head-sha "${{ github.event.pull_request.head.sha }}" | | ||
| while IFS= read -r review_id; do | ||
|
Contributor
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.
|
||
| [ -z "$review_id" ] && continue | ||
| gh api --method PUT \ | ||
| "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews/${review_id}/dismissals" \ | ||
| -f "message=Superseded by the current Agent docs review check." | ||
| done | ||
|
|
||
| - name: Publish the independent review | ||
| env: | ||
|
|
||
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.
CHANGES_REQUESTEDreview on a later page and still keep GitHub's review gate blocking merge after this step completes. Paginate and slurp all pages before passing them tostale_review_requests.py.