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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
177e345a
Commit
177e345a
authored
Feb 21, 2020
by
Alexandru Croitor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup and compact ChangeMilestoneService implementation
Minor cleanup of the ChangeMilestoneService service.
parent
db662ee6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
28 deletions
+14
-28
app/services/resource_events/change_milestone_service.rb
app/services/resource_events/change_milestone_service.rb
+14
-28
No files found.
app/services/resource_events/change_milestone_service.rb
View file @
177e345a
...
...
@@ -2,49 +2,35 @@
module
ResourceEvents
class
ChangeMilestoneService
attr_reader
:resource
,
:user
,
:event_created_at
,
:
resource_args
attr_reader
:resource
,
:user
,
:event_created_at
,
:
milestone
def
initialize
(
resource
:,
user
:,
created_at:
Time
.
now
)
@resource
=
resource
@user
=
user
@event_created_at
=
created_at
@resource_args
=
{
user_id:
user
.
id
,
created_at:
event_created_at
}
@milestone
=
resource
&
.
milestone
end
def
execute
args
=
build_resource_args
action
=
if
milestone
.
nil?
:remove
else
:add
end
ResourceMilestoneEvent
.
create
(
build_resource_args
)
record
=
args
.
merge
(
milestone_id:
milestone
&
.
id
,
action:
ResourceMilestoneEvent
.
actions
[
action
])
create_event
(
record
)
resource
.
expire_note_etag_cache
end
private
def
milestone
resource
&
.
milestone
end
def
create_event
(
record
)
ResourceMilestoneEvent
.
create
(
record
)
resource
.
expire_note_etag_cache
end
def
build_resource_args
key
=
resource
.
class
.
name
.
underscore
.
foreign_key
action
=
milestone
.
blank?
?
:remove
:
:add
key
=
resource
.
class
.
name
.
foreign_key
resource_args
.
merge
(
key
=>
resource
.
id
,
state:
ResourceMilestoneEvent
.
states
[
resource
.
state
])
{
user_id:
user
.
id
,
created_at:
event_created_at
,
milestone_id:
milestone
&
.
id
,
state:
ResourceMilestoneEvent
.
states
[
resource
.
state
],
action:
ResourceMilestoneEvent
.
actions
[
action
],
key
=>
resource
.
id
}
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