BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ac92d70d
Commit
ac92d70d
authored
Dec 04, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract concern for hook triggers
parent
88832ba9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
23 deletions
+67
-23
triggerable_hooks.rb
app/models/concerns/triggerable_hooks.rb
+31
-0
project_hook.rb
app/models/hooks/project_hook.rb
+12
-14
system_hook.rb
app/models/hooks/system_hook.rb
+7
-9
triggerable_hooks_spec.rb
spec/models/concerns/triggerable_hooks_spec.rb
+17
-0
No files found.
app/models/concerns/triggerable_hooks.rb
0 → 100644
View file @
ac92d70d
module
TriggerableHooks
AVAILABLE_TRIGGERS
=
{
repository_update_hooks: :repository_update_events
,
push_hooks: :push_events
,
tag_push_hooks: :tag_push_events
,
issue_hooks: :issues_events
,
confidential_issue_hooks: :confidential_issues_events
,
note_hooks: :note_events
,
merge_request_hooks: :merge_requests_events
,
job_hooks: :job_events
,
pipeline_hooks: :pipeline_events
,
wiki_page_hooks: :wiki_page_events
}.
freeze
extend
ActiveSupport
::
Concern
class_methods
do
attr_reader
:triggerable_hooks
private
def
triggerable_hooks
(
hooks
)
triggers
=
AVAILABLE_TRIGGERS
.
slice
(
*
hooks
)
const_set
(
'TRIGGERS'
,
triggers
)
self
::
TRIGGERS
.
each
do
|
trigger
,
event
|
scope
trigger
,
->
{
where
(
event
=>
true
)
}
end
end
end
end
app/models/hooks/project_hook.rb
View file @
ac92d70d
class
ProjectHook
<
WebHook
TRIGGERS
=
{
push_hooks: :push_events
,
tag_push_hooks: :tag_push_events
,
issue_hooks: :issues_events
,
confidential_issue_hooks: :confidential_issues_events
,
note_hooks: :note_events
,
merge_request_hooks: :merge_requests_events
,
job_hooks: :job_events
,
pipeline_hooks: :pipeline_events
,
wiki_page_hooks: :wiki_page_events
}.
freeze
include
TriggerableHooks
TRIGGERS
.
each
do
|
trigger
,
event
|
scope
trigger
,
->
{
where
(
event
=>
true
)
}
end
triggerable_hooks
only:
[
:push_hooks
,
:tag_push_hooks
,
:issue_hooks
,
:confidential_issue_hooks
,
:note_hooks
,
:merge_request_hooks
,
:job_hooks
,
:pipeline_hooks
,
:wiki_page_hooks
]
belongs_to
:project
validates
:project
,
presence:
true
...
...
app/models/hooks/system_hook.rb
View file @
ac92d70d
class
SystemHook
<
WebHook
TRIGGERS
=
{
repository_update_hooks: :repository_update_events
,
push_hooks: :push_events
,
tag_push_hooks: :tag_push_events
,
merge_request_hooks: :merge_requests_events
}.
freeze
include
TriggerableHooks
TRIGGERS
.
each
do
|
trigger
,
event
|
scope
trigger
,
->
{
where
(
event
=>
true
)
}
end
triggerable_hooks
only:
[
:repository_update_hooks
,
:push_hooks
,
:tag_push_hooks
,
:merge_request_hooks
]
default_value_for
:push_events
,
false
default_value_for
:repository_update_events
,
true
...
...
spec/models/concerns/triggerable_hooks_spec.rb
0 → 100644
View file @
ac92d70d
require
'rails_helper'
RSpec
.
describe
TriggerableHooks
do
before
do
class
TestableHook
<
WebHook
include
TriggerableHooks
triggerable_hooks
only:
[
:push_hooks
]
end
end
describe
'scopes'
do
it
'defines a scope for each of the requested triggers'
do
expect
(
TestableHook
).
to
respond_to
:push_hooks
expect
(
TestableHook
).
not_to
respond_to
:tag_push_hooks
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