comparison hgext/phabricator.py @ 41705:570e62f1dcf2

phabricator: make user searches case-insensitive User names in conduit are case insensitive, but when looking for "FOO" it would return "foo" instead and we'd think the user didn't exist. So lower case both the query and the response when comparing them. Differential Revision: https://phab.mercurial-scm.org/D5934
author Julien Cristau <jcristau@mozilla.com>
date Mon, 11 Feb 2019 16:27:20 +0100
parents bd3f03d8cc9f
children c340a8ac7ef3
comparison
equal deleted inserted replaced
41704:3b0ba4575c8c 41705:570e62f1dcf2
448 448
449 return revision, diff 449 return revision, diff
450 450
451 def userphids(repo, names): 451 def userphids(repo, names):
452 """convert user names to PHIDs""" 452 """convert user names to PHIDs"""
453 names = [name.lower() for name in names]
453 query = {b'constraints': {b'usernames': names}} 454 query = {b'constraints': {b'usernames': names}}
454 result = callconduit(repo, b'user.search', query) 455 result = callconduit(repo, b'user.search', query)
455 # username not found is not an error of the API. So check if we have missed 456 # username not found is not an error of the API. So check if we have missed
456 # some names here. 457 # some names here.
457 data = result[r'data'] 458 data = result[r'data']
458 resolved = set(entry[r'fields'][r'username'] for entry in data) 459 resolved = set(entry[r'fields'][r'username'].lower() for entry in data)
459 unresolved = set(names) - resolved 460 unresolved = set(names) - resolved
460 if unresolved: 461 if unresolved:
461 raise error.Abort(_(b'unknown username: %s') 462 raise error.Abort(_(b'unknown username: %s')
462 % b' '.join(sorted(unresolved))) 463 % b' '.join(sorted(unresolved)))
463 return [entry[r'phid'] for entry in data] 464 return [entry[r'phid'] for entry in data]