mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Merge pull request #363 from gaurovgiri/feat/github-review-bot
add github review comment automating script
This commit is contained in:
commit
fe7579693d
33
Github-Review-Bot/README.md
Normal file
33
Github-Review-Bot/README.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
# GitHub Pull Request Review Script
|
||||
|
||||
This Python script allows you to automatically review all pull requests in a specified GitHub repository.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before you can use this script, ensure you have the following:
|
||||
|
||||
- Python installed on your system.
|
||||
- The `selenium` Python package. You can install it using `pip`:
|
||||
|
||||
```
|
||||
pip install selenium
|
||||
```
|
||||
|
||||
- [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
|
||||
|
||||
- A GitHub account with the necessary access rights to review pull requests in the target repository.
|
||||
|
||||
## Usage
|
||||
|
||||
1. Clone or download this repository to your local machine.
|
||||
|
||||
2. Open the script `github_pull_request_review.py` in a text editor or Python IDE.
|
||||
|
||||
3. Run the script by executing:
|
||||
|
||||
```bash
|
||||
python main.py
|
||||
```
|
||||
4. Answer the prompt
|
||||
|
||||
5. The script will start add review comments.
|
57
Github-Review-Bot/main.py
Normal file
57
Github-Review-Bot/main.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
# Python Script to review all the pull request of mentioned repository
|
||||
|
||||
from selenium.webdriver import Firefox, ActionChains
|
||||
from selenium.webdriver.common.by import By
|
||||
import random
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
|
||||
username = None
|
||||
password = None
|
||||
|
||||
class Github:
|
||||
|
||||
def __init__(self, repo_owner, repo_name):
|
||||
self.base_url = "https://github.com/"
|
||||
self.repo_owner = repo_owner
|
||||
self.repo_name = repo_name
|
||||
self.isLogin = False
|
||||
self.driver = Firefox()
|
||||
self.pull_requests = None
|
||||
|
||||
def login(self):
|
||||
self.driver.get(self.base_url+"/login")
|
||||
self.driver.find_element(by=By.ID, value="login_field").send_keys(username)
|
||||
self.driver.find_element(by=By.ID, value="password").send_keys(password)
|
||||
self.driver.find_element(by=By.NAME, value="commit").click()
|
||||
self.isLogin = True
|
||||
|
||||
def writeReview(self):
|
||||
if not self.isLogin:
|
||||
self.login()
|
||||
|
||||
self.driver.get(self.base_url+self.repo_owner+"/"+self.repo_name+"/pulls")
|
||||
self.driver.implicitly_wait(10)
|
||||
pull_requests = self.driver.find_elements(by=By.XPATH, value="//a[@data-hovercard-type='pull_request']")
|
||||
self.pull_requests = [pull_request.get_attribute("href") for pull_request in pull_requests]
|
||||
|
||||
for pull_request in self.pull_requests:
|
||||
self.driver.get(pull_request+"/files")
|
||||
self.driver.implicitly_wait(10)
|
||||
self.driver.find_element(by=By.ID, value="review-changes-modal").click()
|
||||
self.driver.implicitly_wait(10)
|
||||
self.driver.find_element(by=By.ID, value="pull_request_review[event]_approve").click()
|
||||
self.driver.implicitly_wait(10)
|
||||
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!"]))
|
||||
self.driver.implicitly_wait(10)
|
||||
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys(Keys.ENTER).key_up(Keys.CONTROL).perform()
|
||||
self.driver.implicitly_wait(10)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
username = input("Enter your username: ")
|
||||
password = input("Enter your password: ")
|
||||
|
||||
github_owner = input("Enter the repository owner: ")
|
||||
github_repo = input("Enter the repository name: ")
|
||||
github = Github(github_owner, github_repo)
|
||||
github.writeReview()
|
1
Github-Review-Bot/requirements.txt
Normal file
1
Github-Review-Bot/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
selenium
|
|
@ -75,7 +75,8 @@ So far, the following projects have been integrated to this repo:
|
|||
|[Frammed text generator](FramedText) | [jcdwalle](https://github.com/jcdwalle)|
|
||||
|[Get Time By TimeZone](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Get_Time_TimezoneWise)|[Parth Shah](https://github.com/codingis4noobs) |
|
||||
|[git_automation](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/git_automation)| [loge1998](https://github.com/loge1998)|
|
||||
|[Github repo creator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Git_repo_creator)|[Harish Tiwari ](https://github.com/optimist2309)|
|
||||
|[Github repo creator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Git_repo_creator)|[Harish Tiwari ](https://github.com/optimist2309)|
|
||||
|[Github Review Bot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Github-Review-Bot)|[Gaurav Giri](https://github.com/gaurovgiri)|
|
||||
|[GithubBot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Github_Bot)|[Abhilasha](https://github.com/Abhilasha06)|
|
||||
|[Gmail Mailing Script](mailing) |[mayank-kapur](https://github.com/kapurm17) |
|
||||
|[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)|
|
||||
|
|
Loading…
Reference in New Issue
Block a user