Commit bdb54a00 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'dz-file-hooks-dir-support' into 'master'

Add support for /file_hooks directory

See merge request gitlab-org/gitlab!29675
parents b26ba7f0 fd5448ef
......@@ -38,3 +38,4 @@ exclude_paths:
- backups/
- coverage-javascript/
- plugins/
- file_hooks/
......@@ -25,6 +25,7 @@ AllCops:
- 'generator_templates/**/*'
- 'builds/**/*'
- 'plugins/**/*'
- 'file_hooks/**/*'
CacheRootDirectory: tmp
Cop/StaticTranslationDefinition:
......
---
title: Add support for /file_hooks directory
merge_request: 29675
author:
type: changed
......@@ -23,22 +23,22 @@ see the [system hooks] documentation.
## Setup
The file hooks must be placed directly into the `plugins` directory, subdirectories
The file hooks must be placed directly into the `file_hooks` directory, subdirectories
will be ignored. There is an
[`example` directory inside `plugins`](https://gitlab.com/gitlab-org/gitlab/tree/master/plugins/examples)
[`example` directory inside `file_hooks`](https://gitlab.com/gitlab-org/gitlab/tree/master/file_hooks/examples)
where you can find some basic examples.
Follow the steps below to set up a custom hook:
1. On the GitLab server, navigate to the plugin directory.
For an installation from source the path is usually
`/home/git/gitlab/plugins/`. For Omnibus installs the path is
usually `/opt/gitlab/embedded/service/gitlab-rails/plugins`.
`/home/git/gitlab/file_hooks/`. For Omnibus installs the path is
usually `/opt/gitlab/embedded/service/gitlab-rails/file_hooks`.
For [highly available] configurations, your hook file should exist on each
application server.
1. Inside the `plugins` directory, create a file with a name of your choice,
1. Inside the `file_hooks` directory, create a file with a name of your choice,
without spaces or special characters.
1. Make the hook file executable and make sure it's owned by the Git user.
1. Write the code to make the file hook function as expected. That can be
......@@ -106,9 +106,9 @@ bundle exec rake file_hooks:validate RAILS_ENV=production
Example of output:
```plaintext
Validating file hooks from /plugins directory
* /home/git/gitlab/plugins/save_to_file.clj succeed (zero exit code)
* /home/git/gitlab/plugins/save_to_file.rb failure (non-zero exit code)
Validating file hooks from /file_hooks directory
* /home/git/gitlab/file_hooks/save_to_file.clj succeed (zero exit code)
* /home/git/gitlab/file_hooks/save_to_file.rb failure (non-zero exit code)
```
[system hooks]: ../system_hooks/system_hooks.md
......
*
!*/
!.gitignore
!.gitkeep
!examples/*
......@@ -3,16 +3,17 @@
module Gitlab
module FileHook
def self.any?
plugin_glob.any? { |entry| File.file?(entry) }
dir_glob.any? { |entry| File.file?(entry) }
end
def self.files
plugin_glob.select { |entry| File.file?(entry) }
dir_glob.select { |entry| File.file?(entry) }
end
def self.plugin_glob
Dir.glob(Rails.root.join('plugins/*'))
def self.dir_glob
Dir.glob([Rails.root.join('file_hooks/*'), Rails.root.join('plugins/*')])
end
private_class_method :dir_glob
def self.execute_all_async(data)
args = files.map { |file| [file, data] }
......
namespace :file_hooks do
desc 'Validate existing plugins'
desc 'Validate existing file hooks'
task validate: :environment do
puts 'Validating file hooks from /plugins directory'
puts 'Validating file hooks from /file_hooks and /plugins directories'
Gitlab::FileHook.files.each do |file|
success, message = Gitlab::FileHook.execute(file, Gitlab::DataBuilder::Push::SAMPLE_DATA)
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
describe Gitlab::FileHook do
let(:file_hook) { Rails.root.join('plugins', 'test.rb') }
let(:file_hook) { Rails.root.join('file_hooks', 'test.rb') }
let(:tmp_file) { Tempfile.new('file_hook-dump') }
let(:file_hook_source) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment