Compare commits

..

1 Commits

Author SHA1 Message Date
cab4f933d2 feat: add pr-comment step to post CI results on pull requests
All checks were successful
ci/woodpecker/pr/pipeline Pipeline was successful
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.
2026-05-12 09:00:37 +03:00
2 changed files with 49 additions and 18 deletions

View File

@@ -126,14 +126,13 @@ steps:
UV_PYTHON: "3.13"
GITEA_API_TOKEN:
from_secret: gitea_api_token
depends_on: [coverage, lint, type]
depends_on: [coverage]
when:
event: [pull_request]
commands:
- pip install uv
- |
SHA7=$(printf '%.7s' "${CI_COMMIT_SHA:-unknown}")
COMMIT_URL="${CI_FORGE_URL}/${CI_REPO_OWNER}/${CI_REPO_NAME}/commit/${CI_COMMIT_SHA}"
SOURCE="${CI_COMMIT_SOURCE:-${CI_COMMIT_SOURCE_BRANCH:-?}}"
TARGET="${CI_COMMIT_TARGET:-${CI_COMMIT_TARGET_BRANCH:-?}}"
PIPELINE_URL="${CI_PIPELINE_URL:-}"
@@ -142,6 +141,6 @@ steps:
echo "pr-comment: GITEA_API_TOKEN not set, skipping"
exit 0
fi
FMT='{"body": "## CI Summary\n\n**Commit:** [`%s`](%s)\n**Branch:** `%s` → `%s`\n**Pipeline:** [View](%s)\n\n### Checks\n\n| Check | Status |\n|-------|--------|\n| Lint (ruff + isort) | ✅ |\n| Type check (mypy) | ✅ |\n| Unit tests | ✅ |\n| Integration tests | ✅ |\n| E2E tests | ✅ |\n| Coverage | **%s** |\n\n---\n*Reported by Woodpecker CI*"}'
BODY=$(printf "$FMT" "$SHA7" "$COMMIT_URL" "$SOURCE" "$TARGET" "$PIPELINE_URL" "$COVER")
FMT='{"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*"}'
BODY=$(printf "$FMT" "$SHA7" "$SOURCE" "$TARGET" "$COVER" "$PIPELINE_URL")
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 "$BODY"

View File

@@ -7,7 +7,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from pytfm.web import BasePage
from pytfm.web import BasePage, SmartLocator
if TYPE_CHECKING:
from playwright.sync_api import Page
@@ -22,9 +22,21 @@ class HomePage(BasePage):
path = "/web/"
def __init__(self, page: Page, base_url: str) -> None:
"""Initialize the home page object.
Args:
page: Playwright Page instance.
base_url: Application base URL.
"""
super().__init__(page, base_url)
self._create_post_btn = SmartLocator.by_testid("btn-create-post-header")
self._post_list = SmartLocator.by_testid("post-list")
self._empty_state = SmartLocator.by_testid("empty-state")
def create_post(self) -> None:
"""Click the 'Write a Post' button to navigate to the form."""
self.loc("btn-create-post-header").click()
self._create_post_btn.click(self.page)
def has_post_with_title(self, title: str) -> bool:
"""Check if a post with the given title is present in the list.
@@ -67,7 +79,7 @@ class HomePage(BasePage):
Returns:
True if the empty state is visible.
"""
return self.loc("empty-state")._get_locator().is_visible()
return self._empty_state.is_visible(self.page)
def count_posts(self) -> int:
"""Count the number of post cards on the page.
@@ -126,6 +138,20 @@ class PostFormPage(BasePage):
path = "/web/posts/new"
def __init__(self, page: Page, base_url: str) -> None:
"""Initialize the post form page object.
Args:
page: Playwright Page instance.
base_url: Application base URL.
"""
super().__init__(page, base_url)
self._title_input = SmartLocator.by_testid("input-title")
self._content_input = SmartLocator.by_testid("textarea-content")
self._tags_input = SmartLocator.by_testid("input-tags")
self._publish_btn = SmartLocator.by_testid("btn-publish-post")
self._save_draft_btn = SmartLocator.by_testid("btn-save-draft")
def fill_form(self, title: str, content: str, tags: str) -> None:
"""Fill the post creation form.
@@ -134,8 +160,8 @@ class PostFormPage(BasePage):
content: Post content (markdown).
tags: Comma-separated tags string.
"""
self.loc("input-title").fill(title)
self.loc("input-tags").fill(tags)
self._title_input.fill(self.page, title)
self._tags_input.fill(self.page, tags)
self.page.evaluate(
"(content) => {"
@@ -151,11 +177,11 @@ class PostFormPage(BasePage):
def publish(self) -> None:
"""Click the publish button to submit the form."""
self.loc("btn-publish-post").click()
self._publish_btn.click(self.page)
def save_draft(self) -> None:
"""Click the 'Save as Draft' button."""
self.loc("btn-save-draft").click()
self._save_draft_btn.click(self.page)
class PostDetailPage(BasePage):
@@ -177,6 +203,12 @@ class PostDetailPage(BasePage):
"""
super().__init__(page, base_url)
self.slug = slug
self._title = SmartLocator.by_testid("post-detail-title")
self._status = SmartLocator.by_testid("post-detail-status")
self._content = SmartLocator.by_testid("post-detail-content")
self._edit_btn = SmartLocator.by_testid("btn-edit-post")
self._delete_btn = SmartLocator.by_testid("btn-delete-post")
self._like_button = SmartLocator.by_testid("like-button")
@property
def url(self) -> str:
@@ -202,7 +234,7 @@ class PostDetailPage(BasePage):
Returns:
Post title string.
"""
return self.loc("post-detail-title").text_content() or ""
return self._title.get_text(self.page)
def get_status(self) -> str:
"""Get the post status badge text.
@@ -210,7 +242,7 @@ class PostDetailPage(BasePage):
Returns:
Status text ('Published' or 'Draft').
"""
return self.loc("post-detail-status").text_content() or ""
return self._status.get_text(self.page)
def is_published(self) -> bool:
"""Check if the post status is 'Published'.
@@ -222,7 +254,7 @@ class PostDetailPage(BasePage):
def edit(self) -> None:
"""Click the edit button to navigate to the edit form."""
self.loc("btn-edit-post").click()
self._edit_btn.click(self.page)
def can_edit(self) -> bool:
"""Check if the edit button is visible.
@@ -230,7 +262,7 @@ class PostDetailPage(BasePage):
Returns:
True if edit button is present.
"""
return self.loc("btn-edit-post")._get_locator().is_visible()
return self._edit_btn.is_visible(self.page)
def can_delete(self) -> bool:
"""Check if the delete button is visible.
@@ -238,12 +270,12 @@ class PostDetailPage(BasePage):
Returns:
True if delete button is present.
"""
return self.loc("btn-delete-post")._get_locator().is_visible()
return self._delete_btn.is_visible(self.page)
def delete(self) -> None:
"""Click the delete button and accept the confirmation dialog."""
self.page.on("dialog", lambda dialog: dialog.accept())
self.loc("btn-delete-post").click()
self._delete_btn.click(self.page)
def get_like_count(self) -> int:
"""Get the current like count from the detail page.
@@ -256,4 +288,4 @@ class PostDetailPage(BasePage):
def click_like(self) -> None:
"""Click the like/unlike button to toggle the like state."""
self.loc("like-button").click()
self._like_button.click(self.page)