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
07d05d2d
Commit
07d05d2d
authored
Feb 13, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move all event creation to EventCreateService.
parent
529188e4
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
64 additions
and
74 deletions
+64
-74
app/controllers/projects/tags_controller.rb
app/controllers/projects/tags_controller.rb
+1
-1
app/models/event.rb
app/models/event.rb
+0
-23
app/models/members/project_member.rb
app/models/members/project_member.rb
+6
-11
app/services/create_branch_service.rb
app/services/create_branch_service.rb
+1
-1
app/services/create_tag_service.rb
app/services/create_tag_service.rb
+1
-1
app/services/delete_branch_service.rb
app/services/delete_branch_service.rb
+1
-1
app/services/event_create_service.rb
app/services/event_create_service.rb
+52
-16
app/services/git_push_service.rb
app/services/git_push_service.rb
+1
-10
app/services/git_tag_push_service.rb
app/services/git_tag_push_service.rb
+1
-10
No files found.
app/controllers/projects/tags_controller.rb
View file @
07d05d2d
...
...
@@ -27,7 +27,7 @@ class Projects::TagsController < Projects::ApplicationController
tag
=
@repository
.
find_tag
(
params
[
:id
])
if
tag
&&
@repository
.
rm_tag
(
tag
.
name
)
Event
.
create_ref_event
(
@project
,
current_user
,
tag
,
'rm'
,
'refs/tags'
)
Event
CreateService
.
new
.
push_ref
(
@project
,
current_user
,
tag
,
'rm'
,
'refs/tags'
)
end
respond_to
do
|
format
|
...
...
app/models/event.rb
View file @
07d05d2d
...
...
@@ -49,29 +49,6 @@ class Event < ActiveRecord::Base
scope
:in_projects
,
->
(
project_ids
)
{
where
(
project_id:
project_ids
).
recent
}
class
<<
self
def
create_ref_event
(
project
,
user
,
ref
,
action
=
'add'
,
prefix
=
'refs/heads'
)
commit
=
project
.
repository
.
commit
(
ref
.
target
)
if
action
.
to_s
==
'add'
before
=
'00000000'
after
=
commit
.
id
else
before
=
commit
.
id
after
=
'00000000'
end
Event
.
create
(
project:
project
,
action:
Event
::
PUSHED
,
data:
{
ref:
"
#{
prefix
}
/
#{
ref
.
name
}
"
,
before:
before
,
after:
after
},
author_id:
user
.
id
)
end
def
reset_event_cache_for
(
target
)
Event
.
where
(
target_id:
target
.
id
,
target_type:
target
.
class
.
to_s
).
order
(
'id DESC'
).
limit
(
100
).
...
...
app/models/members/project_member.rb
View file @
07d05d2d
...
...
@@ -114,12 +114,8 @@ class ProjectMember < Member
end
def
post_create_hook
Event
.
create
(
project_id:
self
.
project
.
id
,
action:
Event
::
JOINED
,
author_id:
self
.
user
.
id
)
event_service
.
join_project
(
self
.
project
,
self
.
user
)
notification_service
.
new_team_member
(
self
)
unless
owner?
system_hook_service
.
execute_hooks_for
(
self
,
:create
)
end
...
...
@@ -129,15 +125,14 @@ class ProjectMember < Member
end
def
post_destroy_hook
Event
.
create
(
project_id:
self
.
project
.
id
,
action:
Event
::
LEFT
,
author_id:
self
.
user
.
id
)
event_service
.
leave_project
(
self
.
project
,
self
.
user
)
system_hook_service
.
execute_hooks_for
(
self
,
:destroy
)
end
def
event_service
EventCreateService
.
new
end
def
notification_service
NotificationService
.
new
end
...
...
app/services/create_branch_service.rb
View file @
07d05d2d
...
...
@@ -17,7 +17,7 @@ class CreateBranchService < BaseService
new_branch
=
repository
.
find_branch
(
branch_name
)
if
new_branch
Event
.
create_ref_event
(
project
,
current_user
,
new_branch
,
'add'
)
Event
CreateService
.
new
.
push_ref
(
project
,
current_user
,
new_branch
,
'add'
)
return
success
(
new_branch
)
else
return
error
(
'Invalid reference name'
)
...
...
app/services/create_tag_service.rb
View file @
07d05d2d
...
...
@@ -26,7 +26,7 @@ class CreateTagService < BaseService
project
.
gitlab_ci_service
.
async_execute
(
push_data
)
end
Event
.
create_ref_event
(
project
,
current_user
,
new_tag
,
'add'
,
'refs/tags'
)
Event
CreateService
.
new
.
push_ref
(
project
,
current_user
,
new_tag
,
'add'
,
'refs/tags'
)
success
(
new_tag
)
else
error
(
'Invalid reference name'
)
...
...
app/services/delete_branch_service.rb
View file @
07d05d2d
...
...
@@ -25,7 +25,7 @@ class DeleteBranchService < BaseService
end
if
repository
.
rm_branch
(
branch_name
)
Event
.
create_ref_event
(
project
,
current_user
,
branch
,
'rm'
)
Event
CreateService
.
new
.
push_ref
(
project
,
current_user
,
branch
,
'rm'
)
success
(
'Branch was removed'
)
else
return
error
(
'Failed to remove branch'
)
...
...
app/services/event_create_service.rb
View file @
07d05d2d
...
...
@@ -7,58 +7,94 @@
#
class
EventCreateService
def
open_issue
(
issue
,
current_user
)
create_event
(
issue
,
current_user
,
Event
::
CREATED
)
create_
record_
event
(
issue
,
current_user
,
Event
::
CREATED
)
end
def
close_issue
(
issue
,
current_user
)
create_event
(
issue
,
current_user
,
Event
::
CLOSED
)
create_
record_
event
(
issue
,
current_user
,
Event
::
CLOSED
)
end
def
reopen_issue
(
issue
,
current_user
)
create_event
(
issue
,
current_user
,
Event
::
REOPENED
)
create_
record_
event
(
issue
,
current_user
,
Event
::
REOPENED
)
end
def
open_mr
(
merge_request
,
current_user
)
create_event
(
merge_request
,
current_user
,
Event
::
CREATED
)
create_
record_
event
(
merge_request
,
current_user
,
Event
::
CREATED
)
end
def
close_mr
(
merge_request
,
current_user
)
create_event
(
merge_request
,
current_user
,
Event
::
CLOSED
)
create_
record_
event
(
merge_request
,
current_user
,
Event
::
CLOSED
)
end
def
reopen_mr
(
merge_request
,
current_user
)
create_event
(
merge_request
,
current_user
,
Event
::
REOPENED
)
create_
record_
event
(
merge_request
,
current_user
,
Event
::
REOPENED
)
end
def
merge_mr
(
merge_request
,
current_user
)
create_event
(
merge_request
,
current_user
,
Event
::
MERGED
)
create_
record_
event
(
merge_request
,
current_user
,
Event
::
MERGED
)
end
def
open_milestone
(
milestone
,
current_user
)
create_event
(
milestone
,
current_user
,
Event
::
CREATED
)
create_
record_
event
(
milestone
,
current_user
,
Event
::
CREATED
)
end
def
close_milestone
(
milestone
,
current_user
)
create_event
(
milestone
,
current_user
,
Event
::
CLOSED
)
create_
record_
event
(
milestone
,
current_user
,
Event
::
CLOSED
)
end
def
reopen_milestone
(
milestone
,
current_user
)
create_event
(
milestone
,
current_user
,
Event
::
REOPENED
)
create_
record_
event
(
milestone
,
current_user
,
Event
::
REOPENED
)
end
def
leave_note
(
note
,
current_user
)
create_event
(
note
,
current_user
,
Event
::
COMMENTED
)
create_record_event
(
note
,
current_user
,
Event
::
COMMENTED
)
end
def
join_project
(
project
,
current_user
)
create_event
(
project
,
current_user
,
Event
::
JOINED
)
end
def
leave_project
(
project
,
current_user
)
create_event
(
project
,
current_user
,
Event
::
LEFT
)
end
def
push_ref
(
project
,
current_user
,
ref
,
action
=
'add'
,
prefix
=
'refs/heads'
)
commit
=
project
.
repository
.
commit
(
ref
.
target
)
if
action
.
to_s
==
'add'
before
=
'00000000'
after
=
commit
.
id
else
before
=
commit
.
id
after
=
'00000000'
end
data
=
{
ref:
"
#{
prefix
}
/
#{
ref
.
name
}
"
,
before:
before
,
after:
after
}
push
(
project
,
current_user
,
data
)
end
def
push
(
project
,
current_user
,
push_data
)
create_event
(
project
,
current_user
,
Event
::
PUSHED
,
data:
push_data
)
end
private
def
create_event
(
record
,
current_user
,
status
)
Event
.
create
(
project:
record
.
project
,
target_id:
record
.
id
,
target_type:
record
.
class
.
name
,
def
create_record_event
(
record
,
current_user
,
status
)
create_event
(
record
.
project
,
current_user
,
status
,
target_id:
record
.
id
,
target_type:
record
.
class
.
name
)
end
def
create_event
(
project
,
current_user
,
status
,
attributes
=
{})
attributes
.
reverse_merge!
(
project:
project
,
action:
status
,
author_id:
current_user
.
id
)
Event
.
create
(
attributes
)
end
end
app/services/git_push_service.rb
View file @
07d05d2d
...
...
@@ -52,7 +52,7 @@ class GitPushService
end
@push_data
=
post_receive_data
(
oldrev
,
newrev
,
ref
)
create_push_event
(
@push_data
)
EventCreateService
.
new
.
push
(
project
,
user
,
@push_data
)
project
.
execute_hooks
(
@push_data
.
dup
,
:push_hooks
)
project
.
execute_services
(
@push_data
.
dup
)
end
...
...
@@ -60,15 +60,6 @@ class GitPushService
protected
def
create_push_event
(
push_data
)
Event
.
create!
(
project:
project
,
action:
Event
::
PUSHED
,
data:
push_data
,
author_id:
push_data
[
:user_id
]
)
end
# Extract any GFM references from the pushed commit messages. If the configured issue-closing regex is matched,
# close the referenced Issue. Create cross-reference Notes corresponding to any other referenced Mentionables.
def
process_commit_messages
(
ref
)
...
...
app/services/git_tag_push_service.rb
View file @
07d05d2d
...
...
@@ -5,7 +5,7 @@ class GitTagPushService
@project
,
@user
=
project
,
user
@push_data
=
create_push_data
(
oldrev
,
newrev
,
ref
)
create_push_event
EventCreateService
.
new
.
push
(
project
,
user
,
@push_data
)
project
.
repository
.
expire_cache
project
.
execute_hooks
(
@push_data
.
dup
,
:tag_push_hooks
)
...
...
@@ -22,13 +22,4 @@ class GitTagPushService
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
[])
end
def
create_push_event
Event
.
create!
(
project:
project
,
action:
Event
::
PUSHED
,
data:
push_data
,
author_id:
push_data
[
:user_id
]
)
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