|
|
|
|
|
|
|
|
| name: Merge main into PRs
|
|
|
| on:
|
| workflow_dispatch:
|
|
|
|
|
|
|
|
|
| jobs:
|
| Merge:
|
| if: github.repository == 'ultralytics/ultralytics'
|
| runs-on: ubuntu-latest
|
| steps:
|
| - name: Checkout repository
|
| uses: actions/checkout@v4
|
| with:
|
| fetch-depth: 0
|
| - uses: actions/setup-python@v5
|
| with:
|
| python-version: "3.x"
|
| cache: "pip"
|
| - name: Install requirements
|
| run: |
|
| pip install pygithub
|
| - name: Merge default branch into PRs
|
| shell: python
|
| run: |
|
| from github import Github
|
| import os
|
| import time
|
|
|
| g = Github("${{ secrets.PERSONAL_ACCESS_TOKEN }}")
|
| repo = g.get_repo("${{ github.repository }}")
|
|
|
|
|
| default_branch_name = repo.default_branch
|
| default_branch = repo.get_branch(default_branch_name)
|
|
|
|
|
| updated_branches = 0
|
| up_to_date_branches = 0
|
| errors = 0
|
|
|
| for pr in repo.get_pulls(state='open', sort='created'):
|
| try:
|
|
|
| reactions = pr.as_issue().get_reactions()
|
| if sum([(1 if r.content not in {"-1", "confused"} else 0) for r in reactions]) > 5:
|
| pr.set_labels(*("popular",) + tuple(l.name for l in pr.get_labels()))
|
|
|
|
|
| base_repo_name = repo.full_name
|
| head_repo_name = pr.head.repo.full_name
|
| base_branch_name = pr.base.ref
|
| head_branch_name = pr.head.ref
|
|
|
|
|
| comparison = repo.compare(default_branch.commit.sha, pr.head.sha)
|
| if comparison.behind_by > 0:
|
| print(f"β οΈ PR
|
|
|
|
|
| try:
|
| success = pr.update_branch()
|
| assert success, "Branch update failed"
|
| print(f"β
Successfully merged '{default_branch_name}' into PR
|
| updated_branches += 1
|
| time.sleep(10)
|
| except Exception as update_error:
|
| print(f"β Could not update PR
|
| errors += 1
|
| else:
|
| print(f"β
PR
|
| up_to_date_branches += 1
|
| except Exception as e:
|
| print(f"β Could not process PR
|
| errors += 1
|
|
|
|
|
| print("\n\nSummary:")
|
| print(f"Branches updated: {updated_branches}")
|
| print(f"Branches already up-to-date: {up_to_date_branches}")
|
| print(f"Total errors: {errors}")
|
| |