Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix author-in-team #154

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading