diff --git a/Cargo.lock b/Cargo.lock index 17039f11..e4e8cee2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1699,7 +1699,7 @@ dependencies = [ [[package]] name = "tach" -version = "0.18.0" +version = "0.19.0" dependencies = [ "cached", "criterion", diff --git a/Cargo.toml b/Cargo.toml index fd64cb12..1b7d66e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tach" -version = "0.18.0" +version = "0.19.0" edition = "2021" [lib] diff --git a/docs/usage/commands.mdx b/docs/usage/commands.mdx index 55660399..de452807 100644 --- a/docs/usage/commands.mdx +++ b/docs/usage/commands.mdx @@ -255,7 +255,7 @@ If you use the [pre-commit framework](https://github.com/pre-commit/pre-commit), ```yaml repos: - repo: https://github.com/gauge-sh/tach-pre-commit - rev: v0.18.0 # change this to the latest tag! + rev: v0.19.0 # change this to the latest tag! hooks: - id: tach ``` diff --git a/pyproject.toml b/pyproject.toml index c7e0ba3f..5d8898d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "tach" -version = "0.18.0" +version = "0.19.0" authors = [ { name = "Caelean Barnes", email = "caeleanb@gmail.com" }, { name = "Evan Doyle", email = "evanmdoyle@gmail.com" }, diff --git a/python/tach/__init__.py b/python/tach/__init__.py index ca450435..5e744248 100644 --- a/python/tach/__init__.py +++ b/python/tach/__init__.py @@ -1,5 +1,5 @@ from __future__ import annotations -__version__: str = "0.18.0" +__version__: str = "0.19.0" __all__ = ["__version__"] diff --git a/python/tach/filesystem/git_ops.py b/python/tach/filesystem/git_ops.py index 3a4eb94e..4c09836d 100644 --- a/python/tach/filesystem/git_ops.py +++ b/python/tach/filesystem/git_ops.py @@ -17,6 +17,9 @@ class GitBranchInfo: repo: str name: str commit: str + owner: str + user_name: str + email: str def is_github_actions(): @@ -67,13 +70,25 @@ def get_current_branch_info( try: # TODO: support slashes or org names - repo_name = repo.remotes.origin.url.split("/")[-1].replace(".git", "") + url_parts = repo.remotes.origin.url.split("/") + repo_name = url_parts[-1].replace(".git", "") + owner_name = url_parts[0].split(":")[-1] + config_reader = repo.config_reader() + user_name = str(config_reader.get_value("user", "name", default="")) + email = str(config_reader.get_value("user", "email", default="")) branch = _get_branch_name(repo) commit = _get_commit(repo) except Exception as e: raise TachError(f"Failed to determine current branch information!\nError: {e}") - return GitBranchInfo(repo=repo_name, name=branch, commit=commit) + return GitBranchInfo( + repo=repo_name, + owner=owner_name, + name=branch, + commit=commit, + user_name=user_name, + email=email, + ) def get_changed_files( diff --git a/python/tach/modularity.py b/python/tach/modularity.py index 441a4b22..c2cf4816 100644 --- a/python/tach/modularity.py +++ b/python/tach/modularity.py @@ -44,20 +44,20 @@ def upload_report_to_gauge( """Upload a modularity report to Gauge.""" report = generate_modularity_report(project_root, project_config, force=force) print(f"{BCOLORS.OKCYAN} > Uploading report...{BCOLORS.ENDC}") - path = build_modularity_upload_path(report.repo) - post_json_to_gauge_api(path, asdict(report)) + response_data = post_json_to_gauge_api(asdict(report)) print(f"{BCOLORS.OKGREEN} > Report uploaded!{BCOLORS.ENDC}") + if response_data.get("url"): + print( + f"{BCOLORS.OKBLUE} > {GAUGE_API_BASE_URL}{response_data['url']}{BCOLORS.ENDC}" + ) GAUGE_API_KEY = os.getenv("GAUGE_API_KEY", "") GAUGE_API_BASE_URL = os.getenv("GAUGE_API_BASE_URL", "https://app.gauge.sh") +GAUGE_UPLOAD_URL = f"{GAUGE_API_BASE_URL}/api/client/tach-upload/1.3" -def build_modularity_upload_path(repo: str) -> str: - return f"/api/client/repos/{repo}/modularity" - - -def post_json_to_gauge_api(path: str, data: dict[str, Any]) -> None: +def post_json_to_gauge_api(data: dict[str, Any]) -> dict[str, str]: if not GAUGE_API_KEY: raise TachClosedBetaError( f"{BCOLORS.WARNING}Modularity is currently in closed beta. Visit {GAUGE_API_BASE_URL}/closed-beta to request access.{BCOLORS.ENDC}" @@ -70,28 +70,26 @@ def post_json_to_gauge_api(path: str, data: dict[str, Any]) -> None: } json_data = json.dumps(data) conn = None - full_url = f"{GAUGE_API_BASE_URL}{path}" try: - url_parts: parse.ParseResult = parse.urlparse(full_url) - if full_url.startswith("https://"): + url_parts: parse.ParseResult = parse.urlparse(GAUGE_UPLOAD_URL) + if GAUGE_UPLOAD_URL.startswith("https://"): conn = HTTPSConnection(url_parts.netloc, timeout=10) else: conn = HTTPConnection(url_parts.netloc, timeout=10) - conn.request("POST", path, body=json_data, headers=headers) + conn.request("POST", url_parts.path, body=json_data, headers=headers) response = conn.getresponse() - + response_data = response.read().decode("utf-8") # Check for non-200 status codes if response.status != 200: - error_message = response.read().decode("utf-8") raise TachError( - f"API request failed with status {response.status}: {error_message}" + f"API request failed with status {response.status}: {response_data}" ) - except Exception as e: raise TachError(f"Failed to upload modularity report: {str(e)}") finally: if conn is not None: conn.close() + return json.loads(response_data) # NOTE: these usages are all imports @@ -159,6 +157,9 @@ class CheckResult: @dataclass class Report: + email: str + user_name: str + owner: str repo: str branch: str commit: str @@ -166,6 +167,7 @@ class Report: full_configuration: str modules: list[Module] = field(default_factory=list) usages: list[Usage] = field(default_factory=list) + # [1.3] Check result for dependency errors check_result: CheckResult = field(default_factory=CheckResult) metadata: ReportMetadata = field(default_factory=ReportMetadata) # [1.2] Deprecated @@ -297,6 +299,9 @@ def generate_modularity_report( print(f"{BCOLORS.OKCYAN} > Generating report...{BCOLORS.ENDC}") branch_info = get_current_branch_info(project_root, allow_dirty=force) report = Report( + user_name=branch_info.user_name, + email=branch_info.email, + owner=branch_info.owner, repo=branch_info.repo, branch=branch_info.name, commit=branch_info.commit,