Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
02e1e481
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,发现更多精彩内容 >>
提交
02e1e481
编写于
11月 22, 2016
作者:
J
James Lopez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more refactoring and fixing old specs
上级
8639ea1b
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
50 addition
and
49 deletion
+50
-49
app/controllers/concerns/cycle_analytics_params.rb
app/controllers/concerns/cycle_analytics_params.rb
+4
-0
app/controllers/projects/cycle_analytics/events_controller.rb
...controllers/projects/cycle_analytics/events_controller.rb
+0
-4
app/controllers/projects/cycle_analytics_controller.rb
app/controllers/projects/cycle_analytics_controller.rb
+5
-3
app/models/cycle_analytics.rb
app/models/cycle_analytics.rb
+16
-10
lib/gitlab/cycle_analytics/summary.rb
lib/gitlab/cycle_analytics/summary.rb
+3
-15
spec/models/cycle_analytics/code_spec.rb
spec/models/cycle_analytics/code_spec.rb
+9
-9
spec/models/cycle_analytics/issue_spec.rb
spec/models/cycle_analytics/issue_spec.rb
+1
-1
spec/models/cycle_analytics/plan_spec.rb
spec/models/cycle_analytics/plan_spec.rb
+1
-1
spec/models/cycle_analytics/production_spec.rb
spec/models/cycle_analytics/production_spec.rb
+1
-1
spec/models/cycle_analytics/review_spec.rb
spec/models/cycle_analytics/review_spec.rb
+1
-1
spec/models/cycle_analytics/staging_spec.rb
spec/models/cycle_analytics/staging_spec.rb
+1
-1
spec/models/cycle_analytics/summary_spec.rb
spec/models/cycle_analytics/summary_spec.rb
+1
-1
spec/models/cycle_analytics/test_spec.rb
spec/models/cycle_analytics/test_spec.rb
+1
-1
spec/support/cycle_analytics_helpers/test_generation.rb
spec/support/cycle_analytics_helpers/test_generation.rb
+6
-1
未找到文件。
app/controllers/concerns/cycle_analytics_params.rb
浏览文件 @
02e1e481
module
CycleAnalyticsParams
extend
ActiveSupport
::
Concern
def
options
@options
||=
{
from:
start_date
(
events_params
),
current_user:
current_user
}
end
def
start_date
(
params
)
params
[
:start_date
]
==
'30'
?
30
.
days
.
ago
:
90
.
days
.
ago
end
...
...
app/controllers/projects/cycle_analytics/events_controller.rb
浏览文件 @
02e1e481
...
...
@@ -51,10 +51,6 @@ module Projects
@events
||=
Gitlab
::
CycleAnalytics
::
Events
.
new
(
project:
project
,
options:
options
)
end
def
options
@options
||=
{
from:
start_date
(
events_params
),
current_user:
current_user
}
end
def
events_params
return
{}
unless
params
[
:events
].
present?
...
...
app/controllers/projects/cycle_analytics_controller.rb
浏览文件 @
02e1e481
...
...
@@ -6,7 +6,9 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
before_action
:authorize_read_cycle_analytics!
def
show
@cycle_analytics
=
::
CycleAnalytics
.
new
(
@project
,
current_user
,
from:
start_date
(
cycle_analytics_params
))
@cycle_analytics
=
::
CycleAnalytics
.
new
(
@project
,
options:
options
)
@cycle_analytics_no_data
=
@cycle_analytics
.
no_stats?
respond_to
do
|
format
|
format
.
html
...
...
@@ -25,8 +27,8 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
def
cycle_analytics_json
{
summary:
@cycle_analytics
.
summary
,
stats:
nil
,
# TODO
permissions:
@cycle_analytics
.
permissions
(
user:
current_user
)
# TODO
stats:
@cycle_analytics
.
stats
,
permissions:
@cycle_analytics
.
permissions
(
user:
current_user
)
}
end
end
app/models/cycle_analytics.rb
浏览文件 @
02e1e481
class
CycleAnalytics
STAGES
=
%i[issue plan code test review staging production]
.
freeze
def
initialize
(
project
,
from
:)
def
initialize
(
project
,
options
:)
@project
=
project
@options
=
options
end
...
...
@@ -10,22 +10,28 @@ class CycleAnalytics
@summary
||=
Gitlab
::
CycleAnalytics
::
Summary
.
new
(
@project
,
from:
@options
[
:from
]).
data
end
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
classify_stage
(
method_sym
).
new
(
project:
@project
,
options:
@options
,
stage:
method_sym
)
def
stats
@stats
||=
stats_per_stage
end
def
no_stats?
stats
.
map
(
&
:value
).
compact
.
empty?
end
def
permissions
(
user
:)
Gitlab
::
CycleAnalytics
::
Permissions
.
get
(
user:
user
,
project:
@project
)
end
def
issue
@fetcher
.
calculate_metric
(
:issue
,
Issue
.
arel_table
[
:created_at
],
[
Issue
::
Metrics
.
arel_table
[
:first_associated_with_milestone_at
],
Issue
::
Metrics
.
arel_table
[
:first_added_to_board_at
]])
private
def
stats_per_stage
STAGES
.
map
do
|
stage_name
|
classify_stage
(
method_sym
).
new
(
project:
@project
,
options:
@options
,
stage:
stage_name
).
median_data
end
end
def
classify_stage
(
method_sym
)
"Gitlab::CycleAnalytics::
#{
method_sym
.
to_s
.
capitalize
}
Stage"
.
constantize
def
classify_stage
(
stage_name
)
"Gitlab::CycleAnalytics::
#{
stage_name
.
to_s
.
capitalize
}
Stage"
.
constantize
end
end
lib/gitlab/cycle_analytics/summary.rb
浏览文件 @
02e1e481
...
...
@@ -9,9 +9,9 @@ module Gitlab
end
def
data
[
serialize
(
issue
),
serialize
(
commit
),
serialize
(
deploy
)]
[
serialize
(
Summary
::
Issue
.
new
(
project:
@project
,
from:
@from
)
),
serialize
(
Summary
::
Commit
.
new
(
project:
@project
,
from:
@from
)
),
serialize
(
Summary
::
Deploy
.
new
(
project:
@project
,
from:
@from
)
)]
end
private
...
...
@@ -19,18 +19,6 @@ module Gitlab
def
serialize
(
summary_object
)
AnalyticsSummarySerializer
.
new
.
represent
(
summary_object
).
as_json
end
def
issue
Summary
::
Issue
.
new
(
project:
@project
,
from:
@from
)
end
def
deploy
Summary
::
Deploy
.
new
(
project:
@project
,
from:
@from
)
end
def
commit
Summary
::
Commit
.
new
(
project:
@project
,
from:
@from
)
end
end
end
end
spec/models/cycle_analytics/code_spec.rb
浏览文件 @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#code', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
context
'with deployment'
do
generate_cycle_analytics_spec
(
...
...
@@ -16,10 +16,10 @@ describe 'CycleAnalytics#code', feature: true do
->
(
context
,
data
)
do
context
.
create_commit_referencing_issue
(
data
[
:issue
])
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
post_fn:
->
(
context
,
data
)
do
context
.
merge_merge_requests_closing_issue
(
data
[
:issue
])
context
.
deploy_master
...
...
@@ -50,10 +50,10 @@ describe 'CycleAnalytics#code', feature: true do
->
(
context
,
data
)
do
context
.
create_commit_referencing_issue
(
data
[
:issue
])
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
post_fn:
->
(
context
,
data
)
do
context
.
merge_merge_requests_closing_issue
(
data
[
:issue
])
end
)
...
...
spec/models/cycle_analytics/issue_spec.rb
浏览文件 @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#issue', models: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :issue
,
...
...
spec/models/cycle_analytics/plan_spec.rb
浏览文件 @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#plan', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :plan
,
...
...
spec/models/cycle_analytics/production_spec.rb
浏览文件 @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#production', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :production
,
...
...
spec/models/cycle_analytics/review_spec.rb
浏览文件 @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#review', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :review
,
...
...
spec/models/cycle_analytics/staging_spec.rb
浏览文件 @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#staging', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :staging
,
...
...
spec/models/cycle_analytics/summary_spec.rb
浏览文件 @
02e1e481
...
...
@@ -4,7 +4,7 @@ describe CycleAnalytics::Summary, models: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from
)
{
Time
.
now
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
described_class
.
new
(
project
,
user
,
from:
from
)
}
subject
{
CycleAnalyticsTest
.
new
(
project
,
options:
{
from:
from_date
}
)
}
describe
"#new_issues"
do
it
"finds the number of issues created after the 'from date'"
do
...
...
spec/models/cycle_analytics/test_spec.rb
浏览文件 @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#test', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :test
,
...
...
spec/support/cycle_analytics_helpers/test_generation.rb
浏览文件 @
02e1e481
class
CycleAnalyticsTest
<
CycleAnalytics
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
classify_stage
(
method_sym
).
new
(
project:
@project
,
options:
@options
,
stage:
method_sym
).
median
end
end
# rubocop:disable Metrics/AbcSize
# Note: The ABC size is large here because we have a method generating test cases with
# multiple nested contexts. This shouldn't count as a violation.
module
CycleAnalyticsHelpers
module
TestGeneration
# Generate the most common set of specs that all cycle analytics phases need to have.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录