feat: add pr-comment step to post CI results on pull requests
Some checks failed
ci/woodpecker/pr/pipeline Pipeline failed
Some checks failed
ci/woodpecker/pr/pipeline Pipeline failed
Posts a formatted markdown comment with coverage percentage, commit SHA, branch info, and pipeline link to the Gitea PR via API. Uses GITEA_API_TOKEN secret from Woodpecker for authentication.
This commit is contained in:
@@ -115,3 +115,33 @@ steps:
|
||||
- uv run --no-sync coverage combine .coverage.unit .coverage.integration
|
||||
- uv run --no-sync coverage report --fail-under=70 --include=app/*
|
||||
- uv run --no-sync coverage html
|
||||
|
||||
- name: pr-comment
|
||||
image: python:3.13
|
||||
volumes:
|
||||
- /tmp/uv-cache:/root/.cache/uv
|
||||
environment:
|
||||
UV_CACHE_DIR: /root/.cache/uv
|
||||
UV_LINK_MODE: copy
|
||||
UV_PYTHON: "3.13"
|
||||
GITEA_API_TOKEN:
|
||||
from_secret: gitea_api_token
|
||||
depends_on: [coverage]
|
||||
when:
|
||||
event: [pull_request]
|
||||
commands:
|
||||
- pip install uv
|
||||
- |
|
||||
SHA="${CI_COMMIT_SHA:-unknown}"
|
||||
SHA7="${SHA:0:7}"
|
||||
SOURCE="${CI_COMMIT_SOURCE:-?}"
|
||||
TARGET="${CI_COMMIT_TARGET:-?}"
|
||||
PIPELINE_URL="${CI_PIPELINE_URL:-}"
|
||||
COVER=$(uv run --no-sync coverage report --include='app/*' \
|
||||
| tail -1 | awk '{print $NF}')
|
||||
curl -s -X POST \
|
||||
"${CI_FORGE_URL}/api/v1/repos/${CI_REPO_OWNER}/${CI_REPO_NAME}/issues/${CI_COMMIT_PULL_REQUEST}/comments" \
|
||||
-H "Authorization: token ${GITEA_API_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary "$(printf '{"body": "## CI Results\n\n| Check | Result |\n|-------|--------|\n| Commit | `%s` |\n| Branch | %s → %s |\n| Coverage | **%s** |\n| Pipeline | [View](%s) |\n\n---\n*Reported by @cicd*" \
|
||||
"$SHA7" "$SOURCE" "$TARGET" "$COVER" "$PIPELINE_URL")"
|
||||
|
||||
Reference in New Issue
Block a user