Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
fbec6dbd
Commit
fbec6dbd
authored
May 16, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Autolink package names in composer.json
parent
83747783
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
0 deletions
+109
-0
lib/gitlab/dependency_linker.rb
lib/gitlab/dependency_linker.rb
+1
-0
lib/gitlab/dependency_linker/composer_json_linker.rb
lib/gitlab/dependency_linker/composer_json_linker.rb
+18
-0
spec/lib/gitlab/dependency_linker/composer_json_linker_spec.rb
...lib/gitlab/dependency_linker/composer_json_linker_spec.rb
+82
-0
spec/lib/gitlab/dependency_linker_spec.rb
spec/lib/gitlab/dependency_linker_spec.rb
+8
-0
No files found.
lib/gitlab/dependency_linker.rb
View file @
fbec6dbd
...
...
@@ -4,6 +4,7 @@ module Gitlab
GemfileLinker
,
GemspecLinker
,
PackageJsonLinker
,
ComposerJsonLinker
,
].
freeze
def
self
.
linker
(
blob_name
)
...
...
lib/gitlab/dependency_linker/composer_json_linker.rb
0 → 100644
View file @
fbec6dbd
module
Gitlab
module
DependencyLinker
class
ComposerJsonLinker
<
PackageJsonLinker
self
.
file_type
=
:composer_json
private
def
link_packages
link_packages_at_key
(
"require"
,
&
method
(
:package_url
))
link_packages_at_key
(
"require-dev"
,
&
method
(
:package_url
))
end
def
package_url
(
name
)
"https://packagist.org/packages/
#{
name
}
"
if
name
=~
%r{
\A
#{
REPO_REGEX
}
\z
}
end
end
end
end
spec/lib/gitlab/dependency_linker/composer_json_linker_spec.rb
0 → 100644
View file @
fbec6dbd
require
'rails_helper'
describe
Gitlab
::
DependencyLinker
::
ComposerJsonLinker
,
lib:
true
do
describe
'.support?'
do
it
'supports composer.json'
do
expect
(
described_class
.
support?
(
'composer.json'
)).
to
be_truthy
end
it
'does not support other files'
do
expect
(
described_class
.
support?
(
'composer.json.example'
)).
to
be_falsey
end
end
describe
'#link'
do
let
(
:file_name
)
{
"composer.json"
}
let
(
:file_content
)
do
<<-
CONTENT
.
strip_heredoc
{
"name": "laravel/laravel",
"homepage": "https://laravel.com/",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"repositories": [
{
"type": "git",
"url": "https://github.com/laravel/laravel.git"
}
],
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
}
}
CONTENT
end
subject
{
Gitlab
::
Highlight
.
highlight
(
file_name
,
file_content
)
}
def
link
(
name
,
url
)
%{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
end
it
'links the module name'
do
expect
(
subject
).
to
include
(
link
(
'laravel/laravel'
,
'https://packagist.org/packages/laravel/laravel'
))
end
it
'links the homepage'
do
expect
(
subject
).
to
include
(
link
(
'https://laravel.com/'
,
'https://laravel.com/'
))
end
it
'links the repository URL'
do
expect
(
subject
).
to
include
(
link
(
'https://github.com/laravel/laravel.git'
,
'https://github.com/laravel/laravel.git'
))
end
it
'links the license'
do
expect
(
subject
).
to
include
(
link
(
'MIT'
,
'http://choosealicense.com/licenses/mit/'
))
end
it
'links dependencies'
do
expect
(
subject
).
to
include
(
link
(
'laravel/framework'
,
'https://packagist.org/packages/laravel/framework'
))
expect
(
subject
).
to
include
(
link
(
'fzaninotto/faker'
,
'https://packagist.org/packages/fzaninotto/faker'
))
expect
(
subject
).
to
include
(
link
(
'mockery/mockery'
,
'https://packagist.org/packages/mockery/mockery'
))
expect
(
subject
).
to
include
(
link
(
'phpunit/phpunit'
,
'https://packagist.org/packages/phpunit/phpunit'
))
expect
(
subject
).
to
include
(
link
(
'symfony/css-selector'
,
'https://packagist.org/packages/symfony/css-selector'
))
expect
(
subject
).
to
include
(
link
(
'symfony/dom-crawler'
,
'https://packagist.org/packages/symfony/dom-crawler'
))
end
it
'does not link core dependencies'
do
expect
(
subject
).
not_to
include
(
link
(
'php'
,
'https://packagist.org/packages/php'
))
end
end
end
spec/lib/gitlab/dependency_linker_spec.rb
View file @
fbec6dbd
...
...
@@ -25,5 +25,13 @@ describe Gitlab::DependencyLinker, lib: true do
described_class
.
link
(
blob_name
,
nil
,
nil
)
end
it
'links using ComposerJsonLinker'
do
blob_name
=
'composer.json'
expect
(
described_class
::
ComposerJsonLinker
).
to
receive
(
:link
)
described_class
.
link
(
blob_name
,
nil
,
nil
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment