Skip to content

Commit

Permalink
Fix author-in-team (#154)
Browse files Browse the repository at this point in the history
Use the right GH API to resolve team membership

Signed-off-by: Galo Navarro <[email protected]>
  • Loading branch information
srvaroa authored Oct 9, 2024
1 parent 50e8212 commit 29471ee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/condition_author_in_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
},
}
}
2 changes: 1 addition & 1 deletion pkg/labeler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/labeler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
Expand Down

0 comments on commit 29471ee

Please sign in to comment.