Skip to content

Commit 29471ee

Browse files
authored
Fix author-in-team (#154)
Use the right GH API to resolve team membership Signed-off-by: Galo Navarro <anglorvaroa@gmail.com>
1 parent 50e8212 commit 29471ee

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

cmd/action.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func newLabeler(gh *github.Client, config *labeler.LabelerConfigV1) *labeler.Lab
231231
GetRawDiff: func(owner, repo string, prNumber int) (string, error) {
232232
diff, _, err := gh.PullRequests.GetRaw(ctx,
233233
owner, repo, prNumber,
234-
github.RawOptions{github.Diff})
234+
github.RawOptions{Type: github.Diff})
235235
return diff, err
236236
},
237237
ListIssuesByRepo: func(owner, repo string) ([]*github.Issue, error) {
@@ -244,8 +244,8 @@ func newLabeler(gh *github.Client, config *labeler.LabelerConfigV1) *labeler.Lab
244244
owner, repo, &github.PullRequestListOptions{})
245245
return prs, err
246246
},
247-
IsUserMemberOfTeam: func(user, team string) (bool, error) {
248-
membership, _, err := gh.Organizations.GetOrgMembership(ctx, user, team)
247+
IsUserMemberOfTeam: func(org, user, team string) (bool, error) {
248+
membership, _, err := gh.Teams.GetTeamMembershipBySlug(ctx, org, team, user)
249249
if err != nil {
250250
return false, err
251251
}

pkg/condition_author_in_team.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ func AuthorInTeamCondition(l *Labeler) Condition {
1717
return false, fmt.Errorf("author-in-team is not set in config")
1818
}
1919
// check if author is a member of team
20-
return l.GitHubFacade.IsUserMemberOfTeam(target.Author, matcher.AuthorInTeam)
20+
return l.GitHubFacade.IsUserMemberOfTeam(
21+
target.Owner,
22+
target.Author,
23+
matcher.AuthorInTeam, // this is the team slug
24+
)
2125
},
2226
}
2327
}

pkg/labeler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type GitHubFacade struct {
6969
GetRawDiff func(owner, repo string, prNumber int) (string, error)
7070
ListIssuesByRepo func(owner, repo string) ([]*gh.Issue, error)
7171
ListPRs func(owner, repo string) ([]*gh.PullRequest, error)
72-
IsUserMemberOfTeam func(user, team string) (bool, error)
72+
IsUserMemberOfTeam func(org, user, team string) (bool, error)
7373
}
7474

7575
type Labeler struct {

pkg/labeler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ func NewTestLabeler(t *testing.T, tc TestCase) Labeler {
10751075
return string(data), nil
10761076
},
10771077
// Will return true whenever team contains the given user name
1078-
IsUserMemberOfTeam: func(user, team string) (bool, error) {
1078+
IsUserMemberOfTeam: func(org, user, team string) (bool, error) {
10791079
return strings.Contains(team, user), nil
10801080
},
10811081
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy