@@ -32,10 +32,12 @@ class SupportedActions:
3232 add_remove_labels_action_name : str = "add-remove-labels"
3333 pr_size_action_name : str = "add-pr-size-label"
3434 welcome_comment_action_name : str = "add-welcome-comment"
35+ build_push_pr_image_action_name : str = "push-container-on-comment"
3536 supported_actions : set [str ] = {
3637 pr_size_action_name ,
3738 add_remove_labels_action_name ,
3839 welcome_comment_action_name ,
40+ build_push_pr_image_action_name ,
3941 }
4042
4143 def __init__ (self ) -> None :
@@ -55,7 +57,7 @@ def __init__(self) -> None:
5557 def verify_base_config (self ) -> None :
5658 if not self .action or self .action not in self .SupportedActions .supported_actions :
5759 sys .exit (
58- "`ACTION` is not set in workflow or is not supported. "
60+ f" { self . action } is not set in workflow or is not supported. "
5961 f"Supported actions: { self .SupportedActions .supported_actions } "
6062 )
6163
@@ -77,8 +79,8 @@ def verify_base_config(self) -> None:
7779 )
7880
7981 def set_gh_config (self ) -> None :
80- gh_client : Github = Github (login_or_token = self .github_token )
81- self .repo = gh_client .get_repo (full_name_or_id = self .repo_name )
82+ self . gh_client : Github = Github (login_or_token = self .github_token )
83+ self .repo = self . gh_client .get_repo (full_name_or_id = self .repo_name )
8284 self .pr = self .repo .get_pull (number = self .pr_number )
8385
8486
@@ -88,9 +90,10 @@ def __init__(self) -> None:
8890 self .user_login = os .getenv ("GITHUB_USER_LOGIN" )
8991 self .review_state = os .getenv ("GITHUB_EVENT_REVIEW_STATE" )
9092 self .comment_body = os .getenv ("COMMENT_BODY" , "" )
93+ if self .event_name == "pull_request_review" :
94+ self .comment_body = os .getenv ("REVIEW_COMMENT_BODY" , "" )
9195 self .last_commit = list (self .pr .get_commits ())[- 1 ]
9296 self .last_commit_sha = self .last_commit .sha
93-
9497 self .verify_labeler_config ()
9598
9699 def verify_labeler_config (self ) -> None :
@@ -107,12 +110,31 @@ def verify_labeler_config(self) -> None:
107110 if self .event_name == "pull_request_review" and not self .review_state :
108111 sys .exit ("`GITHUB_EVENT_REVIEW_STATE` is not set" )
109112
113+ def verify_allowed_user (self ) -> bool :
114+ org = self .gh_client .get_organization ("opendatahub-io" )
115+ # slug is the team name with replaced special characters,
116+ # all words to lowercase and spaces replace with a -
117+ try :
118+ team = org .get_team_by_slug ("opendatahub-tests-contributors" )
119+ # check if the user is a member of opendatahub-tests-contributors
120+ membership = team .get_team_membership (member = self .user_login )
121+ LOGGER .info (f"User { self .user_login } is a member of the test contributor team. { membership } " )
122+ return True
123+ except UnknownObjectException :
124+ LOGGER .error (f"User { self .user_login } is not allowed for this action. Exiting." )
125+ return False
126+
110127 def run_pr_label_action (self ) -> None :
111128 if self .action == self .SupportedActions .pr_size_action_name :
112129 self .set_pr_size ()
113130
131+ if self .action == self .SupportedActions .build_push_pr_image_action_name :
132+ if not self .verify_allowed_user ():
133+ sys .exit (1 )
134+
114135 if self .action == self .SupportedActions .add_remove_labels_action_name :
115- self .add_remove_pr_labels ()
136+ if self .verify_allowed_user ():
137+ self .add_remove_pr_labels ()
116138
117139 if self .action == self .SupportedActions .welcome_comment_action_name :
118140 self .add_welcome_comment ()
0 commit comments