-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from natan-dias/feature-new-auto-approve-script
add first version of auto approve script
- Loading branch information
Showing
3 changed files
with
57 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
name: Auto PR Review | ||
name: Auto Approve Pull Requests | ||
|
||
on: [pull_request] | ||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
|
||
jobs: | ||
test: | ||
auto-approve: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/[email protected] | ||
- uses: actions/setup-node@v3 | ||
- uses: omio-labs/pr-reviewer-bot@v1 | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install PyGithub | ||
- name: Auto Approve Pull Requests | ||
env: | ||
PULL_REQUEST_NUMBER: ${{ github.event.number }} | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
|
||
|
||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
GITHUB_REF: ${{ github.event.pull_request.head.ref }} | ||
run: | | ||
python scripts/python_auto_pr_approve.py |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
from github import Github | ||
|
||
# Get the Github token from the environment variable | ||
github_token = os.getenv('GH_TOKEN') | ||
|
||
# List of files to trigger auto-approval | ||
files_to_trigger_approval = ['README.md', 'file2.py'] | ||
|
||
# Login to Github using the token | ||
gh = Github(github_token) | ||
|
||
# Get the repository and pull request from the github context | ||
repository = gh.get_repo(os.getenv('GITHUB_REPOSITORY')) | ||
pull_request_number = int(os.getenv('PULL_REQUEST_NUMBER')) | ||
pull_request = repository.get_pull(int(pull_request_number)) | ||
|
||
#os.getenv('GITHUB_REF').split('/')[-1] | ||
#if pull_request_number != 'merge': | ||
# pull_request = repository.get_pull(int(pull_request_number)) | ||
#else: | ||
# print("Pull request not found") | ||
|
||
# Get the list of files changed in the pull request | ||
files_changed = [file.filename for file in pull_request.get_files()] | ||
|
||
# Check if any of the files to trigger auto-approval are changed | ||
if any(file in files_changed for file in files_to_trigger_approval): | ||
# Add the reviewer (you can add more reviewers if needed) | ||
pull_request.create_review_request(reviewers=['Python Auto Approver']) | ||
|
||
# Approve the pull request | ||
pull_request.create_review(body='Approved', event='APPROVE') |