Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/dependabot-on-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Recreate Dependabot PR on develop

on:
pull_request:
types: [opened]
branches:
- main

jobs:
rebase-dependabot-to-develop:
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Fetch full history and all branches
run: git fetch --unshallow --all

- name: Create a new branch from develop with dependabot changes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ORIGINAL_BRANCH="${{ github.event.pull_request.head.ref }}"
NEW_BRANCH="dependabot-develop-${ORIGINAL_BRANCH}"

# Create new branch based on develop
git checkout origin/develop -b $NEW_BRANCH

# Get last commit message from original Dependabot branch
LAST_COMMIT_MSG=$(git log -1 --pretty=%B origin/$ORIGINAL_BRANCH)

# Merge Dependabot changes into the new branch
git merge --no-commit origin/$ORIGINAL_BRANCH || true
git commit -m "$LAST_COMMIT_MSG"
git push origin $NEW_BRANCH

# Create new pull request against develop
gh pr create \
--base develop \
--head $NEW_BRANCH \
--title "${{ github.event.pull_request.title }} (rebased onto develop)" \
--body "This is an automated copy of #${{ github.event.pull_request.number }}, targeting \`develop\` instead of \`main\`."

# Close the original PR
gh pr close ${{ github.event.pull_request.number }} --comment "Automatically closed: a new PR has been created against \`develop\`."

# Delete the original Dependabot branch
gh api \
-X DELETE \
repos/${{ github.repository }}/git/refs/heads/$ORIGINAL_BRANCH