Skip to content

Commit fe75796

Browse files
authored
Merge pull request hastagAB#363 from gaurovgiri/feat/github-review-bot
add github review comment automating script
2 parents 34ef01a + 8a6dabb commit fe75796

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

Github-Review-Bot/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# GitHub Pull Request Review Script
2+
3+
This Python script allows you to automatically review all pull requests in a specified GitHub repository.
4+
5+
## Prerequisites
6+
7+
Before you can use this script, ensure you have the following:
8+
9+
- Python installed on your system.
10+
- The `selenium` Python package. You can install it using `pip`:
11+
12+
```
13+
pip install selenium
14+
```
15+
16+
- [GeckoDriver](https://github.com/mozilla/geckodriver) for Firefox. Make sure to download the correct version for your system. Or you can replace `FireFox()` with your own webdriver
17+
18+
- A GitHub account with the necessary access rights to review pull requests in the target repository.
19+
20+
## Usage
21+
22+
1. Clone or download this repository to your local machine.
23+
24+
2. Open the script `github_pull_request_review.py` in a text editor or Python IDE.
25+
26+
3. Run the script by executing:
27+
28+
```bash
29+
python main.py
30+
```
31+
4. Answer the prompt
32+
33+
5. The script will start add review comments.

Github-Review-Bot/main.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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()

Github-Review-Bot/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
selenium

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ So far, the following projects have been integrated to this repo:
7575
|[Frammed text generator](FramedText) | [jcdwalle](https://github.com/jcdwalle)|
7676
|[Get Time By TimeZone](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Get_Time_TimezoneWise)|[Parth Shah](https://github.com/codingis4noobs) |
7777
|[git_automation](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/git_automation)| [loge1998](https://github.com/loge1998)|
78-
|[Github repo creator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Git_repo_creator)|[Harish Tiwari ](https://github.com/optimist2309)|
78+
|[Github repo creator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Git_repo_creator)|[Harish Tiwari ](https://github.com/optimist2309)|
79+
|[Github Review Bot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Github-Review-Bot)|[Gaurav Giri](https://github.com/gaurovgiri)|
7980
|[GithubBot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Github_Bot)|[Abhilasha](https://github.com/Abhilasha06)|
8081
|[Gmail Mailing Script](mailing) |[mayank-kapur](https://github.com/kapurm17) |
8182
|[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)|

0 commit comments

Comments
 (0)