Skip to content

Commit 106b8e5

Browse files
authored
chore: add git into to mcp metrics (#410)
- [x] I ran `make setup && make` to update the generated code after editing a `.atd` file (TODO: have a CI check) - [x] I made sure we're still backward compatible with old versions of the CLI. For example, the Semgrep backend need to still be able to _consume_ data generated by Semgrep 1.50.0. See https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades Note that the types related to the semgrep-core JSON output or the semgrep-core RPC do not need to be backward compatible! - [ ] Any accompanying changes in `semgrep-proprietary` are approved and ready to merge once this PR is merged
1 parent b0ca18a commit 106b8e5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

semgrep_metrics.atd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ type finding = {
278278
severity: string;
279279
}
280280

281+
281282
type mcp = {
282283
?session_id <ocaml mutable>: string option;
283284
?num_skipped_rules <ocaml mutable>: int option;
@@ -287,6 +288,9 @@ type mcp = {
287288
?findings <ocaml mutable>: (string (* rule_id *) * finding) list <json repr="object"> option;
288289
?errors <ocaml mutable>: string list option;
289290
?num_lines <ocaml mutable>: int option;
291+
?git_username <ocaml mutable>: string option;
292+
?git_repo <ocaml mutable>: string option;
293+
?git_branch <ocaml mutable>: string option;
290294
}
291295

292296
(*****************************************************************************)

semgrep_metrics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,9 @@ class Mcp:
916916
findings: Optional[List[Tuple[str, Finding]]] = None
917917
errors: Optional[List[str]] = None
918918
num_lines: Optional[int] = None
919+
git_username: Optional[str] = None
920+
git_repo: Optional[str] = None
921+
git_branch: Optional[str] = None
919922

920923
@classmethod
921924
def from_json(cls, x: Any) -> 'Mcp':
@@ -929,6 +932,9 @@ def from_json(cls, x: Any) -> 'Mcp':
929932
findings=_atd_read_assoc_object_into_list(Finding.from_json)(x['findings']) if 'findings' in x else None,
930933
errors=_atd_read_list(_atd_read_string)(x['errors']) if 'errors' in x else None,
931934
num_lines=_atd_read_int(x['num_lines']) if 'num_lines' in x else None,
935+
git_username=_atd_read_string(x['git_username']) if 'git_username' in x else None,
936+
git_repo=_atd_read_string(x['git_repo']) if 'git_repo' in x else None,
937+
git_branch=_atd_read_string(x['git_branch']) if 'git_branch' in x else None,
932938
)
933939
else:
934940
_atd_bad_json('Mcp', x)
@@ -951,6 +957,12 @@ def to_json(self) -> Any:
951957
res['errors'] = _atd_write_list(_atd_write_string)(self.errors)
952958
if self.num_lines is not None:
953959
res['num_lines'] = _atd_write_int(self.num_lines)
960+
if self.git_username is not None:
961+
res['git_username'] = _atd_write_string(self.git_username)
962+
if self.git_repo is not None:
963+
res['git_repo'] = _atd_write_string(self.git_repo)
964+
if self.git_branch is not None:
965+
res['git_branch'] = _atd_write_string(self.git_branch)
954966
return res
955967

956968
@classmethod

0 commit comments

Comments
 (0)