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
Tatuya Kamada
gitlab-ce
Commits
6774a701
Commit
6774a701
authored
Jan 12, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'refactor_push_data_builder' into 'master'
Refactor push data builder See merge request !1384
parents
1c6a1253
bba8e59a
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
122 additions
and
85 deletions
+122
-85
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+1
-2
app/controllers/projects/tags_controller.rb
app/controllers/projects/tags_controller.rb
+1
-0
app/services/create_tag_service.rb
app/services/create_tag_service.rb
+12
-2
app/services/git_push_service.rb
app/services/git_push_service.rb
+2
-61
app/services/git_tag_push_service.rb
app/services/git_tag_push_service.rb
+2
-14
app/services/test_hook_service.rb
app/services/test_hook_service.rb
+1
-1
lib/gitlab/push_data_builder.rb
lib/gitlab/push_data_builder.rb
+63
-0
spec/lib/gitlab/push_data_builder_spec.rb
spec/lib/gitlab/push_data_builder_spec.rb
+35
-0
spec/models/assembla_service_spec.rb
spec/models/assembla_service_spec.rb
+1
-1
spec/models/flowdock_service_spec.rb
spec/models/flowdock_service_spec.rb
+1
-1
spec/models/gemnasium_service_spec.rb
spec/models/gemnasium_service_spec.rb
+1
-1
spec/models/pushover_service_spec.rb
spec/models/pushover_service_spec.rb
+1
-1
spec/models/slack_service_spec.rb
spec/models/slack_service_spec.rb
+1
-1
No files found.
app/controllers/projects/services_controller.rb
View file @
6774a701
...
...
@@ -24,8 +24,7 @@ class Projects::ServicesController < Projects::ApplicationController
end
def
test
data
=
GitPushService
.
new
.
sample_data
(
project
,
current_user
)
data
=
Gitlab
::
PushDataBuilder
.
build_sample
(
project
,
current_user
)
@service
.
execute
(
data
)
redirect_to
:back
...
...
app/controllers/projects/tags_controller.rb
View file @
6774a701
...
...
@@ -13,6 +13,7 @@ class Projects::TagsController < Projects::ApplicationController
def
create
result
=
CreateTagService
.
new
(
@project
,
current_user
).
execute
(
params
[
:tag_name
],
params
[
:ref
],
params
[
:message
])
if
result
[
:status
]
==
:success
@tag
=
result
[
:tag
]
redirect_to
project_tags_path
(
@project
)
...
...
app/services/create_tag_service.rb
View file @
6774a701
...
...
@@ -21,10 +21,15 @@ class CreateTagService < BaseService
new_tag
=
repository
.
find_tag
(
tag_name
)
if
new_tag
if
project
.
gitlab_ci?
push_data
=
create_push_data
(
project
,
current_user
,
new_tag
)
project
.
gitlab_ci_service
.
async_execute
(
push_data
)
end
Event
.
create_ref_event
(
project
,
current_user
,
new_tag
,
'add'
,
'refs/tags'
)
return
success
(
new_tag
)
success
(
new_tag
)
else
return
error
(
'Invalid reference name'
)
error
(
'Invalid reference name'
)
end
end
...
...
@@ -33,4 +38,9 @@ class CreateTagService < BaseService
out
[
:tag
]
=
branch
out
end
def
create_push_data
(
project
,
user
,
tag
)
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
Gitlab
::
Git
::
BLANK_SHA
,
tag
.
target
,
'refs/tags/'
+
tag
.
name
,
[])
end
end
app/services/git_push_service.rb
View file @
6774a701
...
...
@@ -52,16 +52,6 @@ class GitPushService
end
end
# This method provide a sample data
# generated with post_receive_data method
# for given project
#
def
sample_data
(
project
,
user
)
@project
,
@user
=
project
,
user
@push_commits
=
project
.
repository
.
commits
(
project
.
default_branch
,
nil
,
3
)
post_receive_data
(
@push_commits
.
last
.
id
,
@push_commits
.
first
.
id
,
"refs/heads/
#{
project
.
default_branch
}
"
)
end
protected
def
create_push_event
(
push_data
)
...
...
@@ -112,58 +102,9 @@ class GitPushService
end
end
# Produce a hash of post-receive data
#
# data = {
# before: String,
# after: String,
# ref: String,
# user_id: String,
# user_name: String,
# project_id: String,
# repository: {
# name: String,
# url: String,
# description: String,
# homepage: String,
# },
# commits: Array,
# total_commits_count: Fixnum
# }
#
def
post_receive_data
(
oldrev
,
newrev
,
ref
)
# Total commits count
push_commits_count
=
push_commits
.
size
# Get latest 20 commits ASC
push_commits_limited
=
push_commits
.
last
(
20
)
# Hash to be passed as post_receive_data
data
=
{
before:
oldrev
,
after:
newrev
,
ref:
ref
,
user_id:
user
.
id
,
user_name:
user
.
name
,
project_id:
project
.
id
,
repository:
{
name:
project
.
name
,
url:
project
.
url_to_repo
,
description:
project
.
description
,
homepage:
project
.
web_url
,
},
commits:
[],
total_commits_count:
push_commits_count
}
# For performance purposes maximum 20 latest commits
# will be passed as post receive hook data.
#
push_commits_limited
.
each
do
|
commit
|
data
[
:commits
]
<<
commit
.
hook_attrs
(
project
)
end
data
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
push_commits
)
end
def
push_to_existing_branch?
(
ref
,
oldrev
)
...
...
app/services/git_tag_push_service.rb
View file @
6774a701
...
...
@@ -19,20 +19,8 @@ class GitTagPushService
private
def
create_push_data
(
oldrev
,
newrev
,
ref
)
data
=
{
ref:
ref
,
before:
oldrev
,
after:
newrev
,
user_id:
user
.
id
,
user_name:
user
.
name
,
project_id:
project
.
id
,
repository:
{
name:
project
.
name
,
url:
project
.
url_to_repo
,
description:
project
.
description
,
homepage:
project
.
web_url
}
}
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
[])
end
def
create_push_event
...
...
app/services/test_hook_service.rb
View file @
6774a701
class
TestHookService
def
execute
(
hook
,
current_user
)
data
=
Git
PushService
.
new
.
sample_data
(
hook
.
project
,
current_user
)
data
=
Git
lab
::
PushDataBuilder
.
build_sample
(
hook
.
project
,
current_user
)
hook
.
execute
(
data
)
end
end
lib/gitlab/push_data_builder.rb
0 → 100644
View file @
6774a701
module
Gitlab
class
PushDataBuilder
# Produce a hash of post-receive data
#
# data = {
# before: String,
# after: String,
# ref: String,
# user_id: String,
# user_name: String,
# project_id: String,
# repository: {
# name: String,
# url: String,
# description: String,
# homepage: String,
# },
# commits: Array,
# total_commits_count: Fixnum
# }
#
def
self
.
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
commits
=
[])
# Total commits count
commits_count
=
commits
.
size
# Get latest 20 commits ASC
commits_limited
=
commits
.
last
(
20
)
# Hash to be passed as post_receive_data
data
=
{
before:
oldrev
,
after:
newrev
,
ref:
ref
,
user_id:
user
.
id
,
user_name:
user
.
name
,
project_id:
project
.
id
,
repository:
{
name:
project
.
name
,
url:
project
.
url_to_repo
,
description:
project
.
description
,
homepage:
project
.
web_url
,
},
commits:
[],
total_commits_count:
commits_count
}
# For performance purposes maximum 20 latest commits
# will be passed as post receive hook data.
commits_limited
.
each
do
|
commit
|
data
[
:commits
]
<<
commit
.
hook_attrs
(
project
)
end
data
end
# This method provide a sample data generated with
# existing project and commits to test web hooks
def
self
.
build_sample
(
project
,
user
)
commits
=
project
.
repository
.
commits
(
project
.
default_branch
,
nil
,
3
)
build
(
project
,
user
,
commits
.
last
.
id
,
commits
.
first
.
id
,
"refs/heads/
#{
project
.
default_branch
}
"
,
commits
)
end
end
end
spec/lib/gitlab/push_data_builder_spec.rb
0 → 100644
View file @
6774a701
require
'spec_helper'
describe
'Gitlab::PushDataBuilder'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
describe
:build_sample
do
let
(
:data
)
{
Gitlab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
}
it
{
data
.
should
be_a
(
Hash
)
}
it
{
data
[
:before
].
should
==
'6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9'
}
it
{
data
[
:after
].
should
==
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
}
it
{
data
[
:ref
].
should
==
'refs/heads/master'
}
it
{
data
[
:commits
].
size
.
should
==
3
}
it
{
data
[
:total_commits_count
].
should
==
3
}
end
describe
:build
do
let
(
:data
)
do
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
Gitlab
::
Git
::
BLANK_SHA
,
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
,
'refs/tags/v1.1.0'
)
end
it
{
data
.
should
be_a
(
Hash
)
}
it
{
data
[
:before
].
should
==
Gitlab
::
Git
::
BLANK_SHA
}
it
{
data
[
:after
].
should
==
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
}
it
{
data
[
:ref
].
should
==
'refs/tags/v1.1.0'
}
it
{
data
[
:commits
].
should
be_empty
}
it
{
data
[
:total_commits_count
].
should
be_zero
}
end
end
spec/models/assembla_service_spec.rb
View file @
6774a701
...
...
@@ -33,7 +33,7 @@ describe AssemblaService, models: true do
token:
'verySecret'
,
subdomain:
'project_name'
)
@sample_data
=
Git
PushService
.
new
.
sample_data
(
project
,
user
)
@sample_data
=
Git
lab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
@api_url
=
'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret'
WebMock
.
stub_request
(
:post
,
@api_url
)
end
...
...
spec/models/flowdock_service_spec.rb
View file @
6774a701
...
...
@@ -32,7 +32,7 @@ describe FlowdockService do
service_hook:
true
,
token:
'verySecret'
)
@sample_data
=
Git
PushService
.
new
.
sample_data
(
project
,
user
)
@sample_data
=
Git
lab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
@api_url
=
'https://api.flowdock.com/v1/git/verySecret'
WebMock
.
stub_request
(
:post
,
@api_url
)
end
...
...
spec/models/gemnasium_service_spec.rb
View file @
6774a701
...
...
@@ -33,7 +33,7 @@ describe GemnasiumService do
token:
'verySecret'
,
api_key:
'GemnasiumUserApiKey'
)
@sample_data
=
Git
PushService
.
new
.
sample_data
(
project
,
user
)
@sample_data
=
Git
lab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
end
it
"should call Gemnasium service"
do
Gemnasium
::
GitlabService
.
should_receive
(
:execute
).
with
(
an_instance_of
(
Hash
)).
once
...
...
spec/models/pushover_service_spec.rb
View file @
6774a701
...
...
@@ -36,7 +36,7 @@ describe PushoverService do
let
(
:pushover
)
{
PushoverService
.
new
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:sample_data
)
{
Git
PushService
.
new
.
sample_data
(
project
,
user
)
}
let
(
:sample_data
)
{
Git
lab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
}
let
(
:api_key
)
{
'verySecret'
}
let
(
:user_key
)
{
'verySecret'
}
...
...
spec/models/slack_service_spec.rb
View file @
6774a701
...
...
@@ -34,7 +34,7 @@ describe SlackService do
let
(
:slack
)
{
SlackService
.
new
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:sample_data
)
{
Git
PushService
.
new
.
sample_data
(
project
,
user
)
}
let
(
:sample_data
)
{
Git
lab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
}
let
(
:webhook_url
)
{
'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685'
}
before
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