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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
edebd5e7
Commit
edebd5e7
authored
Sep 27, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '22578-cycle-analytics-incorrect-commit-count'
parents
04d9547c
da1fa1e1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
16 deletions
+45
-16
CHANGELOG
CHANGELOG
+1
-0
app/models/cycle_analytics/summary.rb
app/models/cycle_analytics/summary.rb
+23
-5
spec/models/cycle_analytics/summary_spec.rb
spec/models/cycle_analytics/summary_spec.rb
+6
-0
spec/support/cycle_analytics_helpers.rb
spec/support/cycle_analytics_helpers.rb
+15
-11
No files found.
CHANGELOG
View file @
edebd5e7
...
@@ -9,6 +9,7 @@ v 8.12.2 (unreleased)
...
@@ -9,6 +9,7 @@ v 8.12.2 (unreleased)
- Fix Import/Export not recognising correctly the imported services.
- Fix Import/Export not recognising correctly the imported services.
- Fix snippets pagination
- Fix snippets pagination
- Fix List-Unsubscribe header in emails
- Fix List-Unsubscribe header in emails
- Fix an issue with the "Commits" section of the cycle analytics summary. !6513
v 8.12.1
v 8.12.1
- Fix a memory leak in HTML::Pipeline::SanitizationFilter::WHITELIST
- Fix a memory leak in HTML::Pipeline::SanitizationFilter::WHITELIST
...
...
app/models/cycle_analytics/summary.rb
View file @
edebd5e7
...
@@ -10,15 +10,33 @@ class CycleAnalytics
...
@@ -10,15 +10,33 @@ class CycleAnalytics
end
end
def
commits
def
commits
repository
=
@project
.
repository
.
raw_repository
ref
=
@project
.
default_branch
.
presence
count_commits_for
(
ref
)
if
@project
.
default_branch
repository
.
log
(
ref:
@project
.
default_branch
,
after:
@from
).
count
end
end
end
def
deploys
def
deploys
@project
.
deployments
.
where
(
"created_at > ?"
,
@from
).
count
@project
.
deployments
.
where
(
"created_at > ?"
,
@from
).
count
end
end
private
# Don't use the `Gitlab::Git::Repository#log` method, because it enforces
# a limit. Since we need a commit count, we _can't_ enforce a limit, so
# the easiest way forward is to replicate the relevant portions of the
# `log` function here.
def
count_commits_for
(
ref
)
return
unless
ref
repository
=
@project
.
repository
.
raw_repository
sha
=
@project
.
repository
.
commit
(
ref
).
sha
cmd
=
%W(git --git-dir=
#{
repository
.
path
}
log)
cmd
<<
'--format=%H'
cmd
<<
"--after=
#{
@from
.
iso8601
}
"
cmd
<<
sha
raw_output
=
IO
.
popen
(
cmd
)
{
|
io
|
io
.
read
}
raw_output
.
lines
.
count
end
end
end
end
end
spec/models/cycle_analytics/summary_spec.rb
View file @
edebd5e7
...
@@ -34,6 +34,12 @@ describe CycleAnalytics::Summary, models: true do
...
@@ -34,6 +34,12 @@ describe CycleAnalytics::Summary, models: true do
expect
(
subject
.
commits
).
to
eq
(
0
)
expect
(
subject
.
commits
).
to
eq
(
0
)
end
end
it
"finds a large (> 100) snumber of commits if present"
do
Timecop
.
freeze
(
5
.
days
.
from_now
)
{
create_commit
(
"Test message"
,
project
,
user
,
'master'
,
count:
100
)
}
expect
(
subject
.
commits
).
to
eq
(
100
)
end
end
end
describe
"#deploys"
do
describe
"#deploys"
do
...
...
spec/support/cycle_analytics_helpers.rb
View file @
edebd5e7
...
@@ -4,24 +4,28 @@ module CycleAnalyticsHelpers
...
@@ -4,24 +4,28 @@ module CycleAnalyticsHelpers
create_commit
(
"Commit for #
#{
issue
.
iid
}
"
,
issue
.
project
,
user
,
branch_name
)
create_commit
(
"Commit for #
#{
issue
.
iid
}
"
,
issue
.
project
,
user
,
branch_name
)
end
end
def
create_commit
(
message
,
project
,
user
,
branch_name
)
def
create_commit
(
message
,
project
,
user
,
branch_name
,
count:
1
)
filename
=
random_git_name
oldrev
=
project
.
repository
.
commit
(
branch_name
).
sha
oldrev
=
project
.
repository
.
commit
(
branch_name
).
sha
commit_shas
=
Array
.
new
(
count
)
do
|
index
|
filename
=
random_git_name
options
=
{
options
=
{
committer:
project
.
repository
.
user_to_committer
(
user
),
committer:
project
.
repository
.
user_to_committer
(
user
),
author:
project
.
repository
.
user_to_committer
(
user
),
author:
project
.
repository
.
user_to_committer
(
user
),
commit:
{
message:
message
,
branch:
branch_name
,
update_ref:
true
},
commit:
{
message:
message
,
branch:
branch_name
,
update_ref:
true
},
file:
{
content:
"content"
,
path:
filename
,
update:
false
}
file:
{
content:
"content"
,
path:
filename
,
update:
false
}
}
}
commit_sha
=
Gitlab
::
Git
::
Blob
.
commit
(
project
.
repository
,
options
)
project
.
repository
.
commit
(
commit_sha
)
commit_sha
=
Gitlab
::
Git
::
Blob
.
commit
(
project
.
repository
,
options
)
commit_sha
project
.
repository
.
commit
(
commit_sha
)
end
GitPushService
.
new
(
project
,
GitPushService
.
new
(
project
,
user
,
user
,
oldrev:
oldrev
,
oldrev:
oldrev
,
newrev:
commit_sha
,
newrev:
commit_sha
s
.
last
,
ref:
'refs/heads/master'
).
execute
ref:
'refs/heads/master'
).
execute
end
end
...
...
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