Skip to content
Open
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
11 changes: 5 additions & 6 deletions mito-ai/mito_ai/utils/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
from typing import Literal, Optional

from mito_ai.utils.db import (MITO_FOLDER, USER_JSON_PATH, set_user_field)
from mito_ai.utils.schema import (GITHUB_ACTION_EMAIL, GITHUB_ACTION_ID,
UJ_STATIC_USER_ID, UJ_USER_EMAIL,
USER_JSON_DEFAULT)
from mito_ai.utils.schema import (GITHUB_ACTION_EMAIL,
GITHUB_ACTION_ID, UJ_STATIC_USER_ID,
UJ_USER_EMAIL, USER_JSON_DEFAULT)
from mito_ai.utils.telemetry_utils import identify
from mito_ai.utils.utils import is_running_test
from mito_ai.utils.utils import is_github_actions, is_running_test

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import is_github_actions in create.py

Low Severity

The function is_github_actions is imported from mito_ai.utils.utils but never used anywhere in create.py. The code at line 70 still uses is_running_test() to set the GITHUB_ACTION_ID, which applies to all CI environments rather than specifically GitHub Actions. This appears to be either an accidental import or an incomplete change where the condition was intended to be updated but wasn't.

Fix in Cursor Fix in Web



def is_user_json_exists_and_valid_json() -> bool:
Expand Down Expand Up @@ -66,8 +66,7 @@ def try_create_user_json_file() -> None:
if temp_user_id:
set_user_field(UJ_STATIC_USER_ID, temp_user_id)

# Finally, we take special care to put all the testing/CI environments
# (e.g. Github actions) under one ID and email
# Finally, we take special care to put CI under a known ID and email.
if is_running_test():
set_user_field(UJ_STATIC_USER_ID, GITHUB_ACTION_ID)
set_user_field(UJ_USER_EMAIL, GITHUB_ACTION_EMAIL)
Expand Down
13 changes: 7 additions & 6 deletions mito-ai/mito_ai/utils/telemetry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mito_ai.utils.schema import UJ_AI_MITO_API_NUM_USAGES, UJ_MITOSHEET_TELEMETRY, UJ_STATIC_USER_ID, UJ_USER_EMAIL, UJ_FEEDBACKS_V2
from mito_ai.utils.db import get_user_field
from mito_ai._version import __version__
from mito_ai.utils.utils import is_running_test
from mito_ai.utils.utils import is_github_actions, is_running_test
from mito_ai.completions.models import MessageType
import analytics

Expand Down Expand Up @@ -139,9 +139,10 @@ def identify(key_type: Optional[str] = None, is_electron: Optional[bool] = None)
# becase we are only sending this info to the first completion_handler identify call.
params['is_mito_desktop'] = is_electron

if not is_running_test():
# Log identify for real users and for GitHub Actions CI (user id: mito-github-action)
if not is_running_test() or is_github_actions():
# TODO: If the user is in JupyterLite, we need to do some extra work.
# You can see this in the mitosheet package.
# You can see this in the mitosheet package.
try:
analytics.identify(static_user_id, params)
except Exception as e:
Expand Down Expand Up @@ -220,9 +221,9 @@ def log(
if is_enterprise():
return

# Finally, do the acutal logging. We do not log anything when tests are
# running, or if telemetry is turned off
if not is_running_test() and telemetry_turned_on(key_type):
# Log events for real users and for GitHub Actions CI (user id: mito-github-action).
# Skip logging for local pytest and other non-GitHub-Actions CI.
if (not is_running_test() or is_github_actions()) and telemetry_turned_on(key_type):
# TODO: If the user is in JupyterLite, we need to do some extra work.
# You can see this in the mitosheet package.

Expand Down
11 changes: 11 additions & 0 deletions mito-ai/mito_ai/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def is_running_test() -> bool:

return running_pytests or running_ci


def is_github_actions() -> bool:
"""
Returns True if the current code is running inside GitHub Actions CI.
GitHub sets GITHUB_ACTIONS=true in the environment for workflow runs.
Used to enable telemetry for CI runs (with a dedicated user id) while
still skipping telemetry for local pytest runs.
"""
return os.environ.get('GITHUB_ACTIONS') == 'true'


def get_installed_packages() -> List[str]:
"""
Get a list of all installed packages.
Expand Down
Loading