Template
mirror of
https://github.com/MorpheApp/morphe-patches-template.git
synced 2026-11-30 23:09:34 +00:00
chore: Give feedback if open pull request action doesn't have permission to create a pull request
This commit is contained in:
1 parent
70fa48ca8c
commit
5615c932a9
1 file changed
+21
-10
@@ -10,9 +10,6 @@ permissions:
|
||||
pull-requests: write
|
||||
contents: read
|
||||
|
||||
env:
|
||||
MESSAGE: Merge branch `${{ github.head_ref || github.ref_name }}` to `main`
|
||||
|
||||
jobs:
|
||||
pull-request:
|
||||
name: Open pull request
|
||||
@@ -22,10 +19,24 @@ jobs:
|
||||
uses: actions/checkout@v7
|
||||
|
||||
- name: Open pull request
|
||||
uses: repo-sync/pull-request@v2
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
destination_branch: 'main'
|
||||
pr_title: 'chore: ${{ env.MESSAGE }}'
|
||||
pr_body: 'This pull request will ${{ env.MESSAGE }}.'
|
||||
pr_draft: true
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SOURCE_BRANCH: ${{ github.ref_name }}
|
||||
TARGET_BRANCH: main
|
||||
run: |
|
||||
# Check if PR already exists (base=main, head=dev)
|
||||
if gh pr list --base "$TARGET_BRANCH" --head "$SOURCE_BRANCH" --json number | jq -e '. | length > 0' >/dev/null; then
|
||||
echo "Pull request already exists."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Try to create the PR
|
||||
gh pr create \
|
||||
--base "$TARGET_BRANCH" \
|
||||
--head "$SOURCE_BRANCH" \
|
||||
--title 'chore: Merge branch `dev` to `main`' \
|
||||
--body "When dev (pre-release) is ready, then merge this pull request to create a new stable release." \
|
||||
|| {
|
||||
echo "::error::Pull request creation failed. Ensure 'Allow GitHub Actions to create and approve pull requests' is enabled in the repo Settings > Actions > General > Workflow permissions"
|
||||
exit 1
|
||||
}
|
||||
Reference in new issue
Block a user