66
77from github .PullRequest import PullRequest
88from github .Repository import Repository
9- from github .PaginatedList import PaginatedList
109from github .MainClass import Github
1110from github .GithubException import UnknownObjectException
1211from github .Organization import Organization
1312from github .Team import Team
14- from github .NamedUser import NamedUser
1513
1614from constants import (
1715 ALL_LABELS_DICT ,
@@ -102,26 +100,20 @@ def __init__(self) -> None:
102100 self .last_commit = list (self .pr .get_commits ())[- 1 ]
103101 self .last_commit_sha = self .last_commit .sha
104102
105- self .verify_allowed_user ()
106103 self .verify_labeler_config ()
107104
108- def get_allowed_users (self ) -> list [ str ] :
105+ def verify_allowed_user (self ) -> None :
109106 org : Organization = self .gh_client .get_organization ("opendatahub-io" )
110107 # slug is the team name with replaced special characters,
111108 # all words to lowercase and spaces replace with a -
112109 team : Team = org .get_team_by_slug ("opendatahub-tests-contributors" )
113- members : PaginatedList [NamedUser ] = team .get_members ()
114- users = [member .login for member in members ]
115- # TODO: replace once bot user is part of the org and team
116- # users = ["lugi0", "rnetser", "adolfo-ab", "tarukumar", "dbasunag", "mwaykole"]
117- return users
118-
119- def verify_allowed_user (self ) -> None :
120- allowed_users = self .get_allowed_users ()
121- if self .user_login not in allowed_users :
122- LOGGER .info (f"User { self .user_login } is not allowed for this action. Exiting." )
110+ try :
111+ # check if the user is a member of opendatahub-tests-contributors
112+ membership = team .get_team_membership (self .user_login )
113+ LOGGER .info (f"User { self .user_login } is a member of the test contributor team. { membership } " )
114+ except UnknownObjectException :
115+ LOGGER .error (f"User { self .user_login } is not allowed for this action. Exiting." )
123116 sys .exit (0 )
124- LOGGER .info (f"User { self .user_login } is allowed" )
125117
126118 def verify_labeler_config (self ) -> None :
127119 if self .action == self .SupportedActions .add_remove_labels_action_name and self .event_name in (
@@ -142,6 +134,7 @@ def run_pr_label_action(self) -> None:
142134 self .set_pr_size ()
143135
144136 if self .action == self .SupportedActions .add_remove_labels_action_name :
137+ self .verify_allowed_user ()
145138 self .add_remove_pr_labels ()
146139
147140 if self .action == self .SupportedActions .welcome_comment_action_name :
0 commit comments