Mercurial > kallithea
changeset 3343:a042ec2fc12f
improved extraction of user from changeset when sending notification.
Fallback to repo owner if we cannot get the user
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 21 Jan 2013 23:14:43 +0100 |
parents | 397704877bf7 |
children | 801a80ec28e0 |
files | rhodecode/model/comment.py rhodecode/model/db.py |
diffstat | 2 files changed, 25 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/model/comment.py Mon Jan 21 01:51:16 2013 +0100 +++ b/rhodecode/model/comment.py Mon Jan 21 23:14:43 2013 +0100 @@ -88,7 +88,6 @@ if revision: cs = repo.scm_instance.get_changeset(revision) desc = "%s - %s" % (cs.short_id, h.shorter(cs.message, 256)) - author_email = cs.author_email comment.revision = revision elif pull_request: pull_request = self.__get_pull_request(pull_request) @@ -122,7 +121,11 @@ # get the current participants of this changeset recipients = ChangesetComment.get_users(revision=revision) # add changeset author if it's in rhodecode system - recipients += [User.get_by_email(author_email)] + cs_author = User.get_from_cs_author(cs.author) + if not cs_author: + #use repo owner if we cannot extract the author correctly + cs_author = repo.user + recipients += [cs_author] email_kwargs = { 'status_change': status_change, }
--- a/rhodecode/model/db.py Mon Jan 21 01:51:16 2013 +0100 +++ b/rhodecode/model/db.py Mon Jan 21 23:14:43 2013 +0100 @@ -454,6 +454,26 @@ return ret + @classmethod + def get_from_cs_author(cls, author): + """ + Tries to get User objects out of commit author string + + :param author: + """ + from rhodecode.lib.helpers import email, author_name + # Valid email in the attribute passed, see if they're in the system + _email = email(author) + if _email: + user = cls.get_by_email(_email, case_insensitive=True) + if user: + return user + # Maybe we can match by username? + _author = author_name(author) + user = cls.get_by_username(_author, case_insensitive=True) + if user: + return user + def update_lastlogin(self): """Update user lastlogin""" self.last_login = datetime.datetime.now()