Skip to content

Commit

Permalink
Add conditional based on upload type (#452)
Browse files Browse the repository at this point in the history
* Add conditional based on upload type

* Adjust typing for additional data

* lint
  • Loading branch information
adrian-codecov authored Dec 12, 2024
1 parent 1c4ca00 commit b9d7171
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
7 changes: 7 additions & 0 deletions shared/reports/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from dataclasses import asdict, dataclass
from decimal import Decimal
from enum import Enum
from typing import Any, Dict, List, Optional, Sequence, Tuple, TypedDict, Union

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -252,3 +253,9 @@ def astuple(self):
None,
self.diff_totals,
)


class UploadType(Enum):
COVERAGE = "coverage"
TEST_RESULTS = "test_results"
BUNDLE_ANALYSIS = "bundle_analysis"
1 change: 1 addition & 0 deletions shared/torngit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(
"repo": {},
"fallback_installations": None,
"installation": None,
"additional_data": {},
}
self.verify_ssl = verify_ssl
self.data.update(kwargs)
Expand Down
46 changes: 25 additions & 21 deletions shared/torngit/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from shared.torngit.response_types import ProviderPull
from shared.torngit.status import Status
from shared.typings.oauth_token_types import OauthConsumerToken
from shared.typings.torngit import GithubInstallationInfo
from shared.typings.torngit import GithubInstallationInfo, UploadType
from shared.utils.urls import url_concat

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -611,26 +611,30 @@ async def build_comment_request_body(
self, body: dict, issueid: int | None = None
) -> dict:
body = dict(body=body)
try:
ownerid = self.data["owner"].get("ownerid")
if (
issueid is not None
and await INCLUDE_GITHUB_COMMENT_ACTIONS_BY_OWNER.check_value_async(
identifier=ownerid, default=False
)
):
bot_name = get_config(
"github", "comment_action_bot_name", default="sentry"
)
body["actions"] = [
{
"name": "Generate Unit Tests",
"type": "copilot-chat",
"prompt": f"@{bot_name} generate tests for this PR.",
}
]
except Exception:
pass
if (
self.data.get("additional_data", {}).get("upload_type")
!= UploadType.BUNDLE_ANALYSIS
):
try:
ownerid = self.data["owner"].get("ownerid")
if (
issueid is not None
and await INCLUDE_GITHUB_COMMENT_ACTIONS_BY_OWNER.check_value_async(
identifier=ownerid, default=False
)
):
bot_name = get_config(
"github", "comment_action_bot_name", default="sentry"
)
body["actions"] = [
{
"name": "Generate Unit Tests",
"type": "copilot-chat",
"prompt": f"@{bot_name} generate tests for this PR.",
}
]
except Exception:
pass

return body

Expand Down
9 changes: 8 additions & 1 deletion shared/typings/torngit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Dict, List, Optional, TypedDict, Union
from typing import Dict, List, NotRequired, Optional, TypedDict, Union

from shared.reports.types import UploadType


class OwnerInfo(TypedDict):
Expand Down Expand Up @@ -26,8 +28,13 @@ class GithubInstallationInfo(TypedDict):
pem_path: Optional[str]


class AdditionalData(TypedDict):
upload_type: NotRequired[UploadType]


class TorngitInstanceData(TypedDict):
owner: Union[OwnerInfo, Dict]
repo: Union[RepoInfo, Dict]
fallback_installations: List[Optional[GithubInstallationInfo]] | None
installation: Optional[GithubInstallationInfo]
additional_data: Optional[AdditionalData]

0 comments on commit b9d7171

Please sign in to comment.