Skip to content

Commit b0fae76

Browse files
committed
fix(copilot teams collection): Add check for empty usage data
- Added a check to ensure that the usage data for each team is not empty before processing. - This prevents adding teams with no usage data to the copilot_teams list. - Improved logging to reduce CloudWatch noise by logging only when teams that have usage data are found.
1 parent be98d9a commit b0fae76

1 file changed

Lines changed: 37 additions & 13 deletions

File tree

src/main.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,40 @@ 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+
# We don't log this as an error, as it is expected that some teams may not have Copilot data and it'd be too noisy
80+
7781
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-
)
82+
83+
# If the response has data, append the team to the list
84+
# If there is no data, .json() will return an empty list
85+
if usage_data.json():
86+
87+
team_name = team.get("name", "")
88+
team_slug = team.get("slug", "")
89+
team_description = team.get("description", "")
90+
team_html_url = team.get("html_url", "")
91+
92+
logger.info(
93+
"Team %s has Copilot data",
94+
extra={
95+
"team_name": team_name,
96+
"team_slug": team_slug,
97+
"team_description": team_description,
98+
"team_html_url": team_html_url,
99+
}
100+
)
101+
102+
copilot_teams.append(
103+
{
104+
"name": team_name,
105+
"slug": team_slug,
106+
"description": team_description,
107+
"url": team_html_url,
108+
}
109+
)
86110

87111
return copilot_teams
88112

@@ -355,7 +379,7 @@ def handler(event: dict, context) -> str: # pylint: disable=unused-argument
355379
return "Github Data logging is now complete."
356380

357381

358-
# # Dev Only
359-
# # Uncomment the following line to run the script locally
360-
# if __name__ == "__main__":
361-
# handler(None, None)
382+
# Dev Only
383+
# Uncomment the following line to run the script locally
384+
if __name__ == "__main__":
385+
handler(None, None)

0 commit comments

Comments
 (0)