Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
cfe512d6
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 搜索 >>
提交
cfe512d6
编写于
8月 24, 2016
作者:
P
Paco Guzman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Show "Create Merge Request" widget for push events to fork projects on the source project
上级
02591b04
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
12 deletion
+64
-12
CHANGELOG
CHANGELOG
+3
-0
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+11
-10
app/models/user.rb
app/models/user.rb
+2
-2
spec/helpers/projects_helper_spec.rb
spec/helpers/projects_helper_spec.rb
+38
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+10
-0
未找到文件。
CHANGELOG
浏览文件 @
cfe512d6
...
...
@@ -5,6 +5,9 @@ v 8.12.0 (unreleased)
- Optimistic locking for Issues and Merge Requests (title and description overriding prevention)
- Added tests for diff notes
v 8.11.2 (unreleased)
- Show "Create Merge Request" widget for push events to fork projects on the source project
v 8.11.1 (unreleased)
- Fix file links on project page when default view is Files !5933
...
...
app/helpers/projects_helper.rb
浏览文件 @
cfe512d6
...
...
@@ -116,6 +116,17 @@ module ProjectsHelper
license
.
nickname
||
license
.
name
end
def
last_push_event
return
unless
current_user
project_ids
=
[
@project
.
id
]
if
fork
=
current_user
.
fork_of
(
@project
)
project_ids
<<
fork
.
id
end
current_user
.
recent_push
(
project_ids
)
end
private
def
get_project_nav_tabs
(
project
,
current_user
)
...
...
@@ -351,16 +362,6 @@ module ProjectsHelper
namespace_project_new_blob_path
(
@project
.
namespace
,
@project
,
tree_join
(
ref
),
file_name:
'LICENSE'
)
end
def
last_push_event
return
unless
current_user
if
fork
=
current_user
.
fork_of
(
@project
)
current_user
.
recent_push
(
fork
.
id
)
else
current_user
.
recent_push
(
@project
.
id
)
end
end
def
readme_cache_key
sha
=
@project
.
commit
.
try
(
:sha
)
||
'nil'
[
@project
.
path_with_namespace
,
sha
,
"readme"
].
join
(
'-'
)
...
...
app/models/user.rb
浏览文件 @
cfe512d6
...
...
@@ -489,10 +489,10 @@ class User < ActiveRecord::Base
(
personal_projects
.
count
.
to_f
/
projects_limit
)
*
100
end
def
recent_push
(
project_id
=
nil
)
def
recent_push
(
project_id
s
=
nil
)
# Get push events not earlier than 2 hours ago
events
=
recent_events
.
code_push
.
where
(
"created_at > ?"
,
Time
.
now
-
2
.
hours
)
events
=
events
.
where
(
project_id:
project_id
)
if
project_id
events
=
events
.
where
(
project_id:
project_id
s
)
if
project_ids
# Use the latest event that has not been pushed or merged recently
events
.
recent
.
find
do
|
event
|
...
...
spec/helpers/projects_helper_spec.rb
浏览文件 @
cfe512d6
...
...
@@ -136,4 +136,42 @@ describe ProjectsHelper do
expect
(
sanitize_repo_path
(
project
,
import_error
)).
to
eq
(
'Could not clone [REPOS PATH]/namespace/test.git'
)
end
end
describe
'#last_push_event'
do
let
(
:user
)
{
double
(
:user
,
fork_of:
nil
)
}
let
(
:project
)
{
double
(
:project
,
id:
1
)
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
helper
.
instance_variable_set
(
:@project
,
project
)
end
context
'when there is no current_user'
do
let
(
:user
)
{
nil
}
it
'returns nil'
do
expect
(
helper
.
last_push_event
).
to
eq
(
nil
)
end
end
it
'returns recent push on the current project'
do
event
=
double
(
:event
)
expect
(
user
).
to
receive
(
:recent_push
).
with
([
project
.
id
]).
and_return
(
event
)
expect
(
helper
.
last_push_event
).
to
eq
(
event
)
end
context
'when current user has a fork of the current project'
do
let
(
:fork
)
{
double
(
:fork
,
id:
2
)
}
it
'returns recent push considering fork events'
do
expect
(
user
).
to
receive
(
:fork_of
).
with
(
project
).
and_return
(
fork
)
event_on_fork
=
double
(
:event
)
expect
(
user
).
to
receive
(
:recent_push
).
with
([
project
.
id
,
fork
.
id
]).
and_return
(
event_on_fork
)
expect
(
helper
.
last_push_event
).
to
eq
(
event_on_fork
)
end
end
end
end
spec/models/user_spec.rb
浏览文件 @
cfe512d6
...
...
@@ -920,6 +920,16 @@ describe User, models: true do
expect
(
subject
.
recent_push
).
to
eq
(
nil
)
end
it
"includes push events on any of the provided projects"
do
expect
(
subject
.
recent_push
(
project1
)).
to
eq
(
nil
)
expect
(
subject
.
recent_push
(
project2
)).
to
eq
(
push_event
)
push_data1
=
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project1
,
subject
)
push_event1
=
create
(
:event
,
action:
Event
::
PUSHED
,
project:
project1
,
target:
project1
,
author:
subject
,
data:
push_data1
)
expect
(
subject
.
recent_push
([
project1
,
project2
])).
to
eq
(
push_event1
)
# Newest
end
end
describe
'#authorized_groups'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录