From 449920b40fc8a5015d1578ca10a301aa385a1914 Mon Sep 17 00:00:00 2001 From: Kynan Ware <47394200+BagToad@users.noreply.github.com> Date: Tue, 22 Jul 2025 10:47:24 -0600 Subject: [PATCH] Add TeamReviewers flag to RepoMetadataInput Introduces a TeamReviewers boolean to RepoMetadataInput to control whether team reviewers are fetched. Updates RepoMetadata logic to only fetch teams if both Reviewers and TeamReviewers are true. Adds tests to verify correct behavior when TeamReviewers is false. --- api/queries_repo.go | 3 ++- api/queries_repo_test.go | 49 +++++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/api/queries_repo.go b/api/queries_repo.go index 6552aa230..324200afd 100644 --- a/api/queries_repo.go +++ b/api/queries_repo.go @@ -919,6 +919,7 @@ type RepoMetadataInput struct { Assignees bool ActorAssignees bool Reviewers bool + TeamReviewers bool Labels bool ProjectsV1 bool ProjectsV2 bool @@ -964,7 +965,7 @@ func RepoMetadata(client *Client, repo ghrepo.Interface, input RepoMetadataInput } } - if input.Reviewers { + if input.Reviewers && input.TeamReviewers { g.Go(func() error { teams, err := OrganizationTeams(client, repo) // TODO: better detection of non-org repos diff --git a/api/queries_repo_test.go b/api/queries_repo_test.go index c885b9968..2f7a335ca 100644 --- a/api/queries_repo_test.go +++ b/api/queries_repo_test.go @@ -42,12 +42,13 @@ func Test_RepoMetadata(t *testing.T) { repo, _ := ghrepo.FromFullName("OWNER/REPO") input := RepoMetadataInput{ - Assignees: true, - Reviewers: true, - Labels: true, - ProjectsV1: true, - ProjectsV2: true, - Milestones: true, + Assignees: true, + Reviewers: true, + TeamReviewers: true, + Labels: true, + ProjectsV1: true, + ProjectsV2: true, + Milestones: true, } http.Register( @@ -213,6 +214,42 @@ func Test_RepoMetadata(t *testing.T) { } } +func Test_RepoMetadataTeams(t *testing.T) { + // Test that RepoMetadata only fetches teams if the input specifies it + http := &httpmock.Registry{} + client := newTestClient(http) + repo, _ := ghrepo.FromFullName("OWNER/REPO") + input := RepoMetadataInput{ + Reviewers: true, + TeamReviewers: false, + } + + http.Register( + httpmock.GraphQL(`query RepositoryAssignableUsers\b`), + httpmock.StringResponse(` + { "data": { "repository": { "assignableUsers": { + "nodes": [ + { "login": "hubot", "id": "HUBOTID" }, + { "login": "MonaLisa", "id": "MONAID" } + ], + "pageInfo": { "hasNextPage": false } + } } } } + `)) + + http.Register( + httpmock.GraphQL(`query UserCurrent\b`), + httpmock.StringResponse(` + { "data": { "viewer": { "login": "monalisa" } } } + `)) + + _, err := RepoMetadata(client, repo, input) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + require.NoError(t, err) +} + func Test_ProjectNamesToPaths(t *testing.T) { t.Run("when projectsV1 is supported, requests them", func(t *testing.T) { http := &httpmock.Registry{}