From 29471ee1118fa4e10b011964e6e8fe2fd243e700 Mon Sep 17 00:00:00 2001 From: Galo Navarro Date: Wed, 9 Oct 2024 21:35:15 +0200 Subject: [PATCH] Fix author-in-team (#154) Use the right GH API to resolve team membership Signed-off-by: Galo Navarro --- cmd/action.go | 6 +++--- pkg/condition_author_in_team.go | 6 +++++- pkg/labeler.go | 2 +- pkg/labeler_test.go | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/action.go b/cmd/action.go index 137be2d..01b5f81 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -231,7 +231,7 @@ func newLabeler(gh *github.Client, config *labeler.LabelerConfigV1) *labeler.Lab GetRawDiff: func(owner, repo string, prNumber int) (string, error) { diff, _, err := gh.PullRequests.GetRaw(ctx, owner, repo, prNumber, - github.RawOptions{github.Diff}) + github.RawOptions{Type: github.Diff}) return diff, err }, ListIssuesByRepo: func(owner, repo string) ([]*github.Issue, error) { @@ -244,8 +244,8 @@ func newLabeler(gh *github.Client, config *labeler.LabelerConfigV1) *labeler.Lab owner, repo, &github.PullRequestListOptions{}) return prs, err }, - IsUserMemberOfTeam: func(user, team string) (bool, error) { - membership, _, err := gh.Organizations.GetOrgMembership(ctx, user, team) + IsUserMemberOfTeam: func(org, user, team string) (bool, error) { + membership, _, err := gh.Teams.GetTeamMembershipBySlug(ctx, org, team, user) if err != nil { return false, err } diff --git a/pkg/condition_author_in_team.go b/pkg/condition_author_in_team.go index 96c53d9..ecd7e12 100644 --- a/pkg/condition_author_in_team.go +++ b/pkg/condition_author_in_team.go @@ -17,7 +17,11 @@ func AuthorInTeamCondition(l *Labeler) Condition { return false, fmt.Errorf("author-in-team is not set in config") } // check if author is a member of team - return l.GitHubFacade.IsUserMemberOfTeam(target.Author, matcher.AuthorInTeam) + return l.GitHubFacade.IsUserMemberOfTeam( + target.Owner, + target.Author, + matcher.AuthorInTeam, // this is the team slug + ) }, } } diff --git a/pkg/labeler.go b/pkg/labeler.go index 1f61624..a64016c 100644 --- a/pkg/labeler.go +++ b/pkg/labeler.go @@ -69,7 +69,7 @@ type GitHubFacade struct { GetRawDiff func(owner, repo string, prNumber int) (string, error) ListIssuesByRepo func(owner, repo string) ([]*gh.Issue, error) ListPRs func(owner, repo string) ([]*gh.PullRequest, error) - IsUserMemberOfTeam func(user, team string) (bool, error) + IsUserMemberOfTeam func(org, user, team string) (bool, error) } type Labeler struct { diff --git a/pkg/labeler_test.go b/pkg/labeler_test.go index 50316b6..b0aade9 100644 --- a/pkg/labeler_test.go +++ b/pkg/labeler_test.go @@ -1075,7 +1075,7 @@ func NewTestLabeler(t *testing.T, tc TestCase) Labeler { return string(data), nil }, // Will return true whenever team contains the given user name - IsUserMemberOfTeam: func(user, team string) (bool, error) { + IsUserMemberOfTeam: func(org, user, team string) (bool, error) { return strings.Contains(team, user), nil }, },