Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
docs-action committed Nov 13, 2023
1 parent 0ff4b3f commit 6e3c43e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions assets/js/search-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2297,14 +2297,14 @@
},"328": {
"doc": "Lua Hooks",
"title": "Action File Lua Hook Properties",
"content": "See the Action configuration for overall configuration schema and details. | Property | Description | Data Type | Required | Default Value | . | args | One or more arguments to pass to the hook | Dictionary | false |   | . | script | An inline Lua script | String | either this or script_file must be specified |   | . | script_file | The lakeFS path to a Lua script | String | either this or script must be specified |   | . ",
"content": "See the Action configuration for overall configuration schema and details. | Property | Description | Data Type | Required | Default Value | . | args | One or more arguments to pass to the hook | Dictionary | false |   | . | script | An inline Lua script | String | either this or script_path must be specified |   | . | script_path | The path in lakeFS to a Lua script | String | either this or script must be specified |   | . ",
"url": "/howto/hooks/lua.html#action-file-lua-hook-properties",

"relUrl": "/howto/hooks/lua.html#action-file-lua-hook-properties"
},"329": {
"doc": "Lua Hooks",
"title": "Example Lua Hooks",
"content": "For more examples and configuration samples, check out the examples/hooks/ directory in the lakeFS repository. You’ll also find step-by-step examples of hooks in action in the lakeFS samples repository. Display information about an event . This example will print out a JSON representation of the event that occurred: . name: dump_all on: post-commit: post-merge: post-create-tag: post-create-branch: hooks: - id: dump_event type: lua properties: script: | json = require(\"encoding/json\") print(json.marshal(action)) . Ensure that a commit includes a mandatory metadata field . A more useful example: ensure every commit contains a required metadata field: . name: pre commit metadata field check on: pre-commit: branches: - main - dev hooks: - id: ensure_commit_metadata type: lua properties: args: notebook_url: {\"pattern\": \"my-jupyter.example.com/.*\"} spark_version: {} script: | regexp = require(\"regexp\") for k, props in pairs(args) do current_value = action.commit.metadata[k] if current_value == nil then error(\"missing mandatory metadata field: \" .. k) end if props.pattern and not regexp.match(props.pattern, current_value) then error(\"current value for commit metadata field \" .. k .. \" does not match pattern: \" .. props.pattern .. \" - got: \" .. current_value) end end . For more examples and configuration samples, check out the examples/hooks/ directory in the lakeFS repository. ",
"content": "For more examples and configuration samples, check out the examples/hooks/ directory in the lakeFS repository. You’ll also find step-by-step examples of hooks in action in the lakeFS samples repository. Display information about an event . This example will print out a JSON representation of the event that occurred: . name: dump_all on: post-commit: post-merge: post-create-tag: post-create-branch: hooks: - id: dump_event type: lua properties: script: | json = require(\"encoding/json\") print(json.marshal(action)) . Ensure that a commit includes a mandatory metadata field . A more useful example: ensure every commit contains a required metadata field: . name: pre commit metadata field check on: pre-commit: branches: - main - dev hooks: - id: ensure_commit_metadata type: lua properties: args: notebook_url: {\"pattern\": \"my-jupyter.example.com/.*\"} spark_version: {} script_path: lua_hooks/ensure_metadata_field.lua . Lua code at lakefs://repo/main/lua_hooks/ensure_metadata_field.lua: . regexp = require(\"regexp\") for k, props in pairs(args) do current_value = action.commit.metadata[k] if current_value == nil then error(\"missing mandatory metadata field: \" .. k) end if props.pattern and not regexp.match(props.pattern, current_value) then error(\"current value for commit metadata field \" .. k .. \" does not match pattern: \" .. props.pattern .. \" - got: \" .. current_value) end end . For more examples and configuration samples, check out the examples/hooks/ directory in the lakeFS repository. ",
"url": "/howto/hooks/lua.html#example-lua-hooks",

"relUrl": "/howto/hooks/lua.html#example-lua-hooks"
Expand Down
32 changes: 18 additions & 14 deletions howto/hooks/lua.html
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,12 @@ <h2 id="action-file-lua-hook-properties">
<td><code class="language-plaintext highlighter-rouge">script</code></td>
<td>An inline Lua script</td>
<td>String</td>
<td>either this or <code class="language-plaintext highlighter-rouge">script_file</code> must be specified</td>
<td>either this or <code class="language-plaintext highlighter-rouge">script_path</code> must be specified</td>
<td> </td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">script_file</code></td>
<td>The lakeFS path to a Lua script</td>
<td><code class="language-plaintext highlighter-rouge">script_path</code></td>
<td>The path in lakeFS to a Lua script</td>
<td>String</td>
<td>either this or <code class="language-plaintext highlighter-rouge">script</code> must be specified</td>
<td> </td>
Expand Down Expand Up @@ -661,17 +661,21 @@ <h3 id="ensure-that-a-commit-includes-a-mandatory-metadata-field">
<span class="na">args</span><span class="pi">:</span>
<span class="na">notebook_url</span><span class="pi">:</span> <span class="pi">{</span><span class="s2">"</span><span class="s">pattern"</span><span class="pi">:</span> <span class="s2">"</span><span class="s">my-jupyter.example.com/.*"</span><span class="pi">}</span>
<span class="na">spark_version</span><span class="pi">:</span> <span class="pi">{}</span>
<span class="na">script</span><span class="pi">:</span> <span class="pi">|</span>
<span class="s">regexp = require("regexp")</span>
<span class="s">for k, props in pairs(args) do</span>
<span class="s">current_value = action.commit.metadata[k]</span>
<span class="s">if current_value == nil then</span>
<span class="s">error("missing mandatory metadata field: " .. k)</span>
<span class="s">end</span>
<span class="s">if props.pattern and not regexp.match(props.pattern, current_value) then</span>
<span class="s">error("current value for commit metadata field " .. k .. " does not match pattern: " .. props.pattern .. " - got: " .. current_value)</span>
<span class="s">end</span>
<span class="s">end</span>
<span class="na">script_path</span><span class="pi">:</span> <span class="s">lua_hooks/ensure_metadata_field.lua</span>
</code></pre></div></div>

<p>Lua code at <code class="language-plaintext highlighter-rouge">lakefs://repo/main/lua_hooks/ensure_metadata_field.lua</code>:</p>

<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">regexp</span> <span class="o">=</span> <span class="nb">require</span><span class="p">(</span><span class="s2">"regexp"</span><span class="p">)</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">props</span> <span class="k">in</span> <span class="nb">pairs</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="k">do</span>
<span class="n">current_value</span> <span class="o">=</span> <span class="n">action</span><span class="p">.</span><span class="n">commit</span><span class="p">.</span><span class="n">metadata</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="k">if</span> <span class="n">current_value</span> <span class="o">==</span> <span class="kc">nil</span> <span class="k">then</span>
<span class="nb">error</span><span class="p">(</span><span class="s2">"missing mandatory metadata field: "</span> <span class="o">..</span> <span class="n">k</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">if</span> <span class="n">props</span><span class="p">.</span><span class="n">pattern</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">regexp</span><span class="p">.</span><span class="n">match</span><span class="p">(</span><span class="n">props</span><span class="p">.</span><span class="n">pattern</span><span class="p">,</span> <span class="n">current_value</span><span class="p">)</span> <span class="k">then</span>
<span class="nb">error</span><span class="p">(</span><span class="s2">"current value for commit metadata field "</span> <span class="o">..</span> <span class="n">k</span> <span class="o">..</span> <span class="s2">" does not match pattern: "</span> <span class="o">..</span> <span class="n">props</span><span class="p">.</span><span class="n">pattern</span> <span class="o">..</span> <span class="s2">" - got: "</span> <span class="o">..</span> <span class="n">current_value</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<p>For more examples and configuration samples, check out the <a href="https://github.com/treeverse/lakeFS/tree/master/examples/hooks">examples/hooks/</a> directory in the lakeFS repository.</p>
Expand Down

0 comments on commit 6e3c43e

Please sign in to comment.