Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ projects:
- name: labels
type: STRING
mode: REPEATED
- name: author_username
type: STRING
Comment thread
dklawren marked this conversation as resolved.
- name: snapshot_date
type: DATE
- id: commits
Expand Down
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"date_landed",
"date_approved",
"labels",
"author_username",
),
"commits": (
"pull_request_id",
Expand Down Expand Up @@ -787,6 +788,7 @@ def transform_data(raw_data: list[dict], repo: str) -> dict:
if pr.get("labels")
else []
),
"author_username": (pr.get("user") or {}).get("login"),
}

# Extract and flatten commit data
Expand Down
37 changes: 37 additions & 0 deletions tests/test_transform_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,43 @@ def test_labels_empty_list():
assert result["pull_requests"][0]["labels"] == []


def test_pr_author_username_extraction():
"""Test PR author login is extracted from the PR's user object."""
raw_data = [
{
"number": 1,
"title": "PR with author",
"state": "open",
"user": {"login": "octocat"},
"labels": [],
"commit_data": [],
"reviewer_data": [],
"comment_data": [],
}
]

result = main.transform_data(raw_data, "mozilla/firefox")
assert result["pull_requests"][0]["author_username"] == "octocat"


@pytest.mark.parametrize("extra", [{}, {"user": None}], ids=["absent", "null"])
def test_pr_author_username_missing_user(extra: dict):
"""Test PR author is None when the user object is null or absent."""
pr = {
"number": 1,
"title": "PR without author",
"state": "open",
"labels": [],
"commit_data": [],
"reviewer_data": [],
"comment_data": [],
**extra,
}

result = main.transform_data([pr], "mozilla/firefox")
assert result["pull_requests"][0]["author_username"] is None


def test_commit_transformation():
"""Test commit fields mapping."""
raw_data = [
Expand Down
Loading