Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7122943
D1408.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D1408.diff
View Options
diff --git a/swh/loader/npm/tests/test_utils.py b/swh/loader/npm/tests/test_utils.py
--- a/swh/loader/npm/tests/test_utils.py
+++ b/swh/loader/npm/tests/test_utils.py
@@ -225,3 +225,44 @@
'email': b'evgeniy.pakalo@gmail.com'
}
)
+
+ package_json = json.loads('''
+ {
+ "name": "3-way-diff",
+ "version": "0.0.1",
+ "description": "3-way diffing of JavaScript objects",
+ "main": "index.js",
+ "authors": [
+ {
+ "name": "Shawn Walsh",
+ "url": "https://github.com/shawnpwalsh"
+ },
+ {
+ "name": "Markham F Rollins IV",
+ "url": "https://github.com/mrollinsiv"
+ }
+ ],
+ "keywords": [
+ "3-way diff",
+ "3 way diff",
+ "three-way diff",
+ "three way diff"
+ ],
+ "devDependencies": {
+ "babel-core": "^6.20.0",
+ "babel-preset-es2015": "^6.18.0",
+ "mocha": "^3.0.2"
+ },
+ "dependencies": {
+ "lodash": "^4.15.0"
+ }
+ }''')
+
+ self.assertEqual(
+ extract_npm_package_author(package_json),
+ {
+ 'fullname': b'Shawn Walsh',
+ 'name': b'Shawn Walsh',
+ 'email': None
+ }
+ )
diff --git a/swh/loader/npm/utils.py b/swh/loader/npm/utils.py
--- a/swh/loader/npm/utils.py
+++ b/swh/loader/npm/utils.py
@@ -77,19 +77,25 @@
* email
"""
+
+ def _author_str(author_data):
+ if type(author_data) is dict:
+ author_str = ''
+ if 'name' in author_data:
+ author_str += author_data['name']
+ if 'email' in author_data:
+ author_str += ' <%s>' % author_data['email']
+ return author_str
+ else:
+ return author_data
+
author_data = {}
if 'author' in package_json:
- if type(package_json['author']) is str:
- author_data = parse_npm_package_author(package_json['author'])
- elif type(package_json['author']) is dict:
- author_str = ''
- if 'name' in package_json['author']:
- author_str += package_json['author']['name']
- if 'email' in package_json['author']:
- author_str += ' <%s>' % package_json['author']['email']
- author_data = parse_npm_package_author(author_str)
+ author_str = _author_str(package_json['author'])
+ author_data = parse_npm_package_author(author_str)
elif 'authors' in package_json and len(package_json['authors']) > 0:
- author_data = parse_npm_package_author(package_json['authors'][0])
+ author_str = _author_str(package_json['authors'][0])
+ author_data = parse_npm_package_author(author_str)
name = author_data.get('name')
email = author_data.get('email')
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Dec 17 2024, 12:42 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3219154
Attached To
D1408: extract_npm_package_author: Handle list of dict authors layout
Event Timeline
Log In to Comment