Skip to content

Commit

Permalink
Add conditional based on upload type
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-codecov committed Dec 9, 2024
1 parent 016eef6 commit 09f1c66
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
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
43 changes: 22 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,27 @@ 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: 9 additions & 0 deletions shared/typings/torngit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from enum import Enum
from typing import Dict, List, Optional, TypedDict, Union

class UploadType(Enum):
COVERAGE = "coverage"
TEST_RESULTS = "test_results"
BUNDLE_ANALYSIS = "bundle_analysis"

class OwnerInfo(TypedDict):
service_id: str
Expand All @@ -25,9 +30,13 @@ class GithubInstallationInfo(TypedDict):
app_id: Optional[int]
pem_path: Optional[str]

class AdditionalData(TypedDict):
upload_type: Optional[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 09f1c66

Please sign in to comment.