Skip to content

Commit

Permalink
Extract args and send with command events
Browse files Browse the repository at this point in the history
Signed-off-by: even-wei <[email protected]>
  • Loading branch information
even-wei committed Dec 17, 2024
1 parent 8786be3 commit e36309f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
7 changes: 0 additions & 7 deletions recce/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ def get_runner():
return None


def get_cli_args():
# Join all arguments starting from the script name
full_command_line = ' '.join(sys.argv)

return full_command_line


def get_version():
version_file = os.path.normpath(os.path.join(os.path.dirname(__file__), 'VERSION'))
with open(version_file) as fh:
Expand Down
6 changes: 1 addition & 5 deletions recce/event/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import sentry_sdk

from recce import is_ci_env, get_version, get_runner, get_cli_args()
from recce import is_ci_env, get_version, get_runner
from recce import yaml as pyml
from recce.event.collector import Collector
from recce.github import is_github_codespace, get_github_codespace_info, get_github_codespace_name, \
Expand Down Expand Up @@ -174,10 +174,6 @@ def log_event(prop, event_type, **kwargs):
if runner == 'github codespaces':
prop['codespaces_name'] = get_github_codespace_name()

cli_args = get_cli_args()
if cli_args is not None:
prop['cli_args'] = cli_args

payload = dict(
**prop,
)
Expand Down
19 changes: 13 additions & 6 deletions recce/event/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rich.console import Console
from rich.markup import escape

from recce import event, get_runner, get_cli_args()
from recce import event, get_runner
from recce.core import load_context
from recce.exceptions import RecceException
from recce.git import current_branch, hosting_repo
Expand Down Expand Up @@ -88,31 +88,38 @@ def invoke(self, ctx: Context) -> t.Any:
sys.exit(1)
finally:
end_time = time.time()
duration = end_time - start_time
runner = get_runner()
cli_args = get_cli()
repo = hosting_repo()
branch = current_branch()
command = ctx.command.name
duration = end_time - start_time
target_path = ctx.params.get('target_path', None)
target_base_path = ctx.params.get('target_base_path', None)
props = dict(
command=command,
status=status,
reason=reason,
duration=duration,
cloud=ctx.params.get('cloud', False),
review=ctx.params.get('review', False),
debug=ctx.params.get('debug', False),
)

if runner is not None:
props['runner_type'] = runner

if cli_args is not None:
props['cli_args'] = cli_args

if repo is not None:
props['repository'] = sha256(repo.encode()).hexdigest()

if branch is not None:
props['branch'] = sha256(branch.encode()).hexdigest()

if target_path is not None:
props['target_path'] = sha256(target_path.encode()).hexdigest()

if target_base_path is not None:
props['target_base_path'] = sha256(target_base_path.encode()).hexdigest()

try:
recce_context = load_context()
except Exception:
Expand Down

0 comments on commit e36309f

Please sign in to comment.