Repository: con/tributors

Issue:
update-lookup: crashes with "ValueError: too many values to unpack" on .mailmap parsin
```shell
(git)lena:~datalad/datalad-master[master]git
$> tributors update-lookup
INFO:allcontrib:Updating .tributors cache from .all-contributorsrc
INFO:    zenodo:Updating .tributors cache from .zenodo.json
INFO:   mailmap:Updating .tributors cache from .mailmap
Traceback (most recent call last):
  File "/home/yoh/proj/tributors/venvs/dev3/bin/tributors", line 33, in <module>
    sys.exit(load_entry_point('tributors', 'console_scripts', 'tributors')())
  File "/home/yoh/proj/tributors/tributors/client/__init__.py", line 175, in main
    main(args, extra)
  File "/home/yoh/proj/tributors/tributors/client/lookup.py", line 52, in main
    client.update_resource(resources=resources, params=extra)
  File "/home/yoh/proj/tributors/tributors/main/__init__.py", line 97, in update_resource
    resource.update_lookup()
  File "/home/yoh/proj/tributors/tributors/main/parsers/mailmap.py", line 63, in update_lookup
    self.load_data()
  File "/home/yoh/proj/tributors/tributors/main/parsers/mailmap.py", line 41, in load_data
    name, email = line.split("<")
ValueError: too many values to unpack (expected 2)
(dev3) 1 15113 ->1.....................................:Wed 18 Aug 2021 09:53:20 AM EDT:.
(git)lena:~datalad/datalad-master[master]git
$> git describe           
0.14.7-544-g379d4e2f9
changes on filesystem:                                                                                                                                                                                               
 .github/workflows/update-contributors.yml | 2 +-
(dev3) 1 15114.....................................:Wed 18 Aug 2021 09:54:31 AM EDT:.
(git)lena:~datalad/datalad-master[master]git
$> tributors --version
0.0.19
changes on filesystem:                                                                                                                                                                                               
 .github/workflows/update-contributors.yml | 2 +-
(dev3) 1 15115.....................................:Wed 18 Aug 2021 09:54:34 AM EDT:.
(git)lena:~datalad/datalad-master[master]git
$> cat .mailmap 
Alejandro de la Vega <delavega@utexas.edu>
Alex Waite <alexqw85@gmail.com> Alex Waite <alex@waite.eu>
Andy Connolly <andrew.c.connolly@dartmouth.edu> <andycon@users.noreply.github.com>
Anisha Keshavan <keshavan@berkeley.edu>
Benjamin Poldrack <benjaminpoldrack@gmail.com> <bpoldrack@users.noreply.github.com>
Christian Mönch <christian.moench@web.de> Christian Moench <christian.monch@conax.com>
Christian Olaf Häusler <der.haeusler@gmx.net> chris <chris@psyinfolaf.ovgu.de>
Dave MacFarlane <driusan@gmail.com> Dave MacFarlane <dave.macfarlane@mcin.ca>
Dave MacFarlane <driusan@gmail.com> Dave MacFarlane <driusan@mcin.ca>
Debanjum Singh Solanky <debanjum@gmail.com> Debanjum <debanjum@gmail.com> debanjum <debanjum@gmail.com>
Gergana Alteva <glalteva@gmail.com> Gergana Alteva <glalteva@users.noreply.github.com>
Jason Gors <jason.gors.work@gmail.com>
John T. Wodder II <git@varonathe.org> <jwodder@users.noreply.github.com>
Kusti Skytén <kusti.skyten@helsinki.fi> <kskyten@users.noreply.github.com>
Michael Hanke <michael.hanke@gmail.com> mih <mih>
Neuroimaging Community <committer@example.com> blah <committer@example.com> 
Neuroimaging Community <committer@example.com> <test@example.com> 
Neuroimaging Community <committer@example.com> unknown <test@nowhere.com> 
Taylor Olson <to.overlake@gmail.com> Taylor Olson <taylor.m.olson.21@dartmouth.edu>
Torsten Stoeter <torsten.stoeter@lin-magdeburg.de>
Vanessa Sochat <vsoch@users.noreply.github.com> 
Yaroslav Halchenko <debian@onerussian.com> 
Yaroslav Halchenko <debian@onerussian.com> <site-github-private@onerussian.com>
Yaroslav Halchenko <debian@onerussian.com> <yoh@smaug.cns.dartmouth.edu>
```

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3901cb9..aa0b97f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
 The versions coincide with releases on pip.
 
 ## [0.0.x](https://github.com/con/tributors/tree/master) (0.0.x)
+ - fix mailmap parsing which could have lead to "too many values unpack" (0.0.22)
  - add to action ability to run command twice (0.0.21)
  - searching orcid for other-names as final resort, requiring first/last (0.0.19)
  - searching for last, first and reverse for orcid lookup (0.0.18)
diff --git a/tributors/main/parsers/codemeta.py b/tributors/main/parsers/codemeta.py
index 34bb769..ebbe7f3 100644
--- a/tributors/main/parsers/codemeta.py
+++ b/tributors/main/parsers/codemeta.py
@@ -63,7 +63,7 @@ class CodeMetaParser(ParserBase):
 
     def update_metadata(self):
         """Update codemeta metadata from the repository, if we can."""
-        self.data["keywords"] = self.repo.topics(self.data["keywords"])
+        self.data["keywords"] = self.repo.topics(self.data.get("keywords", []))
         self.data["description"] = self.data.get("description") or self.repo.description
         self.data["codeRepository"] = (
             self.data.get("codeRepository") or self.repo.html_url
diff --git a/tributors/main/parsers/mailmap.py b/tributors/main/parsers/mailmap.py
index 280e973..560c594 100644
--- a/tributors/main/parsers/mailmap.py
+++ b/tributors/main/parsers/mailmap.py
@@ -1,6 +1,6 @@
 """
 
-Copyright (C) 2020 Vanessa Sochat.
+Copyright (C) 2020-2022 Vanessa Sochat.
 
 This Source Code Form is subject to the terms of the
 Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
@@ -38,9 +38,21 @@ class MailmapParser(ParserBase):
                 sys.exit("%s does not exist" % self.filename)
 
             for line in read_file(self.filename):
-                name, email = line.split("<")
-                email = email.strip().rstrip(">")
-                self.data[email] = {"name": name.strip()}
+
+                # keep track of the previous name, in case multiple per line
+                name = None
+
+                # mailmap line can have more than one entry, split by right >
+                for entry in line.strip().split(">"):
+                    if not entry:
+                        continue
+                    new_name, email = map(str.strip, entry.split("<"))
+                    # only the first name matters
+                    if not name and new_name:
+                        name = new_name
+                    if not name:
+                        raise ValueError(f"Could not figure out name in {line!r}")
+                    self.data[email] = {"name": name}
         return self.data
 
     @property
diff --git a/tributors/version.py b/tributors/version.py
index cc2394b..c92b6f8 100644
--- a/tributors/version.py
+++ b/tributors/version.py
@@ -8,7 +8,7 @@ with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 """
 
-__version__ = "0.0.21"
+__version__ = "0.0.22"
 AUTHOR = "Vanessa Sochat"
 AUTHOR_EMAIL = "vsochat@stanford.edu"
 NAME = "tributors"


Test patch:
diff --git a/tests/test_mailmap.py b/tests/test_mailmap.py
new file mode 100644
index 0000000..27ea0c4
--- /dev/null
+++ b/tests/test_mailmap.py
@@ -0,0 +1,30 @@
+from tributors.main.parsers.mailmap import MailmapParser
+
+import pytest
+
+
+def test_simple(tmp_path):
+    mailmap = tmp_path / ".mailmap"
+    mailmap.write_text("""
+Joe Smith <joe.smith@gmail.com>
+Neuroimaging Community <committer@example.com>
+Neuroimaging Community <committer@example.com> blah <blah@example.com>
+Neuroimaging Community <committer@example.com> <test@example.com>""")
+    parser = MailmapParser(str(mailmap))
+    r = parser.load_data()
+    assert r == {
+        'joe.smith@gmail.com': {'name': 'Joe Smith'},
+        'committer@example.com': {'name': 'Neuroimaging Community'},
+        'blah@example.com': {'name': 'Neuroimaging Community'},
+        'test@example.com': {'name': 'Neuroimaging Community'}
+    }
+
+
+def test_noname(tmp_path):
+    mailmap = tmp_path / ".mailmap"
+    l = " <joe.smith@gmail.com>"
+    mailmap.write_text(l)
+    with pytest.raises(ValueError) as cme:
+        r = MailmapParser(str(mailmap)).load_data()
+    assert l in str(cme.value)
+
diff --git a/tests/test_orcid.py b/tests/test_orcid.py
index 89f083e..0c228d1 100644
--- a/tests/test_orcid.py
+++ b/tests/test_orcid.py
@@ -40,5 +40,5 @@ def test_queries(tmp_path):
 
     # TODO this looks like the API is changed
     # Test find by other-names (can't do because more than one result)
-    # result = get_orcid(email=None, name="Horea Christian")
-    # assert result == "0000-0001-7037-2449"
+    result = get_orcid(email=None, name="Chris Gorgolewski")
+    assert result == "0000-0003-3321-7583"