1+ # Python Script to review all the pull request of mentioned repository
2+
3+ from selenium .webdriver import Firefox , ActionChains
4+ from selenium .webdriver .common .by import By
5+ import random
6+ from selenium .webdriver .common .keys import Keys
7+
8+ username = None
9+ password = None
10+
11+ class Github :
12+
13+ def __init__ (self , repo_owner , repo_name ):
14+ self .base_url = "https://github.com/"
15+ self .repo_owner = repo_owner
16+ self .repo_name = repo_name
17+ self .isLogin = False
18+ self .driver = Firefox ()
19+ self .pull_requests = None
20+
21+ def login (self ):
22+ self .driver .get (self .base_url + "/login" )
23+ self .driver .find_element (by = By .ID , value = "login_field" ).send_keys (username )
24+ self .driver .find_element (by = By .ID , value = "password" ).send_keys (password )
25+ self .driver .find_element (by = By .NAME , value = "commit" ).click ()
26+ self .isLogin = True
27+
28+ def writeReview (self ):
29+ if not self .isLogin :
30+ self .login ()
31+
32+ self .driver .get (self .base_url + self .repo_owner + "/" + self .repo_name + "/pulls" )
33+ self .driver .implicitly_wait (10 )
34+ pull_requests = self .driver .find_elements (by = By .XPATH , value = "//a[@data-hovercard-type='pull_request']" )
35+ self .pull_requests = [pull_request .get_attribute ("href" ) for pull_request in pull_requests ]
36+
37+ for pull_request in self .pull_requests :
38+ self .driver .get (pull_request + "/files" )
39+ self .driver .implicitly_wait (10 )
40+ self .driver .find_element (by = By .ID , value = "review-changes-modal" ).click ()
41+ self .driver .implicitly_wait (10 )
42+ self .driver .find_element (by = By .ID , value = "pull_request_review[event]_approve" ).click ()
43+ self .driver .implicitly_wait (10 )
44+ self .driver .find_element (by = By .ID , value = "pull_request_review_body" ).send_keys (random .choice (["LGTM" , "Looks good to me" , "LGTM, thanks for the contribution" , "Seems good to me!" ]))
45+ self .driver .implicitly_wait (10 )
46+ ActionChains (self .driver ).key_down (Keys .CONTROL ).send_keys (Keys .ENTER ).key_up (Keys .CONTROL ).perform ()
47+ self .driver .implicitly_wait (10 )
48+
49+
50+ if __name__ == "__main__" :
51+ username = input ("Enter your username: " )
52+ password = input ("Enter your password: " )
53+
54+ github_owner = input ("Enter the repository owner: " )
55+ github_repo = input ("Enter the repository name: " )
56+ github = Github (github_owner , github_repo )
57+ github .writeReview ()
0 commit comments