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
Léo-Paul Géneau
gitlab-ce
Commits
31970445
Commit
31970445
authored
Jan 11, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor push data builder. Moved it to separate class
Also execute GitLab CI on creating tag via UI
parent
31bcd047
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
115 additions
and
78 deletions
+115
-78
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
+10
-0
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
No files found.
app/controllers/projects/services_controller.rb
View file @
31970445
...
...
@@ -24,8 +24,7 @@ class Projects::ServicesController < Projects::ApplicationController
end
def
test
data
=
GitPushService
.
new
.
sample_data
(
project
,
current_user
)
data
=
Gitlab
::
PushDataBuilder
.
build
(
project
,
current_user
)
@service
.
execute
(
data
)
redirect_to
:back
...
...
app/controllers/projects/tags_controller.rb
View file @
31970445
...
...
@@ -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 @
31970445
...
...
@@ -21,6 +21,11 @@ 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
)
else
...
...
@@ -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
,
tag
.
name
,
[])
end
end
app/services/git_push_service.rb
View file @
31970445
...
...
@@ -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 @
31970445
...
...
@@ -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 @
31970445
class
TestHookService
def
execute
(
hook
,
current_user
)
data
=
Git
PushService
.
new
.
sample_data
(
hook
.
project
,
current_user
)
data
=
Git
lab
::
PushDataBuilder
.
build
(
hook
.
project
,
current_user
)
hook
.
execute
(
data
)
end
end
lib/gitlab/push_data_builder.rb
0 → 100644
View file @
31970445
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 @
31970445
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
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