Skip to content

Commit f5a3256

Browse files
committed
ci: merge main branch
2 parents 4229d23 + 7a81c06 commit f5a3256

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

.github/workflows/scripts/pr_workflow.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66

77
from github.PullRequest import PullRequest
88
from github.Repository import Repository
9-
from github.PaginatedList import PaginatedList
109
from github.MainClass import Github
1110
from github.GithubException import UnknownObjectException
1211
from github.Organization import Organization
1312
from github.Team import Team
14-
from github.NamedUser import NamedUser
1513

1614
from 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

Comments
 (0)