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
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
class
Gitignore
FILTER_REGEX
=
/\.gitignore\z/
.
freeze
attr_accessor
:name
,
:directory
def
initialize
(
path
)
@path
=
path
end
def
initialize
(
name
,
directory
)
@name
=
name
@directory
=
directory
def
name
File
.
basename
(
@path
,
'.gitignore'
)
end
def
content
File
.
read
(
path
)
File
.
read
(
@
path
)
end
class
<<
self
...
...
@@ -22,46 +23,33 @@ module Gitlab
file_name
=
"
#{
key
}
.gitignore"
directory
=
select_directory
(
file_name
)
directory
?
new
(
key
,
directory
)
:
nil
directory
?
new
(
File
.
join
(
directory
,
file_name
)
)
:
nil
end
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
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
private
def
path
File
.
expand_path
(
"
#{
name
}
.gitignore"
,
directory
)
end
private
class
<<
self
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
def
global_dir
File
.
expand_path
(
'Global'
,
gitignore_dir
)
File
.
join
(
gitignore_dir
,
'Global'
)
end
def
gitignore_dir
File
.
expand_path
(
'vendor/gitignore'
,
Rails
.
root
)
Rails
.
root
.
join
(
'vendor/gitignore'
)
end
def
files_for_folder
(
dir
)
gitignores
=
[]
Dir
.
entries
(
dir
).
each
do
|
e
|
next
unless
e
.
end_with?
(
'.gitignore'
)
gitignores
<<
e
.
gsub
(
FILTER_REGEX
,
''
)
end
gitignores
Dir
.
glob
(
"
#{
dir
.
to_s
}
/*.gitignore"
).
map
{
|
file
|
file
.
gsub
(
FILTER_REGEX
,
''
)
}
end
end
end
...
...
lib/tasks/gitlab/update_gitignore.rake
View file @
79620c50
namespace
:gitlab
do
desc
"GitLab | Update gitignore"
task
:update_gitignore
do
dir
=
File
.
expand_path
(
'vendor'
,
Rails
.
root
)
FileUtils
.
cd
(
dir
)
unless
clone_gitignores
puts
"Cloning the gitignores failed"
.
red
return
end
dir
=
File
.
expand_path
(
'gitignore'
,
dir
)
clone_gitignores
(
dir
)
remove_unneeded_files
(
dir
)
remove_unneeded_files
(
gitignore_directory
)
remove_unneeded_files
(
global_directory
)
puts
"Done"
.
green
end
def
clone_gitignores
(
dir
)
FileUtils
.
rm_rf
(
dir
)
if
Dir
.
exist?
(
dir
)
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
def
remove_unneeded_files
(
dir
)
[
File
.
expand_path
(
'Global'
,
dir
),
dir
].
each
do
|
path
|
Dir
.
entries
(
path
).
reject
{
|
e
|
e
=~
/(\.{1,2}|Global|\.gitignore)\z/
}.
each
do
|
file
|
FileUtils
.
rm_rf
File
.
expand_path
(
file
,
path
)
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
spec/lib/gitlab/gitignore_spec.rb
View file @
79620c50
...
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
Gitignore
do
subject
{
Gitlab
::
Gitignore
}
describe
'.all'
do
it
'strips the gitignore suffix'
do
expect
(
subject
.
all
.
first
.
name
).
not_to
end_with
(
'.gitignore'
)
...
...
@@ -24,12 +25,13 @@ describe Gitlab::Gitignore do
ruby
=
subject
.
find
(
'Ruby'
)
expect
(
ruby
).
to
be_a
Gitlab
::
Gitignore
expect
(
ruby
.
name
).
to
eq
(
'Ruby'
)
end
end
describe
'#content'
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
.
content
).
to
start_with
(
'*.gem'
)
...
...
spec/requests/api/gitignores_spec.rb
View file @
79620c50
...
...
@@ -13,8 +13,8 @@ describe API::Gitignores, api: true do
describe
'Entity GitignoresList'
do
before
{
get
api
(
'/gitignores'
)
}
it
{
expect
(
json_response
.
first
[
'name'
]).
to
be_truthy
}
it
{
expect
(
json_response
.
first
[
'content'
]).
to
be_
falsey
}
it
{
expect
(
json_response
.
first
[
'name'
]).
not_to
be_nil
}
it
{
expect
(
json_response
.
first
[
'content'
]).
to
be_
nil
}
end
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