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
Boxiang Sun
gitlab-ce
Commits
56318a24
Commit
56318a24
authored
Mar 12, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6474 from jvanbaarsen/post-tag-hook
Add web hooks on tag
parents
cc57a25c
e6ceec9d
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
152 additions
and
32 deletions
+152
-32
app/models/project_hook.rb
app/models/project_hook.rb
+2
-1
app/services/git_tag_push_service.rb
app/services/git_tag_push_service.rb
+27
-0
app/views/projects/hooks/index.html.haml
app/views/projects/hooks/index.html.haml
+8
-1
app/workers/post_receive.rb
app/workers/post_receive.rb
+11
-1
db/migrate/20140305193308_add_tag_push_hooks_to_project_hook.rb
...rate/20140305193308_add_tag_push_hooks_to_project_hook.rb
+5
-0
db/schema.rb
db/schema.rb
+33
-29
spec/models/project_hook_spec.rb
spec/models/project_hook_spec.rb
+19
-0
spec/services/git_tag_push_service_spec.rb
spec/services/git_tag_push_service_spec.rb
+47
-0
No files found.
app/models/project_hook.rb
View file @
56318a24
...
...
@@ -17,9 +17,10 @@
class
ProjectHook
<
WebHook
belongs_to
:project
attr_accessible
:push_events
,
:issues_events
,
:merge_requests_events
attr_accessible
:push_events
,
:issues_events
,
:merge_requests_events
,
:tag_push_events
scope
:push_hooks
,
->
{
where
(
push_events:
true
)
}
scope
:tag_push_hooks
,
->
{
where
(
tag_push_events:
true
)
}
scope
:issue_hooks
,
->
{
where
(
issues_events:
true
)
}
scope
:merge_request_hooks
,
->
{
where
(
merge_requests_events:
true
)
}
end
app/services/git_tag_push_service.rb
0 → 100644
View file @
56318a24
class
GitTagPushService
attr_accessor
:project
,
:user
,
:push_data
def
execute
(
project
,
user
,
oldrev
,
newrev
,
ref
)
@project
,
@user
=
project
,
user
@push_data
=
create_push_data
(
oldrev
,
newrev
,
ref
)
project
.
execute_hooks
(
@push_data
.
dup
,
:tag_push_hooks
)
end
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
}
}
end
end
app/views/projects/hooks/index.html.haml
View file @
56318a24
...
...
@@ -26,6 +26,13 @@
%strong
Push events
%p
.light
This url will be triggered by a push to the repository
%div
=
f
.
check_box
:tag_push_events
,
class:
'pull-left'
.prepend-left-20
=
f
.
label
:tag_push_events
,
class:
'list-label'
do
%strong
Tag push events
%p
.light
This url will be triggered when a new tag is pushed to the repository
%div
=
f
.
check_box
:issues_events
,
class:
'pull-left'
.prepend-left-20
...
...
@@ -56,6 +63,6 @@
.clearfix
%span
.monospace
=
hook
.
url
%p
-
%w(push_events issues_events merge_requests_events)
.
each
do
|
trigger
|
-
%w(push_events
tag_push_events
issues_events merge_requests_events)
.
each
do
|
trigger
|
-
if
hook
.
send
(
trigger
)
%span
.label.label-gray
=
trigger
.
titleize
app/workers/post_receive.rb
View file @
56318a24
...
...
@@ -29,10 +29,20 @@ class PostReceive
return
false
end
if
tag?
(
ref
)
GitTagPushService
.
new
.
execute
(
project
,
user
,
oldrev
,
newrev
,
ref
)
else
GitPushService
.
new
.
execute
(
project
,
user
,
oldrev
,
newrev
,
ref
)
end
end
def
log
(
message
)
Gitlab
::
GitLogger
.
error
(
"POST-RECEIVE:
#{
message
}
"
)
end
private
def
tag?
(
ref
)
!!
(
/refs\/tags\/(.*)/
.
match
(
ref
))
end
end
db/migrate/20140305193308_add_tag_push_hooks_to_project_hook.rb
0 → 100644
View file @
56318a24
class
AddTagPushHooksToProjectHook
<
ActiveRecord
::
Migration
def
change
add_column
:web_hooks
,
:tag_push_events
,
:boolean
,
default:
false
end
end
db/schema.rb
View file @
56318a24
...
...
@@ -11,15 +11,18 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20140304005354
)
do
ActiveRecord
::
Schema
.
define
(
version:
20140305193308
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
create_table
"broadcast_messages"
,
force:
true
do
|
t
|
t
.
text
"message"
,
null:
false
t
.
datetime
"starts_at"
t
.
datetime
"ends_at"
t
.
integer
"alert_type"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"color"
t
.
string
"font"
end
...
...
@@ -27,8 +30,8 @@ ActiveRecord::Schema.define(version: 20140304005354) do
create_table
"deploy_keys_projects"
,
force:
true
do
|
t
|
t
.
integer
"deploy_key_id"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
add_index
"deploy_keys_projects"
,
[
"project_id"
],
name:
"index_deploy_keys_projects_on_project_id"
,
using: :btree
...
...
@@ -49,8 +52,8 @@ ActiveRecord::Schema.define(version: 20140304005354) do
t
.
string
"title"
t
.
text
"data"
t
.
integer
"project_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
integer
"action"
t
.
integer
"author_id"
end
...
...
@@ -65,8 +68,8 @@ ActiveRecord::Schema.define(version: 20140304005354) do
create_table
"forked_project_links"
,
force:
true
do
|
t
|
t
.
integer
"forked_to_project_id"
,
null:
false
t
.
integer
"forked_from_project_id"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
add_index
"forked_project_links"
,
[
"forked_to_project_id"
],
name:
"index_forked_project_links_on_forked_to_project_id"
,
unique:
true
,
using: :btree
...
...
@@ -107,8 +110,8 @@ ActiveRecord::Schema.define(version: 20140304005354) do
create_table
"merge_request_diffs"
,
force:
true
do
|
t
|
t
.
string
"state"
,
default:
"collected"
,
null:
false
t
.
text
"st_commits"
,
limit:
2147483647
t
.
text
"st_diffs"
,
limit:
2147483647
t
.
text
"st_commits"
t
.
text
"st_diffs"
t
.
integer
"merge_request_id"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
...
...
@@ -138,7 +141,7 @@ ActiveRecord::Schema.define(version: 20140304005354) do
add_index
"merge_requests"
,
[
"created_at"
],
name:
"index_merge_requests_on_created_at"
,
using: :btree
add_index
"merge_requests"
,
[
"milestone_id"
],
name:
"index_merge_requests_on_milestone_id"
,
using: :btree
add_index
"merge_requests"
,
[
"source_branch"
],
name:
"index_merge_requests_on_source_branch"
,
using: :btree
add_index
"merge_requests"
,
[
"source_project_id"
],
name:
"index_merge_requests_on_project_id"
,
using: :btree
add_index
"merge_requests"
,
[
"source_project_id"
],
name:
"index_merge_requests_on_
source_
project_id"
,
using: :btree
add_index
"merge_requests"
,
[
"target_branch"
],
name:
"index_merge_requests_on_target_branch"
,
using: :btree
add_index
"merge_requests"
,
[
"title"
],
name:
"index_merge_requests_on_title"
,
using: :btree
...
...
@@ -147,8 +150,8 @@ ActiveRecord::Schema.define(version: 20140304005354) do
t
.
integer
"project_id"
,
null:
false
t
.
text
"description"
t
.
date
"due_date"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"state"
t
.
integer
"iid"
end
...
...
@@ -160,8 +163,8 @@ ActiveRecord::Schema.define(version: 20140304005354) do
t
.
string
"name"
,
null:
false
t
.
string
"path"
,
null:
false
t
.
integer
"owner_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"type"
t
.
string
"description"
,
default:
""
,
null:
false
t
.
string
"avatar"
...
...
@@ -183,8 +186,8 @@ ActiveRecord::Schema.define(version: 20140304005354) do
t
.
string
"line_code"
t
.
string
"commit_id"
t
.
integer
"noteable_id"
t
.
text
"st_diff"
t
.
boolean
"system"
,
default:
false
,
null:
false
t
.
text
"st_diff"
end
add_index
"notes"
,
[
"author_id"
],
name:
"index_notes_on_author_id"
,
using: :btree
...
...
@@ -217,15 +220,15 @@ ActiveRecord::Schema.define(version: 20140304005354) do
t
.
boolean
"archived"
,
default:
false
,
null:
false
end
add_index
"projects"
,
[
"creator_id"
],
name:
"index_projects_on_
owne
r_id"
,
using: :btree
add_index
"projects"
,
[
"creator_id"
],
name:
"index_projects_on_
creato
r_id"
,
using: :btree
add_index
"projects"
,
[
"last_activity_at"
],
name:
"index_projects_on_last_activity_at"
,
using: :btree
add_index
"projects"
,
[
"namespace_id"
],
name:
"index_projects_on_namespace_id"
,
using: :btree
create_table
"protected_branches"
,
force:
true
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
string
"name"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
add_index
"protected_branches"
,
[
"project_id"
],
name:
"index_protected_branches_on_project_id"
,
using: :btree
...
...
@@ -235,8 +238,8 @@ ActiveRecord::Schema.define(version: 20140304005354) do
t
.
string
"title"
t
.
string
"token"
t
.
integer
"project_id"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
boolean
"active"
,
default:
false
,
null:
false
t
.
string
"project_url"
t
.
string
"subdomain"
...
...
@@ -249,7 +252,7 @@ ActiveRecord::Schema.define(version: 20140304005354) do
create_table
"snippets"
,
force:
true
do
|
t
|
t
.
string
"title"
t
.
text
"content"
,
limit:
2147483647
t
.
text
"content"
t
.
integer
"author_id"
,
null:
false
t
.
integer
"project_id"
t
.
datetime
"created_at"
...
...
@@ -335,8 +338,8 @@ ActiveRecord::Schema.define(version: 20140304005354) do
t
.
integer
"group_access"
,
null:
false
t
.
integer
"group_id"
,
null:
false
t
.
integer
"user_id"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
integer
"notification_level"
,
default:
3
,
null:
false
end
...
...
@@ -365,6 +368,7 @@ ActiveRecord::Schema.define(version: 20140304005354) do
t
.
boolean
"push_events"
,
default:
true
,
null:
false
t
.
boolean
"issues_events"
,
default:
false
,
null:
false
t
.
boolean
"merge_requests_events"
,
default:
false
,
null:
false
t
.
boolean
"tag_push_events"
,
default:
false
end
add_index
"web_hooks"
,
[
"project_id"
],
name:
"index_web_hooks_on_project_id"
,
using: :btree
...
...
spec/models/project_hook_spec.rb
0 → 100644
View file @
56318a24
require
'spec_helper'
describe
ProjectHook
do
describe
'.push_hooks'
do
it
'should return hooks for push events only'
do
hook
=
create
(
:project_hook
,
push_events:
true
)
hook2
=
create
(
:project_hook
,
push_events:
false
)
expect
(
ProjectHook
.
push_hooks
).
to
eq
([
hook
])
end
end
describe
'.tag_push_hooks'
do
it
'should return hooks for tag push events only'
do
hook
=
create
(
:project_hook
,
tag_push_events:
true
)
hook2
=
create
(
:project_hook
,
tag_push_events:
false
)
expect
(
ProjectHook
.
tag_push_hooks
).
to
eq
([
hook
])
end
end
end
spec/services/git_tag_push_service_spec.rb
0 → 100644
View file @
56318a24
require
'spec_helper'
describe
GitTagPushService
do
let
(
:user
)
{
create
:user
}
let
(
:project
)
{
create
:project
}
let
(
:service
)
{
GitTagPushService
.
new
}
before
do
@ref
=
'refs/tags/super-tag'
@oldrev
=
'b98a310def241a6fd9c9a9a3e7934c48e498fe81'
@newrev
=
'b19a04f53caeebf4fe5ec2327cb83e9253dc91bb'
end
describe
'Git Tag Push Data'
do
before
do
service
.
execute
(
project
,
user
,
@oldrev
,
@newrev
,
@ref
)
@push_data
=
service
.
push_data
end
subject
{
@push_data
}
it
{
should
include
(
ref:
@ref
)
}
it
{
should
include
(
before:
@oldrev
)
}
it
{
should
include
(
after:
@newrev
)
}
it
{
should
include
(
user_id:
user
.
id
)
}
it
{
should
include
(
user_name:
user
.
name
)
}
it
{
should
include
(
project_id:
project
.
id
)
}
context
'With repository data'
do
subject
{
@push_data
[
:repository
]
}
it
{
should
include
(
name:
project
.
name
)
}
it
{
should
include
(
url:
project
.
url_to_repo
)
}
it
{
should
include
(
description:
project
.
description
)
}
it
{
should
include
(
homepage:
project
.
web_url
)
}
end
end
describe
"Web Hooks"
do
context
"execute web hooks"
do
it
"when pushing tags"
do
project
.
should_receive
(
:execute_hooks
)
service
.
execute
(
project
,
user
,
'oldrev'
,
'newrev'
,
'refs/tags/v1.0.0'
)
end
end
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