Skip to content

Commit c92c7b1

Browse files
authored
Merge pull request #61 from ONS-Innovation/copilot_teams_bug
KEH-1236 | Bug Fix: copilot_team.json logic
2 parents be98d9a + 13b12c3 commit c92c7b1

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

src/main.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,41 @@ def get_copilot_team_date(gh: github_api_toolkit.github_interface, page: int) ->
7373
usage_data = gh.get(f"/orgs/{org}/team/{team['name']}/copilot/metrics")
7474

7575
if not isinstance(usage_data, Response):
76-
logger.error("Unexpected response type: %s", type(usage_data))
76+
77+
# If the response is not a Response object, no copilot data is available for this team
78+
# We can then skip this team
79+
80+
# We don't log this as an error, as it is expected and it'd be too noisy within logs
81+
7782
continue
78-
copilot_teams.append(
79-
{
80-
"name": team.get("name", ""),
81-
"slug": team.get("slug", ""),
82-
"description": team.get("description", ""),
83-
"url": team.get("html_url", ""),
84-
}
85-
)
83+
84+
# If the response has data, append the team to the list
85+
# If there is no data, .json() will return an empty list
86+
if usage_data.json():
87+
88+
team_name = team.get("name", "")
89+
team_slug = team.get("slug", "")
90+
team_description = team.get("description", "")
91+
team_html_url = team.get("html_url", "")
92+
93+
logger.info(
94+
"Team %s has Copilot data",
95+
extra={
96+
"team_name": team_name,
97+
"team_slug": team_slug,
98+
"team_description": team_description,
99+
"team_html_url": team_html_url,
100+
},
101+
)
102+
103+
copilot_teams.append(
104+
{
105+
"name": team_name,
106+
"slug": team_slug,
107+
"description": team_description,
108+
"url": team_html_url,
109+
}
110+
)
86111

87112
return copilot_teams
88113

tests/test_main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,6 @@ def test_get_copilot_team_date_unexpected_usage_response(self, caplog):
331331
with caplog.at_level("ERROR"):
332332
result = get_copilot_team_date(gh, 1)
333333
assert result == []
334-
assert any(
335-
"Unexpected response type" in record.getMessage() for record in caplog.records
336-
)
337334

338335
@patch("src.main.org", "test-org")
339336
def test_get_copilot_team_date_empty_teams(self):

0 commit comments

Comments
 (0)