BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
27bf7ae5
Commit
27bf7ae5
authored
May 27, 2016
by
ZJ van de Weg
Committed by
Alfredo Sumaran
Jun 20, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Gitlab::Gitignores
parent
74f8f260
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
158 additions
and
118 deletions
+158
-118
blob_helper.rb
app/helpers/blob_helper.rb
+3
-5
api.rb
lib/api/api.rb
+1
-1
entities.rb
lib/api/entities.rb
+2
-2
templates.rb
lib/api/templates.rb
+27
-21
base_template.rb
lib/gitlab/template/base_template.rb
+37
-39
gitignore.rb
lib/gitlab/template/gitignore.rb
+23
-0
update_gitignore.rake
lib/tasks/gitlab/update_gitignore.rake
+0
-46
update_templates.rake
lib/tasks/gitlab/update_templates.rake
+61
-0
gitignore_spec.rb
spec/lib/gitlab/template/gitignore_spec.rb
+3
-3
gitignores_spec.rb
spec/requests/api/gitignores_spec.rb
+1
-1
No files found.
app/helpers/blob_helper.rb
View file @
27bf7ae5
...
...
@@ -188,10 +188,8 @@ module BlobHelper
def
gitignore_names
return
@gitignore_names
if
defined?
(
@gitignore_names
)
@gitignore_names
=
{
Global
:
Gitlab
::
Gitignore
.
global
.
map
{
|
gitignore
|
{
name:
gitignore
.
name
}
},
# Note that the key here doesn't cover it really
Languages
:
Gitlab
::
Gitignore
.
languages_frameworks
.
map
{
|
gitignore
|
{
name:
gitignore
.
name
}
}
}
@gitignore_names
=
Gitlab
::
Template
::
Gitignore
.
categories
.
map
do
|
k
,
_
|
[
k
,
Gitlab
::
Template
::
Gitignore
.
by_category
(
k
)]
end
.
to_h
end
end
lib/api/api.rb
View file @
27bf7ae5
...
...
@@ -33,7 +33,6 @@ module API
mount
::
API
::
Commits
mount
::
API
::
DeployKeys
mount
::
API
::
Files
mount
::
API
::
Gitignores
mount
::
API
::
GroupMembers
mount
::
API
::
Groups
mount
::
API
::
Internal
...
...
@@ -58,6 +57,7 @@ module API
mount
::
API
::
Subscriptions
mount
::
API
::
SystemHooks
mount
::
API
::
Tags
mount
::
API
::
Templates
mount
::
API
::
Triggers
mount
::
API
::
Users
mount
::
API
::
Variables
...
...
lib/api/entities.rb
View file @
27bf7ae5
...
...
@@ -472,11 +472,11 @@ module API
expose
:content
end
class
Gitignor
esList
<
Grape
::
Entity
class
Templat
esList
<
Grape
::
Entity
expose
:name
end
class
Gitignor
e
<
Grape
::
Entity
class
Templat
e
<
Grape
::
Entity
expose
:name
,
:content
end
end
...
...
lib/api/
gitignor
es.rb
→
lib/api/
templat
es.rb
View file @
27bf7ae5
module
API
class
Gitignores
<
Grape
::
API
class
Templates
<
Grape
::
API
TEMPLATE_TYPES
=
{
gitignores:
Gitlab
::
Template
::
Gitignore
}.
freeze
# Get the list of the available gitignore templates
#
# Example Request:
# GET /gitignores
get
'gitignores'
do
present
Gitlab
::
Gitignore
.
all
,
with:
Entities
::
GitignoresList
end
TEMPLATE_TYPES
.
each
do
|
template
,
klass
|
# Get the list of the available template
#
# Example Request:
# GET /gitignores
# GET /gitlab_ci_ymls
get
template
.
to_s
do
present
klass
.
all
,
with:
Entities
::
TemplatesList
end
# Get the text for a specific gitignor
e
#
# Parameters:
# name (required) - The name of a licens
e
#
# Example Request:
# GET /gitignores/Elixir
#
get
'gitignores/:name'
do
required_attributes!
[
:name
]
# Get the text for a specific templat
e
#
# Parameters:
# name (required) - The name of a templat
e
#
# Example Request:
# GET /gitignores/Elixir
# GET /gitlab_ci_ymls/Ruby
get
"
#{
template
}
/:name"
do
required_attributes!
[
:name
]
gitignore
=
Gitlab
::
Gitignore
.
find
(
params
[
:name
])
not_found!
(
'.gitignore'
)
unless
gitignor
e
new_template
=
klass
.
find
(
params
[
:name
])
not_found!
(
"
#{
template
.
to_s
.
singularize
}
"
)
unless
new_templat
e
present
gitignore
,
with:
Entities
::
Gitignore
present
new_template
,
with:
Entities
::
Template
end
end
end
end
lib/gitlab/
gitignor
e.rb
→
lib/gitlab/
template/base_templat
e.rb
View file @
27bf7ae5
module
Gitlab
class
Gitignore
FILTER_REGEX
=
/\.gitignore\z/
.
freeze
def
initialize
(
path
)
@path
=
path
end
def
name
File
.
basename
(
@path
,
'.gitignore'
)
end
module
Template
class
BaseTemplate
def
initialize
(
path
)
@path
=
path
end
def
content
File
.
read
(
@path
)
end
def
name
File
.
basename
(
@path
,
self
.
class
.
extension
)
end
class
<<
self
def
all
languages_frameworks
+
global
def
content
File
.
read
(
@path
)
end
def
find
(
key
)
file_name
=
"
#{
key
}
.gitignore"
class
<<
self
def
all
self
.
category_directories
.
flat_map
do
|
dir
|
templates_for_folder
(
dir
)
end
end
directory
=
select_directory
(
file_name
)
directory
?
new
(
File
.
join
(
directory
,
file_name
))
:
nil
end
def
find
(
key
)
file_name
=
"
#{
key
}#{
self
.
extension
}
"
def
global
files_for_folder
(
global_dir
).
map
{
|
file
|
new
(
File
.
join
(
global_dir
,
file
))
}
end
directory
=
select_directory
(
file_name
)
directory
?
new
(
File
.
join
(
directory
,
file_name
))
:
nil
end
def
languages_frameworks
files_for_folder
(
gitignore_dir
).
map
{
|
file
|
new
(
File
.
join
(
gitignore_dir
,
file
))
}
end
def
by_category
(
category
)
templates_for_folder
(
categories
[
category
])
end
private
def
category_directories
self
.
categories
.
values
.
map
{
|
subdir
|
File
.
join
(
base_dir
,
subdir
)}
end
def
select_directory
(
file_name
)
[
gitignore_dir
,
global_dir
].
find
{
|
dir
|
File
.
exist?
(
File
.
join
(
dir
,
file_name
))
}
end
private
def
global_dir
File
.
join
(
gitignore_dir
,
'Global'
)
end
def
select_directory
(
file_name
)
category_directories
.
find
{
|
dir
|
File
.
exist?
(
File
.
join
(
dir
,
file_name
))
}
end
def
gitignore_dir
Rails
.
root
.
join
(
'vendor/gitignore'
)
end
def
templates_for_folder
(
dir
)
Dir
.
glob
(
"
#{
dir
.
to_s
}
/*
#{
self
.
extension
}
"
).
select
{
|
f
|
f
=~
filter_regex
}.
map
{
|
f
|
new
(
f
)
}
end
def
files_for_folder
(
dir
)
Dir
.
glob
(
"
#{
dir
.
to_s
}
/*.gitignore"
).
map
{
|
file
|
file
.
gsub
(
FILTER_REGEX
,
''
)
}
def
filter_regex
/
#{
Regexp
.
escape
(
extension
)
}
\z/
end
end
end
end
...
...
lib/gitlab/template/gitignore.rb
0 → 100644
View file @
27bf7ae5
module
Gitlab
module
Template
class
Gitignore
<
BaseTemplate
class
<<
self
def
extension
'.gitignore'
end
def
categories
{
Languages
:
''
,
Global
:
'Global'
}
end
def
base_dir
Rails
.
root
.
join
(
'vendor/gitignore'
)
end
end
end
end
end
lib/tasks/gitlab/update_gitignore.rake
deleted
100644 → 0
View file @
74f8f260
namespace
:gitlab
do
desc
"GitLab | Update gitignore"
task
:update_gitignore
do
unless
clone_gitignores
puts
"Cloning the gitignores failed"
.
color
(
:red
)
return
end
remove_unneeded_files
(
gitignore_directory
)
remove_unneeded_files
(
global_directory
)
puts
"Done"
.
color
(
:green
)
end
def
clone_gitignores
FileUtils
.
rm_rf
(
gitignore_directory
)
if
Dir
.
exist?
(
gitignore_directory
)
FileUtils
.
cd
vendor_directory
system
(
'git clone --depth=1 --branch=master https://github.com/github/gitignore.git'
)
end
# Retain only certain files:
# - The LICENSE, because we have to
# - The sub dir global
# - The gitignores themself
# - Dir.entires returns also the entries '.' and '..'
def
remove_unneeded_files
(
path
)
Dir
.
foreach
(
path
)
do
|
file
|
FileUtils
.
rm_rf
(
File
.
join
(
path
,
file
))
unless
file
=~
/(\.{1,2}|LICENSE|Global|\.gitignore)\z/
end
end
private
def
vendor_directory
Rails
.
root
.
join
(
'vendor'
)
end
def
gitignore_directory
File
.
join
(
vendor_directory
,
'gitignore'
)
end
def
global_directory
File
.
join
(
gitignore_directory
,
'Global'
)
end
end
lib/tasks/gitlab/update_templates.rake
0 → 100644
View file @
27bf7ae5
namespace
:gitlab
do
desc
"GitLab | Update templates"
task
:update_templates
do
update
(
"gitignore"
)
update
(
"gitlab-ci-yml"
)
end
def
update
(
directory
)
unless
clone_repository
(
directory
)
puts
"Cloning the
#{
directory
}
templates failed"
.
red
return
end
remove_unneeded_files
(
directory
)
puts
"Done"
.
green
end
def
clone_repository
(
directory
)
dir
=
File
.
join
(
vendor_directory
,
directory
)
FileUtils
.
rm_rf
(
dir
)
if
Dir
.
exist?
(
dir
)
FileUtils
.
cd
vendor_directory
system
(
"git clone --depth=1 --branch=master
#{
TEMPLATE_DATA
[
directory
]
}
"
)
end
# Retain only certain files:
# - The LICENSE, because we have to
# - The sub dir global
# - The gitignores themself
# - Dir.entires returns also the entries '.' and '..'
def
remove_unneeded_files
(
directory
)
regex
=
CLEANUP_REGEX
[
directory
]
Dir
.
foreach
(
directory
)
do
|
file
|
FileUtils
.
rm_rf
(
File
.
join
(
directory
,
file
))
unless
file
=~
regex
end
end
private
TEMPLATE_DATA
=
{
"gitignore"
=>
"https://github.com/github/gitignore.git"
,
"gitlab-ci-yml"
=>
"https://gitlab.com/gitlab-org/gitlab-ci-yml.git"
}.
freeze
CLEANUP_REGEX
=
{
"gitignore"
=>
/(\.{1,2}|LICENSE|Global|\.gitignore)\z/
,
"gitlab-ci-yml"
=>
/(\.{1,2}|LICENSE|Pages|\.gitignore)\z/
}.
freeze
def
vendor_directory
Rails
.
root
.
join
(
'vendor'
)
end
def
gitignore_directory
File
.
join
(
vendor_directory
,
'gitignore'
)
end
def
gitlab_ci_directory
File
.
join
(
vendor_directory
,
'gitlab-ci'
)
end
end
spec/lib/gitlab/gitignore_spec.rb
→
spec/lib/gitlab/
template/
gitignore_spec.rb
View file @
27bf7ae5
require
'spec_helper'
describe
Gitlab
::
Gitignore
do
subject
{
Gitlab
::
Gitignore
}
describe
Gitlab
::
Template
::
Gitignore
do
subject
{
described_class
}
describe
'.all'
do
it
'strips the gitignore suffix'
do
...
...
@@ -24,7 +24,7 @@ describe Gitlab::Gitignore do
it
'returns the Gitignore object of a valid file'
do
ruby
=
subject
.
find
(
'Ruby'
)
expect
(
ruby
).
to
be_a
Gitlab
::
Gitignore
expect
(
ruby
).
to
be_a
Gitlab
::
Template
::
Gitignore
expect
(
ruby
.
name
).
to
eq
(
'Ruby'
)
end
end
...
...
spec/requests/api/gitignores_spec.rb
View file @
27bf7ae5
require
'spec_helper'
describe
API
::
Gitignor
es
,
api:
true
do
describe
API
::
Templat
es
,
api:
true
do
include
ApiHelpers
describe
'Entity Gitignore'
do
...
...
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