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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
24b105e2
Commit
24b105e2
authored
May 17, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add auxiliary blob viewers to dependency files
parent
d4d9b731
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
449 additions
and
7 deletions
+449
-7
app/models/blob.rb
app/models/blob.rb
+13
-1
app/models/blob_viewer/cartfile.rb
app/models/blob_viewer/cartfile.rb
+15
-0
app/models/blob_viewer/composer_json.rb
app/models/blob_viewer/composer_json.rb
+23
-0
app/models/blob_viewer/dependency_manager.rb
app/models/blob_viewer/dependency_manager.rb
+43
-0
app/models/blob_viewer/gemfile.rb
app/models/blob_viewer/gemfile.rb
+15
-0
app/models/blob_viewer/gemspec.rb
app/models/blob_viewer/gemspec.rb
+27
-0
app/models/blob_viewer/godeps_json.rb
app/models/blob_viewer/godeps_json.rb
+15
-0
app/models/blob_viewer/package_json.rb
app/models/blob_viewer/package_json.rb
+23
-0
app/models/blob_viewer/podfile.rb
app/models/blob_viewer/podfile.rb
+15
-0
app/models/blob_viewer/podspec.rb
app/models/blob_viewer/podspec.rb
+27
-0
app/models/blob_viewer/podspec_json.rb
app/models/blob_viewer/podspec_json.rb
+9
-0
app/models/blob_viewer/requirements_txt.rb
app/models/blob_viewer/requirements_txt.rb
+15
-0
app/models/blob_viewer/yarn_lock.rb
app/models/blob_viewer/yarn_lock.rb
+15
-0
app/views/projects/blob/viewers/_dependency_manager.html.haml
...views/projects/blob/viewers/_dependency_manager.html.haml
+11
-0
app/views/projects/blob/viewers/_license.html.haml
app/views/projects/blob/viewers/_license.html.haml
+1
-1
app/views/projects/blob/viewers/_loading_auxiliary.html.haml
app/views/projects/blob/viewers/_loading_auxiliary.html.haml
+1
-1
lib/gitlab/file_detector.rb
lib/gitlab/file_detector.rb
+19
-3
spec/features/projects/blobs/blob_show_spec.rb
spec/features/projects/blobs/blob_show_spec.rb
+37
-1
spec/models/blob_viewer/composer_json_spec.rb
spec/models/blob_viewer/composer_json_spec.rb
+25
-0
spec/models/blob_viewer/gemspec_spec.rb
spec/models/blob_viewer/gemspec_spec.rb
+25
-0
spec/models/blob_viewer/package_json_spec.rb
spec/models/blob_viewer/package_json_spec.rb
+25
-0
spec/models/blob_viewer/podspec_json_spec.rb
spec/models/blob_viewer/podspec_json_spec.rb
+25
-0
spec/models/blob_viewer/podspec_spec.rb
spec/models/blob_viewer/podspec_spec.rb
+25
-0
No files found.
app/models/blob.rb
View file @
24b105e2
...
...
@@ -42,7 +42,19 @@ class Blob < SimpleDelegator
BlobViewer
::
License
,
BlobViewer
::
Contributing
,
BlobViewer
::
Changelog
BlobViewer
::
Changelog
,
BlobViewer
::
Cartfile
,
BlobViewer
::
ComposerJson
,
BlobViewer
::
Gemfile
,
BlobViewer
::
Gemspec
,
BlobViewer
::
GodepsJson
,
BlobViewer
::
PackageJson
,
BlobViewer
::
Podfile
,
BlobViewer
::
Podspec
,
BlobViewer
::
PodspecJson
,
BlobViewer
::
RequirementsTxt
,
BlobViewer
::
YarnLock
].
freeze
attr_reader
:project
...
...
app/models/blob_viewer/cartfile.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
Cartfile
<
DependencyManager
include
Static
self
.
file_types
=
%i(cartfile)
def
manager_name
'Carthage'
end
def
manager_url
'https://github.com/Carthage/Carthage'
end
end
end
app/models/blob_viewer/composer_json.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
ComposerJson
<
DependencyManager
include
ServerSide
self
.
file_types
=
%i(composer_json)
def
manager_name
'Composer'
end
def
manager_url
'https://getcomposer.com/'
end
def
package_name
@package_name
||=
package_name_from_json
(
'name'
)
end
def
package_url
"https://packagist.org/packages/
#{
package_name
}
"
end
end
end
app/models/blob_viewer/dependency_manager.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
DependencyManager
<
Base
include
Auxiliary
self
.
partial_name
=
'dependency_manager'
self
.
binary
=
false
def
manager_name
raise
NotImplementedError
end
def
manager_url
raise
NotImplementedError
end
def
package_type
'package'
end
def
package_name
nil
end
def
package_url
nil
end
private
def
package_name_from_json
(
key
)
prepare!
JSON
.
parse
(
blob
.
data
)[
key
]
rescue
nil
end
def
package_name_from_method_call
(
name
)
prepare!
match
=
blob
.
data
.
match
(
/
#{
name
}
\s*=\s*["'](?<name>[^"']+)["']/
)
match
[
:name
]
if
match
end
end
end
app/models/blob_viewer/gemfile.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
Gemfile
<
DependencyManager
include
Static
self
.
file_types
=
%i(gemfile gemfile_lock)
def
manager_name
'Bundler'
end
def
manager_url
'http://bundler.io/'
end
end
end
app/models/blob_viewer/gemspec.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
Gemspec
<
DependencyManager
include
ServerSide
self
.
file_types
=
%i(gemspec)
def
manager_name
'RubyGems'
end
def
manager_url
'https://rubygems.org/'
end
def
package_type
'gem'
end
def
package_name
@package_name
||=
package_name_from_method_call
(
'name'
)
end
def
package_url
"https://rubygems.org/gems/
#{
package_name
}
"
end
end
end
app/models/blob_viewer/godeps_json.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
GodepsJson
<
DependencyManager
include
Static
self
.
file_types
=
%i(godeps_json)
def
manager_name
'godep'
end
def
manager_url
'https://github.com/tools/godep'
end
end
end
app/models/blob_viewer/package_json.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
PackageJson
<
DependencyManager
include
ServerSide
self
.
file_types
=
%i(package_json)
def
manager_name
'npm'
end
def
manager_url
'https://www.npmjs.com/'
end
def
package_name
@package_name
||=
package_name_from_json
(
'name'
)
end
def
package_url
"https://www.npmjs.com/package/
#{
package_name
}
"
end
end
end
app/models/blob_viewer/podfile.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
Podfile
<
DependencyManager
include
Static
self
.
file_types
=
%i(podfile)
def
manager_name
'CocoaPods'
end
def
manager_url
'https://cocoapods.org/'
end
end
end
app/models/blob_viewer/podspec.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
Podspec
<
DependencyManager
include
ServerSide
self
.
file_types
=
%i(podspec)
def
manager_name
'CocoaPods'
end
def
manager_url
'https://cocoapods.org/'
end
def
package_type
'pod'
end
def
package_name
@package_name
||=
package_name_from_method_call
(
'name'
)
end
def
package_url
"https://cocoapods.org/pods/
#{
package_name
}
"
end
end
end
app/models/blob_viewer/podspec_json.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
PodspecJson
<
Podspec
self
.
file_types
=
%i(podspec_json)
def
package_name
@package_name
||=
package_name_from_json
(
'name'
)
end
end
end
app/models/blob_viewer/requirements_txt.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
RequirementsTxt
<
DependencyManager
include
Static
self
.
file_types
=
%i(requirements_txt)
def
manager_name
'pip'
end
def
manager_url
'https://pip.pypa.io/'
end
end
end
app/models/blob_viewer/yarn_lock.rb
0 → 100644
View file @
24b105e2
module
BlobViewer
class
YarnLock
<
DependencyManager
include
Static
self
.
file_types
=
%i(yarn_lock)
def
manager_name
'Yarn'
end
def
manager_url
'https://yarnpkg.com/'
end
end
end
app/views/projects/blob/viewers/_dependency_manager.html.haml
0 → 100644
View file @
24b105e2
=
icon
(
'cubes fw'
)
=
succeed
'.'
do
This project manages its dependencies using
%strong
=
viewer
.
manager_name
-
if
viewer
.
package_name
and defines a
#{
viewer
.
package_type
}
named
%strong<
=
link_to
viewer
.
package_name
,
viewer
.
package_url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
=
link_to
'Learn more'
,
viewer
.
manager_url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
app/views/projects/blob/viewers/_license.html.haml
View file @
24b105e2
...
...
@@ -5,4 +5,4 @@ This project is licensed under the
=
succeed
'.'
do
%strong
=
license
.
name
=
link_to
'Learn more
about this license
'
,
license
.
url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
=
link_to
'Learn more'
,
license
.
url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
app/views/projects/blob/viewers/_loading_auxiliary.html.haml
View file @
24b105e2
=
icon
(
'spinner spin fw'
)
Loading
…
Analyzing file
…
lib/gitlab/file_detector.rb
View file @
24b105e2
...
...
@@ -5,17 +5,33 @@ module Gitlab
# a README or a CONTRIBUTING file.
module
FileDetector
PATTERNS
=
{
# Project files
readme:
/\Areadme/i
,
changelog:
/\A(changelog|history|changes|news)/i
,
license:
/\A(licen[sc]e|copying)(\..+|\z)/i
,
contributing:
/\Acontributing/i
,
version:
'version'
,
avatar:
/\Alogo\.(png|jpg|gif)\z/
,
# Configuration files
gitignore:
'.gitignore'
,
koding:
'.koding.yml'
,
gemfile:
/\A(Gemfile|gems\.rb)\z/
,
gitlab_ci:
'.gitlab-ci.yml'
,
avatar:
/\Alogo\.(png|jpg|gif)\z/
,
route_map:
'route-map.yml'
route_map:
'route-map.yml'
,
# Dependency files
cartfile:
/\ACartfile/
,
composer_json:
'composer.json'
,
gemfile:
/\A(Gemfile|gems\.rb)\z/
,
gemfile_lock:
'Gemfile.lock'
,
gemspec:
/\.gemspec\z/
,
godeps_json:
'Godeps.json'
,
package_json:
'package.json'
,
podfile:
'Podfile'
,
podspec_json:
/\.podspec\.json\z/
,
podspec:
/\.podspec\z/
,
requirements_txt:
/requirements\.txt\z/
,
yarn_lock:
'yarn.lock'
}.
freeze
# Returns an Array of file types based on the given paths.
...
...
spec/features/projects/blobs/blob_show_spec.rb
View file @
24b105e2
...
...
@@ -423,7 +423,43 @@ feature 'File blob', :js, feature: true do
expect
(
page
).
to
have_content
(
'This project is licensed under the MIT License.'
)
# shows a learn more link
expect
(
page
).
to
have_link
(
'Learn more about this license'
,
'http://choosealicense.com/licenses/mit/'
)
expect
(
page
).
to
have_link
(
'Learn more'
,
'http://choosealicense.com/licenses/mit/'
)
end
end
end
context
'*.gemspec'
do
before
do
project
.
add_master
(
project
.
creator
)
Files
::
CreateService
.
new
(
project
,
project
.
creator
,
start_branch:
'master'
,
branch_name:
'master'
,
commit_message:
"Add activerecord.gemspec"
,
file_path:
'activerecord.gemspec'
,
file_content:
<<-
SPEC
.
strip_heredoc
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = "activerecord"
end
SPEC
).
execute
visit_blob
(
'activerecord.gemspec'
)
end
it
'displays an auxiliary viewer'
do
aggregate_failures
do
# shows license
expect
(
page
).
to
have_content
(
'This project manages its dependencies using RubyGems and defines a gem named activerecord.'
)
# shows a link to the gem
expect
(
page
).
to
have_link
(
'activerecord'
,
'https://rubygems.org/gems/activerecord'
)
# shows a learn more link
expect
(
page
).
to
have_link
(
'Learn more'
,
'http://choosealicense.com/licenses/mit/'
)
end
end
end
...
...
spec/models/blob_viewer/composer_json_spec.rb
0 → 100644
View file @
24b105e2
require
'spec_helper'
describe
BlobViewer
::
ComposerJson
,
model:
true
do
include
FakeBlobHelpers
let
(
:project
)
{
build
(
:project
)
}
let
(
:data
)
do
<<-
SPEC
.
strip_heredoc
{
"name": "laravel/laravel",
"homepage": "https://laravel.com/"
}
SPEC
end
let
(
:blob
)
{
fake_blob
(
path:
'composer.json'
,
data:
data
)
}
subject
{
described_class
.
new
(
blob
)
}
describe
'#package_name'
do
it
'returns the package name'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_name
).
to
eq
(
'laravel/laravel'
)
end
end
end
spec/models/blob_viewer/gemspec_spec.rb
0 → 100644
View file @
24b105e2
require
'spec_helper'
describe
BlobViewer
::
Gemspec
,
model:
true
do
include
FakeBlobHelpers
let
(
:project
)
{
build
(
:project
)
}
let
(
:data
)
do
<<-
SPEC
.
strip_heredoc
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = "activerecord"
end
SPEC
end
let
(
:blob
)
{
fake_blob
(
path:
'activerecord.gemspec'
,
data:
data
)
}
subject
{
described_class
.
new
(
blob
)
}
describe
'#package_name'
do
it
'returns the package name'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_name
).
to
eq
(
'activerecord'
)
end
end
end
spec/models/blob_viewer/package_json_spec.rb
0 → 100644
View file @
24b105e2
require
'spec_helper'
describe
BlobViewer
::
PackageJson
,
model:
true
do
include
FakeBlobHelpers
let
(
:project
)
{
build
(
:project
)
}
let
(
:data
)
do
<<-
SPEC
.
strip_heredoc
{
"name": "module-name",
"version": "10.3.1"
}
SPEC
end
let
(
:blob
)
{
fake_blob
(
path:
'package.json'
,
data:
data
)
}
subject
{
described_class
.
new
(
blob
)
}
describe
'#package_name'
do
it
'returns the package name'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_name
).
to
eq
(
'module-name'
)
end
end
end
spec/models/blob_viewer/podspec_json_spec.rb
0 → 100644
View file @
24b105e2
require
'spec_helper'
describe
BlobViewer
::
PodspecJson
,
model:
true
do
include
FakeBlobHelpers
let
(
:project
)
{
build
(
:project
)
}
let
(
:data
)
do
<<-
SPEC
.
strip_heredoc
{
"name": "AFNetworking",
"version": "2.0.0"
}
SPEC
end
let
(
:blob
)
{
fake_blob
(
path:
'AFNetworking.podspec.json'
,
data:
data
)
}
subject
{
described_class
.
new
(
blob
)
}
describe
'#package_name'
do
it
'returns the package name'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_name
).
to
eq
(
'AFNetworking'
)
end
end
end
spec/models/blob_viewer/podspec_spec.rb
0 → 100644
View file @
24b105e2
require
'spec_helper'
describe
BlobViewer
::
Podspec
,
model:
true
do
include
FakeBlobHelpers
let
(
:project
)
{
build
(
:project
)
}
let
(
:data
)
do
<<-
SPEC
.
strip_heredoc
Pod::Spec.new do |spec|
spec.name = 'Reachability'
spec.version = '3.1.0'
end
SPEC
end
let
(
:blob
)
{
fake_blob
(
path:
'Reachability.podspec'
,
data:
data
)
}
subject
{
described_class
.
new
(
blob
)
}
describe
'#package_name'
do
it
'returns the package name'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_name
).
to
eq
(
'Reachability'
)
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