gitea port
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
name: Open a PR to main
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
pull-request:
|
||||
name: Open pull request
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Open pull request
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_URL: ${{ gitea.server_url }}
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
SOURCE_BRANCH: ${{ gitea.ref_name }}
|
||||
TARGET_BRANCH: main
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
api_url="${GITEA_URL%/}/api/v1"
|
||||
auth_header="Authorization: token ${GITEA_TOKEN}"
|
||||
|
||||
open_pulls="$(
|
||||
curl --fail-with-body --silent --show-error \
|
||||
--get \
|
||||
--header "$auth_header" \
|
||||
--data-urlencode "state=open" \
|
||||
--data-urlencode "base_branch=${TARGET_BRANCH}" \
|
||||
--data-urlencode "limit=50" \
|
||||
"${api_url}/repos/${GITEA_REPOSITORY}/pulls"
|
||||
)"
|
||||
if jq -e --arg branch "$SOURCE_BRANCH" \
|
||||
'any(.[]; .head.ref == $branch)' <<<"$open_pulls" >/dev/null; then
|
||||
echo "Pull request already exists."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
commits="$(git rev-list --count "origin/${TARGET_BRANCH}..HEAD")"
|
||||
if [[ "$commits" -eq 0 ]]; then
|
||||
echo "No commits between ${TARGET_BRANCH} and ${SOURCE_BRANCH}. Skipping pull request creation."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
payload="$(
|
||||
jq -n \
|
||||
--arg base "$TARGET_BRANCH" \
|
||||
--arg head "$SOURCE_BRANCH" \
|
||||
--arg title 'chore: Merge branch `dev` to `main`' \
|
||||
--arg body 'When dev (pre-release) is ready, merge this pull request to create a new stable release.' \
|
||||
'{base: $base, head: $head, title: $title, body: $body}'
|
||||
)"
|
||||
|
||||
curl --fail-with-body --silent --show-error \
|
||||
--request POST \
|
||||
--header "$auth_header" \
|
||||
--header "Content-Type: application/json" \
|
||||
--data "$payload" \
|
||||
"${api_url}/repos/${GITEA_REPOSITORY}/pulls" >/dev/null
|
||||
echo "Pull request created."
|
||||
Reference in New Issue
Block a user