@@ -76,13 +76,32 @@ def _post_comment(self, message: str) -> RequestResponse:
7676 endpoint = f"issues/{ self .pr_num } /comments"
7777 return self .api .post (endpoint , {"body" : message })
7878
79- def _fetch_and_validate_lgtm_votes (self ):
79+ def _fetch_and_validate_lgtm_votes (self ) -> Tuple [ int , Dict [ str , Optional [ str ]]] :
8080 """
8181 Fetches LGTM votes and validates them.
8282
8383 Returns the number of valid votes and a dictionary of users with their
8484 permissions.
8585 """
86+ reviews_endpoint = f"pulls/{ self .pr_num } /reviews"
87+ reviews_response = self .api .get (reviews_endpoint )
88+ if reviews_response .status_code != 200 :
89+ error_message = COMMENTS_FETCH_ERROR .format (
90+ status_code = reviews_response .status_code ,
91+ response_text = reviews_response .text ,
92+ pr_num = self .pr_num ,
93+ )
94+ print (error_message , file = sys .stderr )
95+ sys .exit (1 )
96+
97+ lgtm_users : Dict [str , Optional [str ]] = {}
98+ reviews = reviews_response .json ()
99+ for review in reviews :
100+ if review ["state" ].lower () == "approved" :
101+ user = review ["user" ]["login" ]
102+ if user != self .pr_sender : # Skip self-approvals
103+ lgtm_users [user ] = None
104+
86105 endpoint = f"issues/{ self .pr_num } /comments"
87106 response = self .api .get (endpoint )
88107 if response .status_code != 200 :
@@ -93,9 +112,7 @@ def _fetch_and_validate_lgtm_votes(self):
93112 )
94113 print (error_message , file = sys .stderr )
95114 sys .exit (1 )
96-
97115 comments = response .json ()
98- lgtm_users : Dict [str , Optional [str ]] = {}
99116 for comment in comments :
100117 body = comment .get ("body" , "" )
101118 if re .search (r"^/lgtm\b" , body , re .IGNORECASE ):
@@ -331,40 +348,11 @@ def rebase(self) -> RequestResponse:
331348 def lgtm (self , send_comment : bool = True ) -> int :
332349 """
333350 Processes LGTM votes and approves the PR if the threshold is met.
334- """
335- endpoint = f"issues/{ self .pr_num } /comments"
336- response = self .api .get (endpoint )
337- if response .status_code != 200 :
338- error_message = COMMENTS_FETCH_ERROR .format (
339- status_code = response .status_code ,
340- response_text = response .text ,
341- pr_num = self .pr_num ,
342- )
343- print (error_message , file = sys .stderr )
344- sys .exit (1 )
345-
346- comments = response .json ()
347- lgtm_users : Dict [str , Optional [str ]] = {}
348- for comment in comments :
349- body = comment .get ("body" , "" )
350- if re .search (r"^/lgtm\b" , body , re .IGNORECASE ):
351- user = comment ["user" ]["login" ]
352- if user == self .pr_sender :
353- msg = SELF_APPROVAL_ERROR .format (
354- user = user , comment_url = comment ["html_url" ]
355- )
356- self ._post_comment (msg )
357- print (msg , file = sys .stderr )
358- sys .exit (1 )
359- lgtm_users [user ] = None
360-
361- valid_votes = 0
362- for user in lgtm_users :
363- permission , is_valid = self ._check_membership (user )
364- lgtm_users [user ] = permission
365- if is_valid :
366- valid_votes += 1
367351
352+ Includes both comment-based LGTM and direct PR approvals.
353+ """
354+ # First check direct PR approvals
355+ valid_votes , lgtm_users = self ._fetch_and_validate_lgtm_votes ()
368356 if valid_votes >= self .lgtm_threshold :
369357 users_table = ""
370358 for user , permission in lgtm_users .items ():
@@ -431,7 +419,6 @@ def merge_pr(self) -> bool:
431419
432420 # Fetch LGTM votes and check if the threshold is met
433421 valid_votes , lgtm_users = self ._fetch_and_validate_lgtm_votes ()
434-
435422 if valid_votes >= self .lgtm_threshold :
436423 endpoint = f"pulls/{ self .pr_num } /merge"
437424 data = {
0 commit comments