<commit_before>package comments

import (
	"fmt"
	"log"

	"github.com/google/go-github/github"
)

var (
	teamsCache             = map[string][]github.Team{}
	teamHasPushAccessCache = map[string]*github.Repository{}
	teamMembershipCache    = map[string]bool{}
)

type Authenticator struct {
	client *github.Client
}

func isAuthorizedCommenter(client *github.Client, event github.IssueCommentEvent) bool {
	auth := Authenticator{client: client}
	orgTeams := auth.teamsForOrg(*event.Repo.Owner.Login)
	for _, team := range orgTeams {
		if auth.isTeamMember(*team.ID, *event.Comment.User.Login) &&
			auth.teamHasPushAccess(*team.ID, *event.Repo.Owner.Name, *event.Repo.Name) {
			return true
		}
	}
	return false
}

func (auth Authenticator) isTeamMember(teamId int, login string) bool {
	cacheKey := auth.cacheKeyIsTeamMember(teamId, login)
	if _, ok := teamMembershipCache[cacheKey]; !ok {
		newOk, _, err := auth.client.Organizations.IsTeamMember(teamId, login)
		if err != nil {
			log.Printf("ERROR performing IsTeamMember(%d, \"%s\"): %v", teamId, login, err)
			return false
		}
		teamMembershipCache[cacheKey] = newOk
	}
	return teamMembershipCache[cacheKey]
}

func (auth Authenticator) teamHasPushAccess(teamId int, owner, repo string) bool {
	cacheKey := auth.cacheKeyTeamHashPushAccess(teamId, owner, repo)
	if _, ok := teamHasPushAccessCache[cacheKey]; !ok {
		repository, _, err := auth.client.Organizations.IsTeamRepo(teamId, owner, repo)
		if err != nil {
			log.Printf("ERROR performing IsTeamRepo(%d, \"%s\", \"%s\"): %v", teamId, repo, err)
			return false
		}<commit_msg>Use .Login instead of .Name<commit_after>package comments

import (
	"fmt"
	"log"

	"github.com/google/go-github/github"
)

var (
	teamsCache             = map[string][]github.Team{}
	teamHasPushAccessCache = map[string]*github.Repository{}
	teamMembershipCache    = map[string]bool{}
)

type Authenticator struct {
	client *github.Client
}

func isAuthorizedCommenter(client *github.Client, event github.IssueCommentEvent) bool {
	auth := Authenticator{client: client}
	orgTeams := auth.teamsForOrg(*event.Repo.Owner.Login)
	for _, team := range orgTeams {
		if auth.isTeamMember(*team.ID, *event.Comment.User.Login) &&
			auth.teamHasPushAccess(*team.ID, *event.Repo.Owner.Login, *event.Repo.Name) {
			return true
		}
	}
	return false
}

func (auth Authenticator) isTeamMember(teamId int, login string) bool {
	cacheKey := auth.cacheKeyIsTeamMember(teamId, login)
	if _, ok := teamMembershipCache[cacheKey]; !ok {
		newOk, _, err := auth.client.Organizations.IsTeamMember(teamId, login)
		if err != nil {
			log.Printf("ERROR performing IsTeamMember(%d, \"%s\"): %v", teamId, login, err)
			return false
		}
		teamMembershipCache[cacheKey] = newOk
	}
	return teamMembershipCache[cacheKey]
}

func (auth Authenticator) teamHasPushAccess(teamId int, owner, repo string) bool {
	cacheKey := auth.cacheKeyTeamHashPushAccess(teamId, owner, repo)
	if _, ok := teamHasPushAccessCache[cacheKey]; !ok {
		repository, _, err := auth.client.Organizations.IsTeamRepo(teamId, owner, repo)
		if err != nil {
			log.Printf("ERROR performing IsTeamRepo(%d, \"%s\", \"%s\"): %v", teamId, repo, err)
			return false
		}
{'fraction_non_alphanumeric': 0.137801440651425, 'fraction_numerical': 0.0, 'mean_word_length': 4.734290843806104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6854738', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1091, 'n_words': 234}