look up affiliations by email domain

When we cannot find the member's record in the foundation database,
use the email address domain to try to find an affiliation.

Change-Id: I4665aa9829373c075cb638326157981ca1251575
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-04-30 17:11:03 -04:00
parent 5916277b0a
commit 37f96735d4
5 changed files with 1404 additions and 58 deletions

View File

@ -49,6 +49,11 @@ class Organizations:
str(entry['company_name']).lower(): entry['company_name']
for entry in self._data
})
self._domains = {
domain.lower(): entry['company_name']
for entry in self._data
for domain in entry.get('domains', [])
}
@functools.lru_cache(maxsize=1024)
def __getitem__(self, name):
@ -64,3 +69,8 @@ class Organizations:
if name.endswith(end):
name = name[:-1 * len(end)]
return name
@functools.lru_cache(maxsize=1024)
def from_email(self, email):
domain = email.partition('@')[-1].lower()
return self._domains.get(domain)

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,8 @@ class TestOrganizations(base.TestCase):
'Red Hat Czech, s.r.o.',
'Red Hat Software'],
'company_name': 'Red Hat'},
{'domains': ['doughellmann.com', 'pymotw.com'],
'company_name': 'PyMOTW'},
])
def test_with_alias(self):
@ -64,3 +66,14 @@ class TestOrganizations(base.TestCase):
'Company',
self.o["'Company, Inc.'"],
)
def test_from_email(self):
self.assertEqual(
'PyMOTW',
self.o.from_email('doug@doughellmann.com')
)
def test_from_email_not_there(self):
self.assertIsNone(
self.o.from_email('dhellmann@redhat.com')
)

View File

@ -108,13 +108,18 @@ class ListContributions(lister.Lister):
# Figure out which organization the user was
# affiliated with at the time of the work.
organization = "*unknown"
organization = None
member = member_factory.fetch(participant.email)
if member:
affiliation = member.find_affiliation(participant.date)
if affiliation:
organization = canonical_orgs[
affiliation.organization]
else:
organization = canonical_orgs.from_email(
participant.email)
if not organization:
organization = "*unknown"
yield (
review_id,

View File

@ -5,3 +5,4 @@ beautifulsoup4>=4.6.0
requests
pyyaml
cliff
yamlordereddictloader