|
8 | 8 | # source => 'puppet:///modules/my_module/post-receive',
|
9 | 9 | # }
|
10 | 10 | #
|
| 11 | +# @example Calculate hashed storage path |
| 12 | +# gitlab::custom_hook { 'my_custom_hook': |
| 13 | +# project => 93, |
| 14 | +# type => 'post-receive', |
| 15 | +# source => 'puppet:///modules/my_module/post-receive', |
| 16 | +# } |
| 17 | +# # Hook path will be `@hashed/6e/40/6e4001871c0cf27c7634ef1dc478408f642410fd3a444e2a88e301f5c4a35a4d` |
| 18 | +# |
| 19 | +# @param project The GitLab project name, or the hashed directory name or project ID number |
11 | 20 | # @param namespace The GitLab group namespace for the project.
|
12 |
| -# @param project The GitLab project name. |
13 | 21 | # @param type The custom hook type. Should be one of pre-receive, post-receive, or update.
|
14 | 22 | # @param content Specify the custom hook contents either as a string or using the template function. If this paramter is specified source parameter must not be present.
|
15 | 23 | # @param source Specify a file source path to populate the custom hook contents. If this paramter is specified content parameter must not be present.
|
16 | 24 | # @param repos_path The GitLab shell repos path. This defaults to '/var/opt/gitlab/git-data/repositories' if not present.
|
| 25 | +# @param hashed_storage Whether to treat the project name as a hashed storage directory name or ID number |
17 | 26 | define gitlab::custom_hook (
|
18 |
| - String $namespace, |
19 |
| - String $project, |
| 27 | + Variant[String,Integer] $project, |
20 | 28 | Enum['update', 'post-receive', 'pre-receive'] $type,
|
| 29 | + Optional[String] $namespace = undef, |
21 | 30 | Optional[String] $content = undef,
|
22 | 31 | Optional[String] $source = undef,
|
23 | 32 | Optional[Stdlib::Absolutepath] $repos_path = undef,
|
| 33 | + Optional[Boolean] $hashed_storage = false, |
24 | 34 | ) {
|
25 | 35 | if $repos_path {
|
26 | 36 | $_repos_path = $repos_path
|
|
38 | 48 | fail("gitlab::custom_hook[${name}]: Must specify either content or source, but not both")
|
39 | 49 | }
|
40 | 50 |
|
41 |
| - $hook_path = "${_repos_path}/${namespace}/${project}.git/custom_hooks" |
| 51 | + if ! ($hashed_storage) and ! ($namespace) { |
| 52 | + fail("gitlab::custom_hook[${name}]: Must specify either namespace or hashed_storage") |
| 53 | + } |
| 54 | + |
| 55 | + if ($hashed_storage) and ($namespace) { |
| 56 | + fail("gitlab::custom_hook[${name}]: Must specify either namespace or hashed_storage, but not both") |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + if ($namespace) { |
| 61 | + $hook_path = "${_repos_path}/${namespace}/${project}.git/custom_hooks" |
| 62 | + } elseif ($hashed_storage) { |
| 63 | + if ($project.is_a(Integer)) { |
| 64 | + $_project_hash = sha256(String($project)) |
| 65 | + } else { |
| 66 | + $_project_hash = $project |
| 67 | + } |
| 68 | + |
| 69 | + if ($_project_hash.length != 64) { |
| 70 | + fail("gitlab::custom_hook[${name}]: Invalid project hash ${_project_hash}") |
| 71 | + } |
| 72 | + |
| 73 | + $hook_path = "${_repos_path}/@hashed/${_project_hash[0,2]}/${_project_hash[2,2]}/${_project_hash}.git/custom_hooks" |
| 74 | + } |
42 | 75 |
|
43 | 76 | File {
|
44 | 77 | owner => $gitlab::service_user,
|
|
0 commit comments