Reviewed-on: #4 Co-authored-by: Andrew Kettel <andrew.kettel@gmail.com> Co-committed-by: Andrew Kettel <andrew.kettel@gmail.com>
53 lines
1.4 KiB
Bash
Executable File
53 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
BRANCH="dependency-updates-$(date +%Y%m%d)"
|
|
SUMMARY_FILE="/tmp/update_summary.md"
|
|
|
|
git config user.email "ci@gitea.com"
|
|
git config user.name "Gitea CI"
|
|
|
|
git checkout -b "$BRANCH"
|
|
git add pyproject.toml poetry.lock
|
|
git commit -m "chore: update dependencies $(date +%Y-%m-%d)"
|
|
git push "https://oauth2:${CI_TOKEN}@${CI_SERVER_URL#https://}/${REPO}.git" "$BRANCH"
|
|
|
|
# build the entire JSON payload in Python to avoid shell escaping issues
|
|
PAYLOAD=$(python3 - <<EOF
|
|
import json, sys
|
|
|
|
with open("${SUMMARY_FILE}") as f:
|
|
description = f.read()
|
|
|
|
payload = {
|
|
"head": "${BRANCH}",
|
|
"base": "main",
|
|
"title": "chore: dependency updates $(date +%Y-%m-%d)",
|
|
"body": description,
|
|
"assignees": [${ASSIGNEE_ID}],
|
|
}
|
|
|
|
print(json.dumps(payload))
|
|
EOF
|
|
)
|
|
|
|
HTTP_RESPONSE=$(curl --silent --show-error \
|
|
--write-out "HTTPSTATUS:%{http_code}" \
|
|
--request POST \
|
|
--header "Authorization: token ${CI_TOKEN}" \
|
|
--header "Content-Type: application/json" \
|
|
--data "$PAYLOAD" \
|
|
"${CI_SERVER_URL}/api/v1/repos/${REPO}/pulls")
|
|
|
|
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS:.*//g')
|
|
HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
|
|
|
|
echo "API response status: $HTTP_STATUS"
|
|
echo "API response body: $HTTP_BODY"
|
|
|
|
if [ "$HTTP_STATUS" -ne 201 ]; then
|
|
echo "Failed to create pull request"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Pull request created for branch: $BRANCH" |