Skip to content

Commit

Permalink
Merge pull request #23 from natan-dias/feature-new-auto-approve-script
Browse files Browse the repository at this point in the history
add first version of auto approve script
  • Loading branch information
natan-dias authored Aug 9, 2024
2 parents 8830f27 + 4e3b656 commit 8bc320a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 18 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/pr-review.yaml
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
10 changes: 0 additions & 10 deletions .pr-bot.yml

This file was deleted.

33 changes: 33 additions & 0 deletions scripts/python_auto_pr_approve.py
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')

0 comments on commit 8bc320a

Please sign in to comment.