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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
5330af3f
Commit
5330af3f
authored
Apr 18, 2016
by
Gabriel Mazetto
Committed by
Dmitriy Zaporozhets
Apr 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using single builder for push and tag events
parent
2384bed4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
46 deletions
+47
-46
app/services/git_push_service.rb
app/services/git_push_service.rb
+1
-1
app/services/git_tag_push_service.rb
app/services/git_tag_push_service.rb
+1
-1
doc/system_hooks/system_hooks.md
doc/system_hooks/system_hooks.md
+38
-2
lib/gitlab/push_data_builder.rb
lib/gitlab/push_data_builder.rb
+1
-20
spec/lib/gitlab/push_data_builder_spec.rb
spec/lib/gitlab/push_data_builder_spec.rb
+6
-22
No files found.
app/services/git_push_service.rb
View file @
5330af3f
...
...
@@ -141,7 +141,7 @@ class GitPushService < BaseService
def
build_push_data_system_hook
@push_data_system
||=
Gitlab
::
PushDataBuilder
.
build
_system
(
@project
,
current_user
,
params
[
:oldrev
],
params
[
:newrev
],
params
[
:ref
])
build
(
@project
,
current_user
,
params
[
:oldrev
],
params
[
:newrev
],
params
[
:ref
],
[
])
end
def
push_to_existing_branch?
...
...
app/services/git_tag_push_service.rb
View file @
5330af3f
...
...
@@ -38,6 +38,6 @@ class GitTagPushService < BaseService
def
build_system_push_data
Gitlab
::
PushDataBuilder
.
build
_system
(
project
,
current_user
,
params
[
:oldrev
],
params
[
:newrev
],
params
[
:ref
]
)
build
(
project
,
current_user
,
params
[
:oldrev
],
params
[
:newrev
],
params
[
:ref
],
[],
''
)
end
end
doc/system_hooks/system_hooks.md
View file @
5330af3f
...
...
@@ -4,6 +4,12 @@ Your GitLab instance can perform HTTP POST requests on the following events: `pr
System hooks can be used, e.g. for logging or changing information in a LDAP server.
> **Note:**
>
> We follow the same structure from Webhooks for Push and Tag events, but we never display commits.
>
> Same deprecations from Webhooks are valid here.
## Hooks request example
**Request header**
:
...
...
@@ -276,7 +282,22 @@ X-Gitlab-Event: System Hook
"visibility_level"
:
0
,
"path_with_namespace"
:
"mike/diaspora"
,
"default_branch"
:
"master"
,
}
"homepage"
:
"http://example.com/mike/diaspora"
,
"url"
:
"git@example.com:mike/diaspora.git"
,
"ssh_url"
:
"git@example.com:mike/diaspora.git"
,
"http_url"
:
"http://example.com/mike/diaspora.git"
},
"repository"
:{
"name"
:
"Diaspora"
,
"url"
:
"git@example.com:mike/diaspora.git"
,
"description"
:
""
,
"homepage"
:
"http://example.com/mike/diaspora"
,
"git_http_url"
:
"http://example.com/mike/diaspora.git"
,
"git_ssh_url"
:
"git@example.com:mike/diaspora.git"
,
"visibility_level"
:
0
},
"commits"
:
[],
"total_commits_count"
:
0
}
```
...
...
@@ -314,6 +335,21 @@ X-Gitlab-Event: System Hook
"visibility_level"
:
0
,
"path_with_namespace"
:
"jsmith/example"
,
"default_branch"
:
"master"
,
}
"homepage"
:
"http://example.com/jsmith/example"
,
"url"
:
"git@example.com:jsmith/example.git"
,
"ssh_url"
:
"git@example.com:jsmith/example.git"
,
"http_url"
:
"http://example.com/jsmith/example.git"
},
"repository"
:{
"name"
:
"Example"
,
"url"
:
"ssh://git@example.com/jsmith/example.git"
,
"description"
:
""
,
"homepage"
:
"http://example.com/jsmith/example"
,
"git_http_url"
:
"http://example.com/jsmith/example.git"
,
"git_ssh_url"
:
"git@example.com:jsmith/example.git"
,
"visibility_level"
:
0
},
"commits"
:
[],
"total_commits_count"
:
0
}
```
lib/gitlab/push_data_builder.rb
View file @
5330af3f
...
...
@@ -41,6 +41,7 @@ module Gitlab
# Hash to be passed as post_receive_data
data
=
{
object_kind:
type
,
event_name:
type
,
before:
oldrev
,
after:
newrev
,
ref:
ref
,
...
...
@@ -62,26 +63,6 @@ module Gitlab
data
end
def
build_system
(
project
,
user
,
oldrev
,
newrev
,
ref
)
type
=
Gitlab
::
Git
.
tag_ref?
(
ref
)
?
'tag_push'
:
'push'
data
=
{
event_name:
type
,
before:
oldrev
,
after:
newrev
,
ref:
ref
,
checkout_sha:
checkout_sha
(
project
.
repository
,
newrev
,
ref
),
user_id:
user
.
id
,
user_name:
user
.
name
,
user_email:
user
.
email
,
user_avatar:
user
.
avatar_url
,
project_id:
project
.
id
,
project:
project
.
hook_attrs
(
backward:
false
)
}
data
end
# This method provide a sample data generated with
# existing project and commits to test webhooks
def
build_sample
(
project
,
user
)
...
...
spec/lib/gitlab/push_data_builder_spec.rb
View file @
5330af3f
...
...
@@ -34,6 +34,12 @@ describe Gitlab::PushDataBuilder, lib: true do
it
{
expect
(
data
[
:checkout_sha
]).
to
eq
(
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
)
}
it
{
expect
(
data
[
:after
]).
to
eq
(
'8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b'
)
}
it
{
expect
(
data
[
:ref
]).
to
eq
(
'refs/tags/v1.1.0'
)
}
it
{
expect
(
data
[
:user_id
]).
to
eq
(
user
.
id
)
}
it
{
expect
(
data
[
:user_name
]).
to
eq
(
user
.
name
)
}
it
{
expect
(
data
[
:user_email
]).
to
eq
(
user
.
email
)
}
it
{
expect
(
data
[
:user_avatar
]).
to
eq
(
user
.
avatar_url
)
}
it
{
expect
(
data
[
:project_id
]).
to
eq
(
project
.
id
)
}
it
{
expect
(
data
[
:project
]).
to
be_a
(
Hash
)
}
it
{
expect
(
data
[
:commits
]).
to
be_empty
}
it
{
expect
(
data
[
:total_commits_count
]).
to
be_zero
}
...
...
@@ -45,26 +51,4 @@ describe Gitlab::PushDataBuilder, lib: true do
not_to
raise_error
end
end
describe
'.build_system'
do
let
(
:data
)
do
described_class
.
build_system
(
project
,
user
,
Gitlab
::
Git
::
BLANK_SHA
,
'8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b'
,
'refs/tags/v1.1.0'
)
end
it
{
expect
(
data
).
to
be_a
(
Hash
)
}
it
{
expect
(
data
[
:before
]).
to
eq
(
Gitlab
::
Git
::
BLANK_SHA
)
}
it
{
expect
(
data
[
:checkout_sha
]).
to
eq
(
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
)
}
it
{
expect
(
data
[
:after
]).
to
eq
(
'8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b'
)
}
it
{
expect
(
data
[
:ref
]).
to
eq
(
'refs/tags/v1.1.0'
)
}
it
{
expect
(
data
[
:user_id
]).
to
eq
(
user
.
id
)
}
it
{
expect
(
data
[
:user_name
]).
to
eq
(
user
.
name
)
}
it
{
expect
(
data
[
:user_email
]).
to
eq
(
user
.
email
)
}
it
{
expect
(
data
[
:user_avatar
]).
to
eq
(
user
.
avatar_url
)
}
it
{
expect
(
data
[
:project_id
]).
to
eq
(
project
.
id
)
}
it
{
expect
(
data
[
:project
]).
to
be_a
(
Hash
)
}
include_examples
'project hook data'
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