Skip to content

Commit 5a8400b

Browse files
authored
ref(scm): Wrap raw response with data key and provide the headers (#111715)
This is a forward compatibility step. By wrapping the raw response with the data key we can add more keys later to communicate more information (if needed) without breaking existing callers. I decided to add the headers to the raw response for completeness.
1 parent 20b0021 commit 5a8400b

File tree

6 files changed

+6268
-6139
lines changed

6 files changed

+6268
-6139
lines changed

src/sentry/scm/private/providers/github.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def get_pull_request_diff(
712712
return {
713713
"data": response.text,
714714
"type": "github",
715-
"raw": response.text,
715+
"raw": {"data": response.text, "headers": dict(response.headers)},
716716
"meta": _extract_response_meta(response),
717717
}
718718

@@ -933,7 +933,7 @@ def get_archive_link(
933933
return {
934934
"data": ArchiveLink(url=response.headers["Location"], headers={}),
935935
"type": "github",
936-
"raw": response.headers["Location"],
936+
"raw": {"data": response.headers["Location"], "headers": dict(response.headers)},
937937
"meta": _extract_response_meta(response),
938938
}
939939

@@ -1125,7 +1125,7 @@ def map_action[T](
11251125
return {
11261126
"data": fn(raw),
11271127
"type": "github",
1128-
"raw": raw,
1128+
"raw": {"data": raw, "headers": dict(response.headers)},
11291129
"meta": _extract_response_meta(response),
11301130
}
11311131

@@ -1143,6 +1143,6 @@ def map_paginated_action[T](
11431143
return {
11441144
"data": fn(raw),
11451145
"type": "github",
1146-
"raw": raw,
1146+
"raw": {"data": raw, "headers": dict(response.headers)},
11471147
"meta": meta,
11481148
}

src/sentry/scm/private/providers/gitlab.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def get_tree(
354354
truncated=False,
355355
),
356356
type="gitlab",
357-
raw=raw,
357+
raw={"data": raw, "headers": None},
358358
meta={},
359359
)
360360

@@ -390,7 +390,7 @@ def get_archive_link(
390390
return ActionResult(
391391
data=data,
392392
type="gitlab",
393-
raw=url,
393+
raw={"data": url, "headers": None},
394394
meta={},
395395
)
396396

@@ -597,7 +597,7 @@ def make_paginated_result[T](
597597
return PaginatedActionResult(
598598
data=[map_item(item) for item in raw_items],
599599
type="gitlab",
600-
raw=raw,
600+
raw={"data": raw, "headers": None},
601601
# No actual pagination for now
602602
meta=PaginatedResponseMeta(next_cursor=None),
603603
)
@@ -615,7 +615,7 @@ def make_result[T](
615615
return ActionResult(
616616
data=map_item(raw_item),
617617
type="gitlab",
618-
raw=raw,
618+
raw={"data": raw, "headers": None},
619619
meta={},
620620
)
621621

src/sentry/scm/types.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22
from datetime import datetime
3-
from typing import Any, Literal, Protocol, Required, TypedDict, runtime_checkable
3+
from typing import Any, Literal, MutableMapping, Protocol, Required, TypedDict, runtime_checkable
44

55
type Action = Literal["check_run", "comment", "pull_request"]
66
type EventType = "CheckRunEvent" | "CommentEvent" | "PullRequestEvent"
@@ -217,6 +217,11 @@ class PullRequest(TypedDict):
217217
base: PullRequestBranch
218218

219219

220+
class RawResult(TypedDict):
221+
headers: MutableMapping[str, str] | None
222+
data: Any
223+
224+
220225
class ActionResult[T](TypedDict):
221226
"""Wraps a provider response with metadata and the original API payload.
222227
@@ -230,7 +235,7 @@ class ActionResult[T](TypedDict):
230235

231236
data: T
232237
type: ProviderName
233-
raw: Any
238+
raw: RawResult
234239
meta: ResponseMeta
235240

236241

@@ -244,7 +249,7 @@ class PaginatedActionResult[T](TypedDict):
244249

245250
data: list[T]
246251
type: ProviderName
247-
raw: Any
252+
raw: RawResult
248253
meta: PaginatedResponseMeta
249254

250255

0 commit comments

Comments
 (0)