Skip to content

Improve Toad's PR reviewer suggestions: enhance change detection lo...#2

Merged
HergenD merged 2 commits intomainfrom
toad/plf-3219-improve-toad-s-pr-reviewer-sugg-c6921655bfd73bf6
Mar 10, 2026
Merged

Improve Toad's PR reviewer suggestions: enhance change detection lo...#2
HergenD merged 2 commits intomainfrom
toad/plf-3219-improve-toad-s-pr-reviewer-sugg-c6921655bfd73bf6

Conversation

@HergenD
Copy link
Member

@HergenD HergenD commented Mar 10, 2026

Summary

Improve Toad's PR reviewer suggestions: enhance change detection logic, limit to 2 suggested reviewers, and tag GitHub accounts in PR description instead of plain text

Linear: PLF-3219

View Slack thread

Category: feature | Size: small

Suggested reviewers (based on recent file history): Hergen Dillema

Slack context

Improve PR reviewer suggestions: better change detection, cap at 2, tag GitHub accounts.

Files to change

  • internal/vcs/github.goGetFileContributors function
  • internal/tadpole/runner.go — reviewer section building

Changes

1. internal/vcs/github.go

Rename or replace GetFileContributors(ctx, repoPath, files, botSet, maxTotal) with a version that returns GitHub login handles instead of git author names.

New approach:

  1. Run git log --format=%H -- <files> (collect commit SHAs for changed files)
  2. Deduplicate SHAs
  3. For each SHA, call the GitHub REST API: GET /repos/{owner}/{repo}/commits/{sha} — the response includes author.login (the GitHub username). Use the existing GitHubProvider's authenticated client for these calls.
  4. Count occurrences per login, exclude bots (same filtering as before: botNames map + strings.Contains(lower, "bot"))
  5. Sort by count desc, return top maxTotal logins as []string (each entry is just the login, e.g. "johndoe").

The GitHubProvider struct already has owner/repo info and a GitHub client — add a method on *GitHubProvider rather than a standalone function so it has access to the client. Something like:

func (g *GitHubProvider) GetSuggestedReviewers(ctx context.Context, repoPath string, files []string, botNames map[string]bool, max int) []string

2. internal/tadpole/runner.go

In the ship function where reviewers are built:

  • Change the maxTotal argument from 5 to 2
  • Call the new method vcsProvider.(*vcs.GitHubProvider).GetSuggestedReviewers(...) instead of vcs.GetFileContributors(...)
  • Format each login with @ prefix so GitHub renders them as mentions: "@" + login
  • Update the reviewersSection format string to reflect this is tagging real accounts, e.g.:
    reviewersSection = fmt.Sprintf("**Suggested reviewers:** %s\n\n", strings.Join(tagged, ", "))
    where tagged is the slice with @ prepended to each login.

Notes

  • Keep the change n

(truncated)


🐸 Created by toad tadpole

Replace git author name lookup with GitHub API-based login resolution.
GetSuggestedReviewers collects commit SHAs for changed files (capped at 20),
resolves each to a GitHub login via gh api, filters bots, and returns the
top contributors by commit count. The PR body now shows @login mentions
capped at 2 instead of 5 plain author names.
@HergenD
Copy link
Member Author

HergenD commented Mar 10, 2026

Review

The core idea is good — resolving to GitHub login handles for proper @-mentions is a real improvement over plain git author names. A few things to address:

Promote GetSuggestedReviewers to the Provider interface

The new method is added directly on *GitHubProvider, and runner.go uses a type assertion to call it:

if ghProvider, ok := vcsProvider.(*vcs.GitHubProvider); ok {
    logins := ghProvider.GetSuggestedReviewers(...)
}

This means GitLab repos get no reviewer suggestions at all, and any future provider would need its own special-cased type assertion. Instead, add GetSuggestedReviewers to the Provider interface so every platform can implement it and the runner just calls vcsProvider.GetSuggestedReviewers(...) with no type assertion.

The old code had the same problem (GetFileContributors was a standalone function gated behind a GitHub type check) — this PR is a good opportunity to fix that pattern rather than carry it forward.

Add -n 20 to git log

git log --format=%H -- <files> without -n scans the entire history. The 20-SHA cap only limits what's processed, not what git traverses. Adding -n 20 to the args avoids unnecessary work in large repos.

Remove dead GetFileContributors

The old function is still in github.go but no longer called from runner.go. Should be cleaned up.

Minor: bot filtering case inconsistency

botNames[login] checks original case, but the strings.Contains(lower, "bot") check uses lowercase. If botNames contains "MyBot", it won't match a login of "mybot". Should normalize both sides.

- Add GetSuggestedReviewers to the Provider interface so all platforms
  implement it; removes the *GitHubProvider type assertion in runner.go
- Add GitLabProvider stub that returns nil (not implemented)
- Add -n 20 to git log in GetSuggestedReviewers to avoid scanning full
  history on large repos
- Remove dead GetFileContributors function (no longer called)
- Normalize botNames lookup to lowercase to match the strings.ToLower
  check, fixing case inconsistency in bot filtering
@HergenD HergenD merged commit 16f243a into main Mar 10, 2026
8 checks passed
@HergenD
Copy link
Member Author

HergenD commented Mar 10, 2026

LGTM — all feedback addressed:

  • GetSuggestedReviewers promoted to Provider interface with GitLab stub
  • Type assertion removed from runner — clean provider-agnostic call
  • -n 20 on git log to limit traversal
  • Bot filtering case-normalized
  • Old GetFileContributors removed

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.

1 participant