-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Hooks
Dawa Ometto edited this page Nov 29, 2022
·
4 revisions
Gollum also supports hooks: pieces of code, written by you, that are run when specific events occur. Gollum Hooks exist for the following events:
-
:post_wiki_initialize
- Ran immediately after the wiki is first setup.
-
wiki
object is provided in the block (see example below).
-
:post_commit
- ran immediately after each commit -- so a page creation, edit, file upload, etc.
-
Committer
object and SHA of the commit are provided to the block (see example below).
You can register multiple Hooks (i.e. multiple blocks of code to be ran) for each event. To register a Hook, add e.g. the following to your config.rb (and don't forget to enable --config
):
Gollum::Hook.register(:post_wiki_initialize, :print_info_hook) do |wiki|
puts "You can execute any ruby code here, like printing information on the wiki object that has just been initialized: #{wiki}."
end
Below are some examples of typical use cases.
You can define a hook to trigger one of the git hooks in your repository:
Gollum::Hook.register(:post_commit, :hook_id) do |committer, sha1|
system('/path/to/wiki/.git/hooks/post-commit')
end
Gollum::Hook.register(:post_commit, :hook_id) do |committer, sha1|
committer.wiki.repo.git.pull('origin', committer.wiki.ref)
committer.wiki.repo.git.push('origin', committer.wiki.ref)
end