Translated README (readmeai_auto) #19
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
name: Rebase Pull Request | |
on: | |
issue_comment: | |
types: | |
- created | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
rebase: | |
name: Rebase | |
if: > | |
github.event.issue.pull_request != null && | |
( | |
contains(github.event.comment.body, '/rebase') || | |
contains(github.event.comment.body, '/Rebase') | |
) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
persist-credentials: false | |
- name: Configure Git | |
run: | | |
git config --global user.name 'GitHub Action' | |
git config --global user.email '[email protected]' | |
- name: Fetch pull request branch | |
env: | |
PR_NUMBER: ${{ github.event.issue.number }} | |
run: | | |
git fetch origin pull/${PR_NUMBER}/head:pr-${PR_NUMBER} | |
git checkout pr-${PR_NUMBER} | |
- name: Rebase branch | |
id: rebase | |
env: | |
PR_NUMBER: ${{ github.event.issue.number }} | |
run: | | |
git fetch origin main | |
git rebase origin/main || echo "status=failure" >> $GITHUB_OUTPUT | |
echo "status=success" >> $GITHUB_OUTPUT || true | |
- name: Push changes | |
if: steps.rebase.outputs.status == 'success' | |
env: | |
PR_NUMBER: ${{ github.event.issue.number }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | |
git push "$remote_repo" HEAD:pr-${PR_NUMBER} -f | |
- name: Comment on successful rebase | |
if: steps.rebase.outputs.status == 'success' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '✅ Pull Request successfully rebased on main branch.' | |
}) | |
- name: Comment on unsuccessful rebase | |
if: always() && steps.rebase.outputs.status != 'success' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '⚠️ Rebase failed. Please resolve conflicts manually.' | |
}) |