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
1df225bb
Commit
1df225bb
authored
Sep 29, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3006 from jweslley/master
add rake tasks for web hooks management
parents
cbb5b000
5a906b1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
0 deletions
+96
-0
doc/raketasks/web_hooks.md
doc/raketasks/web_hooks.md
+31
-0
lib/tasks/gitlab/web_hook.rake
lib/tasks/gitlab/web_hook.rake
+65
-0
No files found.
doc/raketasks/web_hooks.md
0 → 100644
View file @
1df225bb
### Add a web hook for **ALL** projects:
RAILS_ENV=production bundle exec rake gitlab:web_hook:add URL="http://example.com/hook"
### Add a web hook for projects in a given **NAMESPACE**:
RAILS_ENV=production bundle exec rake gitlab:web_hook:add URL="http://example.com/hook" NAMESPACE=acme
### Remove a web hook from **ALL** projects using:
RAILS_ENV=production bundle exec rake gitlab:web_hook:rm URL="http://example.com/hook"
### Remove a web hook from projects in a given **NAMESPACE**:
RAILS_ENV=production bundle exec rake gitlab:web_hook:rm URL="http://example.com/hook" NAMESPACE=acme
### List **ALL** web hooks:
RAILS_ENV=production bundle exec rake gitlab:web_hook:list
### List the web hooks from projects in a given **NAMESPACE**:
RAILS_ENV=production bundle exec rake gitlab:web_hook:list NAMESPACE=/
> Note: `/` is the global namespace.
lib/tasks/gitlab/web_hook.rake
0 → 100644
View file @
1df225bb
namespace
:gitlab
do
namespace
:web_hook
do
desc
"GITLAB | Adds a web hook to the projects"
task
:add
=>
:environment
do
web_hook_url
=
ENV
[
'URL'
]
namespace_path
=
ENV
[
'NAMESPACE'
]
projects
=
find_projects
(
namespace_path
)
puts
"Adding web hook '
#{
web_hook_url
}
' to:"
projects
.
find_each
(
batch_size:
1000
)
do
|
project
|
print
"-
#{
project
.
name
}
... "
web_hook
=
project
.
hooks
.
new
(
url:
web_hook_url
)
if
web_hook
.
save
puts
"added"
.
green
else
print
"failed"
.
red
puts
" [
#{
web_hook
.
errors
.
full_messages
.
to_sentence
}
]"
end
end
end
desc
"GITLAB | Remove a web hook from the projects"
task
:rm
=>
:environment
do
web_hook_url
=
ENV
[
'URL'
]
namespace_path
=
ENV
[
'NAMESPACE'
]
projects
=
find_projects
(
namespace_path
)
projects_ids
=
projects
.
pluck
(
:id
)
puts
"Removing web hooks with the url '
#{
web_hook_url
}
' ... "
count
=
WebHook
.
where
(
url:
web_hook_url
,
project_id:
projects_ids
,
type:
'ProjectHook'
).
delete_all
puts
"
#{
count
}
web hooks were removed."
end
desc
"GITLAB | List web hooks"
task
:list
=>
:environment
do
namespace_path
=
ENV
[
'NAMESPACE'
]
projects
=
find_projects
(
namespace_path
)
web_hooks
=
projects
.
all
.
map
(
&
:hooks
).
flatten
web_hooks
.
each
do
|
hook
|
puts
"
#{
hook
.
project
.
name
.
truncate
(
20
).
ljust
(
20
)
}
->
#{
hook
.
url
}
"
end
puts
"
\n
#{
web_hooks
.
size
}
web hooks found."
end
end
def
find_projects
(
namespace_path
)
if
namespace_path
.
blank?
Project
elsif
namespace_path
==
'/'
Project
.
where
(
namespace_id:
nil
)
else
namespace
=
Namespace
.
where
(
path:
namespace_path
).
first
if
namespace
Project
.
where
(
namespace_id:
namespace
.
id
)
else
puts
"Namespace not found:
#{
namespace_path
}
"
.
red
exit
2
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