Created
July 3, 2023 20:41
-
-
Save steebchen/fc9bcf5c94fcf934503822a44f56d11f to your computer and use it in GitHub Desktop.
auto PR
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: auto pull request | |
on: | |
push: | |
branches: | |
- wip/* | |
- feat/* | |
- fix/* | |
- ci/* | |
- refactor/* | |
- chore/* | |
- docs/* | |
- revert/* | |
jobs: | |
create-pull-request: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create Pull Request | |
uses: actions/github-script@v6 | |
if: github.actor == 'steebchen' | |
with: | |
github-token: ${{ secrets.AUTO_PR_GITHUB_TOKEN }} | |
script: | | |
const { repo, owner } = context.repo; | |
const existing = await github.rest.pulls.list({ | |
owner, | |
repo, | |
}); | |
const pr = existing.data.find(pull => pull.head.ref === '${{ github.ref_name }}') | |
if (pr) { | |
console.log('pull request already exists, updating', pr); | |
await github.rest.pulls.update({ | |
pull_number: pr.number, | |
owner, | |
repo, | |
title: '${{ github.event.head_commit.message }}', | |
}) | |
console.log('done'); | |
return; | |
} | |
const result = await github.rest.pulls.create({ | |
title: '${{ github.event.head_commit.message }}', | |
owner, | |
repo, | |
head: '${{ github.ref_name }}', | |
base: 'main', | |
}); | |
github.rest.issues.addLabels({ | |
owner, | |
repo, | |
issue_number: result.data.number, | |
labels: ['automated'] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment