name: Auto Create PR on: push: branches-ignore: - main jobs: create-pr: # Same act_runner label as deploy.yml (config: labels: ["cohaise:host"]). runs-on: cohaise permissions: contents: read pull-requests: write steps: - name: Create Pull Request env: # Built-in job token: no secret or personal token to configure. TOKEN: ${{ github.token }} API_URL: ${{ github.api_url }} REPO: ${{ github.repository }} BRANCH: ${{ github.ref_name }} MESSAGE: ${{ github.event.head_commit.message }} run: | set -eu TITLE=$(printf '%s' "$MESSAGE" | head -n 1) TITLE=${TITLE:-"Update $BRANCH"} TITLE=$(printf '%s' "$TITLE" | sed 's/\\/\\\\/g; s/"/\\"/g') STATUS=$(curl -sS -o /tmp/pr.json -w '%{http_code}' \ -X POST \ -H "Authorization: token ${TOKEN}" \ -H 'Content-Type: application/json' \ --data "{\"head\":\"${BRANCH}\",\"base\":\"main\",\"title\":\"${TITLE}\",\"body\":\"Automated PR from ${BRANCH} to main.\"}" \ "${API_URL}/repos/${REPO}/pulls") case "$STATUS" in 201) echo "Pull request created." ;; 409) echo "Pull request already exists." ;; 422) echo "Nothing to open a pull request for." ;; *) cat /tmp/pr.json exit 1 ;; esac