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
Jérome Perrin
gitlab-ce
Commits
79620c50
Commit
79620c50
authored
May 12, 2016
by
Zeger-Jan van de Weg
Committed by
Alfredo Sumaran
May 20, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update API and fetching task
parent
1f5fcb63
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
41 deletions
+51
-41
lib/gitlab/gitignore.rb
lib/gitlab/gitignore.rb
+14
-26
lib/tasks/gitlab/update_gitignore.rake
lib/tasks/gitlab/update_gitignore.rake
+32
-12
spec/lib/gitlab/gitignore_spec.rb
spec/lib/gitlab/gitignore_spec.rb
+3
-1
spec/requests/api/gitignores_spec.rb
spec/requests/api/gitignores_spec.rb
+2
-2
No files found.
lib/gitlab/gitignore.rb
View file @
79620c50
...
@@ -2,15 +2,16 @@ module Gitlab
...
@@ -2,15 +2,16 @@ module Gitlab
class
Gitignore
class
Gitignore
FILTER_REGEX
=
/\.gitignore\z/
.
freeze
FILTER_REGEX
=
/\.gitignore\z/
.
freeze
attr_accessor
:name
,
:directory
def
initialize
(
path
)
@path
=
path
end
def
initialize
(
name
,
directory
)
def
name
@name
=
name
File
.
basename
(
@path
,
'.gitignore'
)
@directory
=
directory
end
end
def
content
def
content
File
.
read
(
path
)
File
.
read
(
@
path
)
end
end
class
<<
self
class
<<
self
...
@@ -22,46 +23,33 @@ module Gitlab
...
@@ -22,46 +23,33 @@ module Gitlab
file_name
=
"
#{
key
}
.gitignore"
file_name
=
"
#{
key
}
.gitignore"
directory
=
select_directory
(
file_name
)
directory
=
select_directory
(
file_name
)
directory
?
new
(
key
,
directory
)
:
nil
directory
?
new
(
File
.
join
(
directory
,
file_name
)
)
:
nil
end
end
def
global
def
global
files_for_folder
(
global_dir
).
map
{
|
f
|
new
(
f
,
global_dir
)
}
files_for_folder
(
global_dir
).
map
{
|
f
ile
|
new
(
File
.
join
(
global_dir
,
file
)
)
}
end
end
def
languages_frameworks
def
languages_frameworks
files_for_folder
(
gitignore_dir
).
map
{
|
f
|
new
(
f
,
gitignore_dir
)
}
files_for_folder
(
gitignore_dir
).
map
{
|
f
ile
|
new
(
File
.
join
(
gitignore_dir
,
file
)
)
}
end
end
end
private
private
def
path
File
.
expand_path
(
"
#{
name
}
.gitignore"
,
directory
)
end
class
<<
self
def
select_directory
(
file_name
)
def
select_directory
(
file_name
)
[
self
.
gitignore_dir
,
self
.
global_dir
].
find
{
|
dir
|
File
.
exist?
(
File
.
expand_path
(
file_name
,
dir
))
}
[
gitignore_dir
,
global_dir
].
find
{
|
dir
|
File
.
exist?
(
File
.
join
(
dir
,
file_name
))
}
end
end
def
global_dir
def
global_dir
File
.
expand_path
(
'Global'
,
gitignore_dir
)
File
.
join
(
gitignore_dir
,
'Global'
)
end
end
def
gitignore_dir
def
gitignore_dir
File
.
expand_path
(
'vendor/gitignore'
,
Rails
.
root
)
Rails
.
root
.
join
(
'vendor/gitignore'
)
end
end
def
files_for_folder
(
dir
)
def
files_for_folder
(
dir
)
gitignores
=
[]
Dir
.
glob
(
"
#{
dir
.
to_s
}
/*.gitignore"
).
map
{
|
file
|
file
.
gsub
(
FILTER_REGEX
,
''
)
}
Dir
.
entries
(
dir
).
each
do
|
e
|
next
unless
e
.
end_with?
(
'.gitignore'
)
gitignores
<<
e
.
gsub
(
FILTER_REGEX
,
''
)
end
gitignores
end
end
end
end
end
end
...
...
lib/tasks/gitlab/update_gitignore.rake
View file @
79620c50
namespace
:gitlab
do
namespace
:gitlab
do
desc
"GitLab | Update gitignore"
desc
"GitLab | Update gitignore"
task
:update_gitignore
do
task
:update_gitignore
do
dir
=
File
.
expand_path
(
'vendor'
,
Rails
.
root
)
unless
clone_gitignores
FileUtils
.
cd
(
dir
)
puts
"Cloning the gitignores failed"
.
red
return
end
dir
=
File
.
expand_path
(
'gitignore'
,
dir
)
remove_unneeded_files
(
gitignore_directory
)
clone_gitignores
(
dir
)
remove_unneeded_files
(
global_directory
)
remove_unneeded_files
(
dir
)
puts
"Done"
.
green
puts
"Done"
.
green
end
end
def
clone_gitignores
(
dir
)
def
clone_gitignores
FileUtils
.
rm_rf
(
dir
)
if
Dir
.
exist?
(
dir
)
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'
)
system
(
'git clone --depth=1 --branch=master https://github.com/github/gitignore.git'
)
end
end
def
remove_unneeded_files
(
dir
)
# Retain only certain files:
[
File
.
expand_path
(
'Global'
,
dir
),
dir
].
each
do
|
path
|
# - The LICENSE, because we have to
Dir
.
entries
(
path
).
reject
{
|
e
|
e
=~
/(\.{1,2}|Global|\.gitignore)\z/
}.
each
do
|
file
|
# - The sub dir global
FileUtils
.
rm_rf
File
.
expand_path
(
file
,
path
)
# - The gitignores themself
end
# - 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
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
end
spec/lib/gitlab/gitignore_spec.rb
View file @
79620c50
...
@@ -2,6 +2,7 @@ require 'spec_helper'
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
Gitignore
do
describe
Gitlab
::
Gitignore
do
subject
{
Gitlab
::
Gitignore
}
subject
{
Gitlab
::
Gitignore
}
describe
'.all'
do
describe
'.all'
do
it
'strips the gitignore suffix'
do
it
'strips the gitignore suffix'
do
expect
(
subject
.
all
.
first
.
name
).
not_to
end_with
(
'.gitignore'
)
expect
(
subject
.
all
.
first
.
name
).
not_to
end_with
(
'.gitignore'
)
...
@@ -24,12 +25,13 @@ describe Gitlab::Gitignore do
...
@@ -24,12 +25,13 @@ describe Gitlab::Gitignore do
ruby
=
subject
.
find
(
'Ruby'
)
ruby
=
subject
.
find
(
'Ruby'
)
expect
(
ruby
).
to
be_a
Gitlab
::
Gitignore
expect
(
ruby
).
to
be_a
Gitlab
::
Gitignore
expect
(
ruby
.
name
).
to
eq
(
'Ruby'
)
end
end
end
end
describe
'#content'
do
describe
'#content'
do
it
'loads the full file'
do
it
'loads the full file'
do
gitignore
=
subject
.
new
(
'Ruby'
,
File
.
expand_path
(
'vendor/gitignore'
,
Rails
.
root
))
gitignore
=
subject
.
new
(
Rails
.
root
.
join
(
'vendor/gitignore/Ruby.gitignore'
))
expect
(
gitignore
.
name
).
to
eq
'Ruby'
expect
(
gitignore
.
name
).
to
eq
'Ruby'
expect
(
gitignore
.
content
).
to
start_with
(
'*.gem'
)
expect
(
gitignore
.
content
).
to
start_with
(
'*.gem'
)
...
...
spec/requests/api/gitignores_spec.rb
View file @
79620c50
...
@@ -13,8 +13,8 @@ describe API::Gitignores, api: true do
...
@@ -13,8 +13,8 @@ describe API::Gitignores, api: true do
describe
'Entity GitignoresList'
do
describe
'Entity GitignoresList'
do
before
{
get
api
(
'/gitignores'
)
}
before
{
get
api
(
'/gitignores'
)
}
it
{
expect
(
json_response
.
first
[
'name'
]).
to
be_truthy
}
it
{
expect
(
json_response
.
first
[
'name'
]).
not_to
be_nil
}
it
{
expect
(
json_response
.
first
[
'content'
]).
to
be_
falsey
}
it
{
expect
(
json_response
.
first
[
'content'
]).
to
be_
nil
}
end
end
describe
'GET /gitignores'
do
describe
'GET /gitignores'
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