Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
e166a802
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e166a802
编写于
4月 29, 2016
作者:
Z
Zeger-Jan van de Weg
提交者:
Alfredo Sumaran
5月 20, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Backend for a gitignores dropdown
上级
56eb4200
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
227 addition
and
9 deletion
+227
-9
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+4
-0
app/models/repository.rb
app/models/repository.rb
+14
-6
app/views/projects/blob/_editor.html.haml
app/views/projects/blob/_editor.html.haml
+3
-0
app/views/projects/empty.html.haml
app/views/projects/empty.html.haml
+7
-3
lib/api/api.rb
lib/api/api.rb
+1
-0
lib/api/entities.rb
lib/api/entities.rb
+8
-0
lib/api/gitignores.rb
lib/api/gitignores.rb
+29
-0
lib/gitlab/gitignore.rb
lib/gitlab/gitignore.rb
+68
-0
lib/tasks/gitlab/update_gitignore.rake
lib/tasks/gitlab/update_gitignore.rake
+26
-0
spec/lib/gitlab/gitignore_spec.rb
spec/lib/gitlab/gitignore_spec.rb
+38
-0
spec/requests/api/gitignores_spec.rb
spec/requests/api/gitignores_spec.rb
+29
-0
未找到文件。
app/helpers/blob_helper.rb
浏览文件 @
e166a802
...
...
@@ -184,4 +184,8 @@ module BlobHelper
Other
:
licenses
.
reject
(
&
:featured
).
map
{
|
license
|
[
license
.
name
,
license
.
key
]
}
}
end
def
gitignores_for_select
@gitignores_for_select
||=
Gitlab
::
Gitignore
.
all
end
end
app/models/repository.rb
浏览文件 @
e166a802
...
...
@@ -472,9 +472,7 @@ class Repository
def
changelog
cache
.
fetch
(
:changelog
)
do
tree
(
:head
).
blobs
.
find
do
|
file
|
file
.
name
=~
/\A(changelog|history|changes|news)/i
end
file_on_head
(
/\A(changelog|history|changes|news)/i
)
end
end
...
...
@@ -482,9 +480,7 @@ class Repository
return
nil
unless
head_exists?
cache
.
fetch
(
:license_blob
)
do
tree
(
:head
).
blobs
.
find
do
|
file
|
file
.
name
=~
/\A(licen[sc]e|copying)(\..+|\z)/i
end
file_on_head
(
/\A(licen[sc]e|copying)(\..+|\z)/i
)
end
end
...
...
@@ -496,6 +492,14 @@ class Repository
end
end
def
gitignore
return
nil
if
!
exists?
||
empty?
cache
.
fetch
(
:gitignore
)
do
file_on_head
(
/\A\.gitignore\z/
)
end
end
def
gitlab_ci_yml
return
nil
unless
head_exists?
...
...
@@ -989,4 +993,8 @@ class Repository
def
head_exists?
exists?
&&
!
empty?
&&
!
rugged
.
head_unborn?
end
def
file_on_head
(
regex
)
tree
(
:head
).
blobs
.
find
{
|
file
|
file
.
name
=~
regex
}
end
end
app/views/projects/blob/_editor.html.haml
浏览文件 @
e166a802
...
...
@@ -16,6 +16,9 @@
.license-selector.js-license-selector.hide
=
select_tag
:license_type
,
grouped_options_for_select
(
licenses_for_select
,
@project
.
repository
.
license_key
),
include_blank:
true
,
class:
'select2 license-select'
,
data:
{
placeholder:
'Choose a license template'
,
project:
@project
.
name
,
fullname:
@project
.
namespace
.
human_name
}
.gitignore-selector.js-gitignore-selector.hide
=
select_tag
:gitignore_template
,
options_for_select
(
Gitlab
::
Gitignore
.
all
),
include_blank:
true
,
class:
'select2 gitignore-select'
,
data:
{
placeholder:
'Choose a .gitignore template'
}
.encoding-selector
=
select_tag
:encoding
,
options_for_select
([
"base64"
,
"text"
],
"text"
),
class:
'select2'
...
...
app/views/projects/empty.html.haml
浏览文件 @
e166a802
...
...
@@ -15,10 +15,14 @@
If you already have files you can push them using command line instructions below.
%p
Otherwise you can start with adding a
=
link_to
"README"
,
new_readme_path
,
class:
'underlined-link'
=
succeed
','
do
=
link_to
"README"
,
new_readme_path
,
class:
'underlined-link'
a
=
succeed
','
do
=
link_to
"LICENSE"
,
add_special_file_path
(
@project
,
file_name:
'LICENSE'
),
class:
'underlined-link'
or a
=
link_to
"LICENSE"
,
add_special_file_path
(
@project
,
file_name:
'LICENSE
'
),
class:
'underlined-link'
file
to this project.
=
link_to
'.gitignore'
,
add_special_file_path
(
@project
,
file_name:
'.gitignore
'
),
class:
'underlined-link'
to this project.
-
if
can?
(
current_user
,
:push_code
,
@project
)
%div
{
class:
container_class
}
...
...
lib/api/api.rb
浏览文件 @
e166a802
...
...
@@ -58,5 +58,6 @@ module API
mount
::
API
::
Runners
mount
::
API
::
Licenses
mount
::
API
::
Subscriptions
mount
::
API
::
Gitignores
end
end
lib/api/entities.rb
浏览文件 @
e166a802
...
...
@@ -457,5 +457,13 @@ module API
expose
(
:limitations
)
{
|
license
|
license
.
meta
[
'limitations'
]
}
expose
:content
end
class
GitignoresList
<
Grape
::
Entity
expose
:name
end
class
Gitignore
<
Grape
::
Entity
expose
:name
,
:content
end
end
end
lib/api/gitignores.rb
0 → 100644
浏览文件 @
e166a802
module
API
class
Gitignores
<
Grape
::
API
# Get the list of the available gitignore templates
#
# Example Request:
# GET /gitignores
get
'gitignores'
do
present
Gitlab
::
Gitignore
.
all
,
with:
Entities
::
GitignoresList
end
# Get the text for a specific gitignore
#
# Parameters:
# key (required) - The key of a license
#
# Example Request:
# GET /gitignores/elixir
#
get
'gitignores/:key'
do
required_attributes!
[
:key
]
gitignore
=
Gitlab
::
Gitignore
.
find
(
params
[
:key
])
not_found!
(
'.gitignore'
)
unless
gitignore
present
gitignore
,
with:
Entities
::
Gitignore
end
end
end
lib/gitlab/gitignore.rb
0 → 100644
浏览文件 @
e166a802
module
Gitlab
class
Gitignore
FILTER_REGEX
=
/\.gitignore\z/
.
freeze
attr_accessor
:name
,
:directory
def
initialize
(
name
,
directory
)
@name
=
name
@directory
=
directory
end
def
content
File
.
read
(
path
)
end
class
<<
self
def
all
languages_frameworks
+
global
end
def
find
(
key
)
file_name
=
"
#{
key
}
.gitignore"
directory
=
select_directory
(
file_name
)
directory
?
new
(
key
,
directory
)
:
nil
end
def
global
files_for_folder
(
global_dir
).
map
{
|
f
|
new
(
f
,
global_dir
)
}
end
def
languages_frameworks
files_for_folder
(
gitignore_dir
).
map
{
|
f
|
new
(
f
,
gitignore_dir
)
}
end
end
private
def
path
File
.
expand_path
(
"
#{
name
}
.gitignore"
,
directory
)
end
class
<<
self
def
select_directory
(
file_name
)
[
self
.
gitignore_dir
,
self
.
global_dir
].
find
{
|
dir
|
File
.
exist?
(
File
.
expand_path
(
file_name
,
dir
))
}
end
def
global_dir
File
.
expand_path
(
'Global'
,
gitignore_dir
)
end
def
gitignore_dir
File
.
expand_path
(
'vendor/gitignore'
,
Rails
.
root
)
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
end
end
end
end
lib/tasks/gitlab/update_gitignore.rake
0 → 100644
浏览文件 @
e166a802
namespace
:gitlab
do
desc
"GitLab | Update gitignore"
task
:update_gitignore
do
dir
=
File
.
expand_path
(
'vendor'
,
Rails
.
root
)
FileUtils
.
cd
(
dir
)
dir
=
File
.
expand_path
(
'gitignore'
,
dir
)
clone_gitignores
(
dir
)
remove_unneeded_files
(
dir
)
puts
"Done"
.
green
end
def
clone_gitignores
(
dir
)
FileUtils
.
rm_rf
(
dir
)
if
Dir
.
exist?
(
dir
)
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
end
end
end
spec/lib/gitlab/gitignore_spec.rb
0 → 100644
浏览文件 @
e166a802
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'
)
end
it
'combines the globals and rest'
do
all
=
subject
.
all
.
map
(
&
:name
)
expect
(
all
).
to
include
(
'Vim'
)
expect
(
all
).
to
include
(
'Ruby'
)
end
end
describe
'.find'
do
it
'returns nil if the file does not exist'
do
expect
(
subject
.
find
(
'mepmep-yadida'
)).
to
be
nil
end
it
'returns the Gitignore object of a valid file'
do
ruby
=
subject
.
find
(
'Ruby'
)
expect
(
ruby
).
to
be_a
Gitlab
::
Gitignore
end
end
describe
'#content'
do
it
'loads the full file'
do
gitignore
=
subject
.
new
(
'Ruby'
,
File
.
expand_path
(
'vendor/gitignore'
,
Rails
.
root
))
expect
(
gitignore
.
name
).
to
eq
'Ruby'
expect
(
gitignore
.
content
).
to
start_with
(
'*.gem'
)
end
end
end
spec/requests/api/gitignores_spec.rb
0 → 100644
浏览文件 @
e166a802
require
'spec_helper'
describe
API
::
Gitignores
,
api:
true
do
include
ApiHelpers
describe
'Entity Gitignore'
do
before
{
get
api
(
'/gitignores/Ruby'
)
}
it
{
expect
(
json_response
[
'name'
]).
to
eq
(
'Ruby'
)
}
it
{
expect
(
json_response
[
'content'
]).
to
include
(
'*.gem'
)
}
end
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
}
end
describe
'GET /gitignores'
do
it
'returns a list of available license templates'
do
get
api
(
'/gitignores'
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
be
>
15
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录