Skip to content

Commit

Permalink
Merge pull request #24 from natan-dias/feature-test-auto-approval
Browse files Browse the repository at this point in the history
test auto approval
  • Loading branch information
natan-dias authored Aug 12, 2024
2 parents 8bc320a + 14ba81a commit 1e240d4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pr-auto-approval.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Auto approve

on: pull_request_target

jobs:
auto-approve:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.actor == 'natan-dias'
steps:
- uses: hmarr/auto-approve-action@v4
with:
github-token: ${{ secrets.GH_TOKEN }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
## Devops Repo for testing

- Small test for auto PR review bot
- Second test with auto PR
- Second test with auto PR review
- Third test with auto PR review
30 changes: 24 additions & 6 deletions scripts/python_auto_pr_approve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
github_token = os.getenv('GH_TOKEN')

# List of files to trigger auto-approval
files_to_trigger_approval = ['README.md', 'file2.py']
files_to_trigger_approval = ['README.md', 'python_auto_pr_approve.py']

# Login to Github using the token
gh = Github(github_token)
Expand All @@ -15,6 +15,15 @@
pull_request_number = int(os.getenv('PULL_REQUEST_NUMBER'))
pull_request = repository.get_pull(int(pull_request_number))

# Get more information

print(f"Pull request: {pull_request.number} - {pull_request.title}")
print(f"Repository: {repository.name}")
print(f"Repository owner: {repository.owner.login}")
print(f"Pull request state: {pull_request.state}")
#print(f"Pull request merged: {pull_request.merged}")
#print(f"Pull request closed: {pull_request.closed}")

#os.getenv('GITHUB_REF').split('/')[-1]
#if pull_request_number != 'merge':
# pull_request = repository.get_pull(int(pull_request_number))
Expand All @@ -26,8 +35,17 @@

# 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')
# Get the reviewer
reviewer = 'natan-bot'
try:
# Check if the reviewer is a valid GitHub user
gh.get_user(reviewer)
print(f"Reviewer is valid: {reviewer}")
except Exception as e:
print(f"Error: {e}")
print("Reviewer is not a valid GitHub user")
else:
# Add the reviewer
pull_request.create_review_request(reviewers=[reviewer])
# Approve the pull request
pull_request.create_review(body='Approved', event='APPROVE')

0 comments on commit 1e240d4

Please sign in to comment.