|
10 | 10 | * create_pull_request_draft |
11 | 11 | * create_review |
12 | 12 | * get_check_run |
13 | | - * get_git_commit |
14 | 13 | * get_pull_request_diff |
15 | | - * get_tree |
16 | 14 | * minimize_comment |
17 | 15 | * request_review |
18 | 16 | * resolve_review_thread |
|
40 | 38 | Commit, |
41 | 39 | CommitAuthor, |
42 | 40 | FileContent, |
| 41 | + GitCommitObject, |
| 42 | + GitCommitTree, |
43 | 43 | GitRef, |
| 44 | + GitTree, |
44 | 45 | PaginatedActionResult, |
45 | 46 | PaginatedResponseMeta, |
46 | 47 | PaginationParams, |
|
56 | 57 | RequestOptions, |
57 | 58 | ReviewComment, |
58 | 59 | ReviewSide, |
| 60 | + TreeEntry, |
59 | 61 | ) |
60 | 62 | from sentry.shared_integrations.exceptions import ApiError |
61 | 63 |
|
@@ -330,6 +332,47 @@ def create_branch(self, branch: BranchName, sha: SHA) -> ActionResult[GitRef]: |
330 | 332 | raw = self.client.create_branch(self._repo_id, branch, sha) |
331 | 333 | return make_result(map_git_ref, raw) |
332 | 334 |
|
| 335 | + @catch_provider_exception |
| 336 | + def get_tree( |
| 337 | + self, |
| 338 | + tree_sha: SHA, |
| 339 | + recursive: bool = True, |
| 340 | + pagination: PaginationParams | None = None, |
| 341 | + request_options: RequestOptions | None = None, |
| 342 | + ) -> ActionResult[GitTree]: |
| 343 | + """List the repository tree at a given ref. |
| 344 | +
|
| 345 | + GitLab's tree API takes a ref (commit SHA, branch, tag) rather than a |
| 346 | + tree-object SHA. We treat ``tree_sha`` as a ref so callers can pass a |
| 347 | + commit SHA obtained from ``get_git_commit``. |
| 348 | + """ |
| 349 | + raw = self.client.get_repository_tree(self._repo_id, ref=tree_sha, recursive=recursive) |
| 350 | + return ActionResult( |
| 351 | + data=GitTree( |
| 352 | + sha=tree_sha, |
| 353 | + tree=[map_tree_entry(e) for e in raw], |
| 354 | + truncated=False, |
| 355 | + ), |
| 356 | + type="gitlab", |
| 357 | + raw=raw, |
| 358 | + meta={}, |
| 359 | + ) |
| 360 | + |
| 361 | + @catch_provider_exception |
| 362 | + def get_git_commit( |
| 363 | + self, |
| 364 | + sha: SHA, |
| 365 | + request_options: RequestOptions | None = None, |
| 366 | + ) -> ActionResult[GitCommitObject]: |
| 367 | + """Get a commit as a git object. |
| 368 | +
|
| 369 | + GitLab's commit endpoint does not expose the tree-object SHA. We set |
| 370 | + ``tree.sha`` to the commit SHA so that downstream code can pass it to |
| 371 | + ``get_tree`` (which accepts any ref). |
| 372 | + """ |
| 373 | + raw = self.client.get_commit(self._repo_id, sha) |
| 374 | + return make_result(map_git_commit_object, raw) |
| 375 | + |
333 | 376 | @catch_provider_exception |
334 | 377 | def get_archive_link( |
335 | 378 | self, |
@@ -667,6 +710,26 @@ def map_reaction_result(raw: dict[str, Any]) -> ReactionResult: |
667 | 710 | ) |
668 | 711 |
|
669 | 712 |
|
| 713 | +def map_git_commit_object(raw: dict[str, Any]) -> GitCommitObject: |
| 714 | + return GitCommitObject( |
| 715 | + sha=raw["id"], |
| 716 | + # GitLab's commit API does not return a tree-object SHA. We use the |
| 717 | + # commit SHA so callers can pass it to get_tree (which accepts any ref). |
| 718 | + tree=GitCommitTree(sha=raw["id"]), |
| 719 | + message=raw["message"], |
| 720 | + ) |
| 721 | + |
| 722 | + |
| 723 | +def map_tree_entry(raw: dict[str, Any]) -> TreeEntry: |
| 724 | + return TreeEntry( |
| 725 | + path=raw["path"], |
| 726 | + mode=raw["mode"], |
| 727 | + type=raw["type"], |
| 728 | + sha=raw["id"], |
| 729 | + size=None, |
| 730 | + ) |
| 731 | + |
| 732 | + |
670 | 733 | def map_review_comment(discussion_id: str) -> Callable[[dict[str, Any]], ReviewComment]: |
671 | 734 | def _map_review_comment(raw: dict[str, Any]) -> ReviewComment: |
672 | 735 | return ReviewComment( |
|
0 commit comments