Skip to content

Commit 31b1b0b

Browse files
authored
Merge pull request #403 from nexB/395-php-composer
#395 Add parser for PHP composer and support for composer packages detection.
2 parents d79ad1f + 68ffc5c commit 31b1b0b

File tree

11 files changed

+1479
-73
lines changed

11 files changed

+1479
-73
lines changed

src/packagedcode/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def as_dict(self, **kwargs):
312312
repo_ivy = 'IVY'
313313
repo_maven = 'Maven'
314314
repo_npm = 'NPM'
315+
repo_phpcomposer = 'Packagist'
315316
repo_nuget = 'Nuget'
316317
repo_python = 'Pypi'
317318
repo_yum = 'YUM'
@@ -325,6 +326,7 @@ def as_dict(self, **kwargs):
325326
repo_ivy,
326327
repo_maven,
327328
repo_npm,
329+
repo_phpcomposer,
328330
repo_nuget,
329331
repo_python,
330332
repo_yum,

src/packagedcode/npm.py

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from commoncode import fileutils
3737

3838
from packagedcode import models
39+
from packagedcode.utils import parse_repo_url
3940

4041
"""
4142
Handle Node.js NPM packages
@@ -299,79 +300,6 @@ def repository_mapper(repo, package):
299300
return package
300301

301302

302-
VCS_URLS = (
303-
'https://',
304-
'http://',
305-
'git://',
306-
'git+git://',
307-
'hg+https://',
308-
'hg+http://',
309-
'git+https://',
310-
'git+http://',
311-
'svn+https://',
312-
'svn+http://',
313-
'svn://',
314-
)
315-
316-
317-
def parse_repo_url(repo_url):
318-
"""
319-
Validate a repo_ulr and handle shortcuts for GitHub, GitHub gist,
320-
Bitbucket, or GitLab repositories (same syntax as npm install):
321-
322-
See https://docs.npmjs.com/files/package.json#repository
323-
This is done here in npm:
324-
https://github.com/npm/npm/blob/d3c858ce4cfb3aee515bb299eb034fe1b5e44344/node_modules/hosted-git-info/git-host-info.js
325-
326-
These should be resolved:
327-
npm/npm
328-
gist:11081aaa281
329-
bitbucket:example/repo
330-
gitlab:another/repo
331-
expressjs/serve-static
332-
git://github.com/angular/di.js.git
333-
git://github.com/hapijs/boom
334-
[email protected]:balderdashy/waterline-criteria.git
335-
http://github.com/ariya/esprima.git
336-
http://github.com/isaacs/nopt
337-
https://github.com/chaijs/chai
338-
https://github.com/christkv/kerberos.git
339-
https://gitlab.com/foo/private.git
340-
[email protected]:foo/private.git
341-
"""
342-
343-
# TODO: Improve this and use outside of NPMs
344-
is_vcs_url = repo_url.startswith(VCS_URLS)
345-
if is_vcs_url:
346-
# TODO: ensure the .git suffix is present if needed
347-
return repo_url
348-
349-
if repo_url.startswith('git@'):
350-
left, right = repo_url.split('@', 1)
351-
host, repo = right.split(':', 1)
352-
# may be we should
353-
if any(h in host for h in ['github', 'bitbucket', 'gitlab']):
354-
return 'https://%(host)s/%(repo)s' % locals()
355-
else:
356-
return repo_url
357-
358-
if repo_url.startswith('gist:'):
359-
return repo_url
360-
361-
elif repo_url.startswith(('bitbucket:', 'gitlab:', 'github:')):
362-
hoster_urls = {
363-
'bitbucket:': 'https://bitbucket.org/%(repo)s',
364-
'github:': 'https://github.com/%(repo)s',
365-
'gitlab:': 'https://gitlab.com/%(repo)s',
366-
}
367-
hoster, repo = repo_url.split(':', 1)
368-
return hoster_urls[hoster] % locals()
369-
elif len(repo_url.split('/')) == 2:
370-
# implicit github
371-
return 'https://github.com/%(repo_url)s' % locals()
372-
return repo_url
373-
374-
375303
def url_mapper(url, package):
376304
"""
377305
In a package.json, the "url" field is a redirection to a package download

0 commit comments

Comments
 (0)