Skip to content

Detect team review requests via the reviewers API - #141

Merged
mokagio merged 1 commit into
trunkfrom
mokagio/team-review-requests
Aug 5, 2026
Merged

Detect team review requests via the reviewers API#141
mokagio merged 1 commit into
trunkfrom
mokagio/team-review-requests

Conversation

@mokagio

@mokagio mokagio commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Rationale

Reported on wordpress-mobile/release-toolkit#761: Danger warned "No reviewers have been set for this PR yet" on a PR whose apps-infra-tooling team review request had been pending for three minutes.

requested_reviewers? read requested_teams off pr_json. GitHub strips that field from the pull request payload for tokens that cannot see the organization's teams, and the dangermattic bot is an outside collaborator on wordpress-mobile, not a member. So on repos where CODEOWNERS assigns a team and no individual, the warning fired on every PR until someone (or Copilot) actually reviewed.

GET /pulls/{n}/requested_reviewers reports teams regardless of org visibility, so this switches to it.

Gotchas

The old behaviour was masked in release-toolkit by active_reviewers?: Copilot's automatic review made the check pass before anyone noticed the team wasn't being seen.

This is not the timing race between PR creation and CODEOWNERS assignment that was also suspected on that thread — the failing Danger run happened three minutes after the request was recorded.

How to test

bundle exec rake

Against the live PR that surfaced this, the two sources differ exactly as described — old source empty without org visibility, new source correct either way:

[org-visible token] pr_json['requested_teams'] -> ["apps-infra-tooling"]
[org-visible token] review_requests['teams']   -> ["apps-infra-tooling"]

[no org visibility] pr_json['requested_teams'] -> []
[no org visibility] review_requests['teams']   -> ["apps-infra-tooling"]

`requested_reviewers?` read `requested_teams` off `pr_json`, which GitHub
strips for tokens that cannot see the organization's teams.
The `dangermattic` bot is an outside collaborator on `wordpress-mobile`, so
every PR whose only reviewer is a team — as `CODEOWNERS` assigns — was
reported as having no reviewers.

Verified against wordpress-mobile/release-toolkit#761, where a team review
request is pending: `pr_json['requested_teams']` is `[]` without org
visibility, while `pull_request_review_requests` returns the team either way.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 29, 2026 04:26
@mokagio mokagio self-assigned this Jul 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the GithubUtils#requested_reviewers? Danger helper to correctly detect team review requests even when the GitHub token cannot see organization teams, by switching from pr_json fields to the dedicated “requested reviewers” API endpoint.

Changes:

  • Update requested_reviewers? to use GET /pulls/{n}/requested_reviewers via Octokit (pull_request_review_requests).
  • Add small private helpers for PR repo/name extraction (pr_repo_name, pr_number) and reuse them in active_reviewers?.
  • Update RSpec coverage and add a changelog entry for the bug fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/dangermattic/plugins/common/github_utils.rb Switch requested-reviewer detection to the dedicated review-requests API and reuse shared PR identifiers.
spec/github_utils_spec.rb Adjust tests to validate requested-reviewer detection with the new API source.
CHANGELOG.md Document the behavioral fix for team review requests with limited-visibility tokens.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/dangermattic/plugins/common/github_utils.rb
Comment thread spec/github_utils_spec.rb

private

def pr_repo_name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@iangmaia iangmaia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@mokagio
mokagio merged commit 3090ba7 into trunk Aug 5, 2026
6 checks passed
@mokagio
mokagio deleted the mokagio/team-review-requests branch August 5, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants