Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "GitAuto"
version = "1.6.11"
version = "1.12.0"
requires-python = ">=3.14"
dependencies = [
"annotated-doc==0.0.4",
Expand Down
10 changes: 7 additions & 3 deletions services/github/comments/delete_comments_by_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from services.github.comments.filter_comments_by_identifiers import (
filter_comments_by_identifiers,
)
from services.github.comments.get_all_comments import get_all_comments
from services.github.comments.get_pr_comments import get_pr_comments
from utils.error.handle_exceptions import handle_exceptions


Expand All @@ -16,8 +16,12 @@ def delete_comments_by_identifiers(
identifiers: list[str],
):
"""Delete all comments containing the identifiers made by GitAuto"""
comments = get_all_comments(
owner=owner, repo=repo, pr_number=pr_number, token=token
comments = get_pr_comments(
owner=owner,
repo=repo,
pr_number=pr_number,
token=token,
exclude_self=False,
)
matching_comments = filter_comments_by_identifiers(comments, identifiers)
for comment in matching_comments:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from typing import Sequence

from config import GITHUB_APP_USER_NAME
from services.github.types.webhook.pr_comment import Comment
from utils.error.handle_exceptions import handle_exceptions


@handle_exceptions(default_return_value=[], raise_on_error=False)
def filter_comments_by_identifiers(comments: list[dict], identifiers: list[str]):
def filter_comments_by_identifiers(comments: Sequence[Comment], identifiers: list[str]):
"""Filter comments by identifier text(s) and made by GitAuto"""
comments = comments or []

Expand Down
15 changes: 0 additions & 15 deletions services/github/comments/get_all_comments.py

This file was deleted.

35 changes: 0 additions & 35 deletions services/github/comments/get_comments.py

This file was deleted.

32 changes: 32 additions & 0 deletions services/github/comments/get_pr_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import requests

from config import GITHUB_API_URL, GITHUB_APP_IDS, TIMEOUT
from services.github.types.webhook.pr_comment import Comment
from services.github.utils.create_headers import create_headers
from utils.error.handle_exceptions import handle_exceptions
from utils.logging.logging_config import logger


@handle_exceptions(default_return_value=[], raise_on_error=False)
def get_pr_comments(
*, owner: str, repo: str, pr_number: int, token: str, exclude_self: bool
):
"""https://docs.github.com/en/rest/issues/comments#list-issue-comments"""
url = f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues/{pr_number}/comments"
headers = create_headers(token=token)
response = requests.get(url=url, headers=headers, timeout=TIMEOUT)
response.raise_for_status()
comments: list[Comment] = response.json()
if exclude_self:
filtered: list[Comment] = []
for comment in comments:
app = comment.get("performed_via_github_app")
if app is None or app.get("id") not in GITHUB_APP_IDS:
filtered.append(comment)
logger.info(
"Filtered %d → %d PR comments (excluded self)", len(comments), len(filtered)
)
return filtered

logger.info("Returning all %d PR comments", len(comments))
return comments
32 changes: 18 additions & 14 deletions services/github/comments/test_delete_comments_by_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@


@pytest.fixture
def mock_get_all_comments():
def mock_get_pr_comments():
with patch(
"services.github.comments.delete_comments_by_identifiers.get_all_comments"
"services.github.comments.delete_comments_by_identifiers.get_pr_comments"
) as mock:
yield mock

Expand All @@ -37,7 +37,7 @@ def mock_delete_comment():


def test_delete_comments_by_identifiers_successful_deletion(
mock_get_all_comments,
mock_get_pr_comments,
mock_filter_comments_by_identifiers,
mock_delete_comment,
):
Expand All @@ -50,7 +50,7 @@ def test_delete_comments_by_identifiers_successful_deletion(
{"id": 1, "body": "Comment with id-1", "user": {"login": "gitauto-ai[bot]"}},
{"id": 2, "body": "Comment with id-2", "user": {"login": "gitauto-ai[bot]"}},
]
mock_get_all_comments.return_value = sample_comments
mock_get_pr_comments.return_value = sample_comments
mock_filter_comments_by_identifiers.return_value = sample_comments
mock_delete_comment.return_value = None

Expand All @@ -65,14 +65,18 @@ def test_delete_comments_by_identifiers_successful_deletion(
)

assert result is None
mock_get_all_comments.assert_called_once_with(
owner=owner, repo=repo, pr_number=pr_number, token=token
mock_get_pr_comments.assert_called_once_with(
owner=owner,
repo=repo,
pr_number=pr_number,
token=token,
exclude_self=False,
)
assert mock_delete_comment.call_count == 2


def test_delete_comments_by_identifiers_no_comments_found(
mock_get_all_comments,
mock_get_pr_comments,
mock_filter_comments_by_identifiers,
mock_delete_comment,
):
Expand All @@ -81,7 +85,7 @@ def test_delete_comments_by_identifiers_no_comments_found(
pr_number = fake.random_int(min=1, max=999)
token = fake.sha256()

mock_get_all_comments.return_value = []
mock_get_pr_comments.return_value = []
mock_filter_comments_by_identifiers.return_value = []

result = delete_comments_by_identifiers(
Expand All @@ -97,7 +101,7 @@ def test_delete_comments_by_identifiers_no_comments_found(


def test_delete_comments_by_identifiers_no_matching_comments(
mock_get_all_comments,
mock_get_pr_comments,
mock_filter_comments_by_identifiers,
mock_delete_comment,
):
Expand All @@ -109,7 +113,7 @@ def test_delete_comments_by_identifiers_no_matching_comments(
sample_comments = [
{"id": 1, "body": "Some comment", "user": {"login": "gitauto-ai[bot]"}}
]
mock_get_all_comments.return_value = sample_comments
mock_get_pr_comments.return_value = sample_comments
mock_filter_comments_by_identifiers.return_value = []

result = delete_comments_by_identifiers(
Expand All @@ -125,7 +129,7 @@ def test_delete_comments_by_identifiers_no_matching_comments(


def test_delete_comments_by_identifiers_exception_handling(
mock_get_all_comments,
mock_get_pr_comments,
mock_filter_comments_by_identifiers,
mock_delete_comment,
):
Expand All @@ -134,7 +138,7 @@ def test_delete_comments_by_identifiers_exception_handling(
pr_number = fake.random_int(min=1, max=999)
token = fake.sha256()

mock_get_all_comments.side_effect = Exception("API error")
mock_get_pr_comments.side_effect = Exception("API error")

result = delete_comments_by_identifiers(
owner=owner,
Expand All @@ -150,7 +154,7 @@ def test_delete_comments_by_identifiers_exception_handling(


def test_delete_comments_by_identifiers_delete_comment_exception(
mock_get_all_comments,
mock_get_pr_comments,
mock_filter_comments_by_identifiers,
mock_delete_comment,
):
Expand All @@ -162,7 +166,7 @@ def test_delete_comments_by_identifiers_delete_comment_exception(
matching_comments = [
{"id": 1, "body": "test", "user": {"login": "gitauto-ai[bot]"}}
]
mock_get_all_comments.return_value = matching_comments
mock_get_pr_comments.return_value = matching_comments
mock_filter_comments_by_identifiers.return_value = matching_comments
mock_delete_comment.side_effect = Exception("Delete failed")

Expand Down
12 changes: 12 additions & 0 deletions services/github/comments/test_filter_comments_by_identifiers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# pyright: reportArgumentType=false
import inspect
from unittest.mock import patch

from services.github.comments.filter_comments_by_identifiers import (
filter_comments_by_identifiers,
)
from services.github.types.webhook.pr_comment import Comment


def test_filter_comments_by_identifiers_empty_comments():
Expand Down Expand Up @@ -224,3 +227,12 @@ def test_filter_comments_by_identifiers_multiple_identifiers_single_comment():
result = filter_comments_by_identifiers(comments, ["first-id", "second-id"])
assert len(result) == 1
assert result[0]["id"] == 1


def test_filter_comments_by_identifiers_accepts_comment_type():
"""Verify function signature accepts list[Comment] type."""
sig = inspect.signature(filter_comments_by_identifiers)
params = sig.parameters
assert "comments" in params
assert "identifiers" in params
assert Comment is not None
112 changes: 0 additions & 112 deletions services/github/comments/test_get_comments.py

This file was deleted.

Loading