Skip to content

Commit

Permalink
feat: Respond with actual KeyID instead of a GitHub link to keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie committed May 4, 2024
1 parent bf5eaa8 commit 750c78a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/backends/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__(
contributions: Optional[int] = None,
bio: Optional[str] = None,
keys: Optional[str] = None,
key_id: Optional[str] = None,
):
match contributions, bio, keys:
case None, None, None:
Expand All @@ -129,6 +130,7 @@ def __init__(
avatar_url=avatar_url,
html_url=html_url,
bio=bio,
key_id=key_id,
)
case int(_), str(_), str(_):
dict.__init__(
Expand Down
19 changes: 13 additions & 6 deletions api/backends/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def __assemble_contributor(
) -> Contributor:
match team_view:
case True:
keys = {"login", "avatar_url", "html_url", "bio"}
keys = {"login", "avatar_url", "html_url", "bio", "key_id"}
case _:
keys = {"login", "avatar_url", "html_url", "contributions"}

Expand All @@ -107,11 +107,6 @@ async def __assemble_contributor(
contributor,
)

if team_view:
filter_contributor["keys"] = (
f"{base_url.replace('api.', '')}/{filter_contributor['login']}.gpg"
)

return Contributor(**filter_contributor)

@staticmethod
Expand Down Expand Up @@ -313,6 +308,18 @@ async def get_team_members(self, repository: GithubRepository) -> list[Contribut
user_data_response,
)
)

for index, user in enumerate(user_data):
response: ClientResponse = await http_get(
headers=self.headers, url=f"{base_url}/users/{user['login']}/gpg_keys"
)
output = await response.json()

if len(output) is not 0:
user_data[index]["key_id"] = output[0]["key_id"]
else:
user_data[index]["key_id"] = ""

team_members: list[Contributor] = await asyncio.gather(
*map(
lambda member: self.__assemble_contributor(member, team_view=True),
Expand Down

0 comments on commit 750c78a

Please sign in to comment.