11from bisect import bisect_left , bisect_right
2+ from collections import defaultdict
23from datetime import datetime , timezone
34import logging
45import re
@@ -253,21 +254,27 @@ async def set_jira_identities(request: AthenianWebRequest, body: dict) -> web.Re
253254 ),
254255 ]
255256 github_id_rows , jira_id_rows = await gather (* tasks )
256- github_id_map = {r [GitHubUser .login .name ]: r [GitHubUser .node_id .name ] for r in github_id_rows }
257- jira_id_map = {r [JIRAUser .display_name .name ]: r [JIRAUser .id .name ] for r in jira_id_rows }
257+ github_id_map = defaultdict (list )
258+ for r in github_id_rows :
259+ github_id_map [r [GitHubUser .login .name ]].append (
260+ r [GitHubUser .node_id .name ])
261+
262+ jira_id_map = {
263+ r [JIRAUser .display_name .name ]: r [JIRAUser .id .name ]
264+ for r in jira_id_rows
265+ }
258266 cleared_github_ids = set ()
259267 updated_maps = []
260268 for i , change in enumerate (request_model .changes ):
261- try :
262- github_id = github_id_map [change .developer_id .rsplit ("/" , 1 )[1 ]]
263- except KeyError :
269+ github_ids = github_id_map [change .developer_id .rsplit ("/" , 1 )[1 ]]
270+ if len (github_ids ) == 0 :
264271 raise ResponseError (
265272 InvalidRequestError (
266273 detail = "Developer was not found." , pointer = f".changes[{ i } ].developer_id" ,
267274 ),
268275 )
269276 if change .jira_name is None :
270- cleared_github_ids .add ( github_id )
277+ cleared_github_ids .update ( github_ids )
271278 continue
272279 if not change .jira_name :
273280 raise ResponseError (
@@ -283,7 +290,9 @@ async def set_jira_identities(request: AthenianWebRequest, body: dict) -> web.Re
283290 detail = "JIRA user was not found." , pointer = f".changes[{ i } ].jira_name" ,
284291 ),
285292 )
286- updated_maps .append ((github_id , jira_id ))
293+
294+ for github_id in github_ids :
295+ updated_maps .append ((github_id , jira_id ))
287296
288297 try :
289298 async with sdb .connection () as sdb_conn :
0 commit comments