decc974c796912b653629e0cc49fa8539ba47f40

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

docs: add hooks section

Diff

 1diff --git a/README.md b/README.md
 2index c78a71970e689eb106dd099d054c52fef32ce967..c2179ba41926f951224e3e8efe7e79da303c1b42 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -122,6 +122,9 @@ self-explanatory and will look like this:
 6 # This is the name that will be displayed in the UI.
 7 name: "Soft Serve"
 8 
 9+# Log format to use. Valid values are "json", "logfmt", and "text".
10+log_format: "text"
11+
12 # The SSH server configuration.
13 ssh:
14   # The address on which the SSH server will listen.
15@@ -139,9 +142,6 @@ ssh:
16   # ssh remotes.
17   client_key_path: "ssh/soft_serve_client"
18 
19-  # The path to the SSH server's internal api private key.
20-  internal_key_path: "ssh/soft_serve_internal"
21-
22   # The maximum number of seconds a connection can take.
23   # A value of 0 means no timeout.
24   max_timeout: 0
25@@ -519,6 +519,65 @@ You can copy text to your clipboard over SSH. For instance, you can press
26     Copying over SSH depends on your terminal support of OSC52. Refer to
27     [go-osc52](https://github.com/aymanbagabas/go-osc52) for more information.
28 
29+## Hooks
30+
31+Soft Serve supports git server-side hooks `pre-receive`, `update`,
32+`post-update`, and `post-receive`. This means you can define your own hooks to
33+run on repository push events. Hooks can be defined as a per-repository hook,
34+and/or global hooks that get run for all repositories.
35+
36+You can find per-repository hooks under the repository `hooks` directory.
37+
38+Globs hooks can be found in your `SOFT_SERVE_DATA_PATH` directory under
39+`hooks`. Defining global hooks is useful if you want to run CI/CD for example.
40+
41+Here's an example of sending a message after receiving a push event. Create an
42+executable file `<data path>/hooks/update`:
43+
44+```sh
45+#!/bin/sh
46+#
47+# An example hook script to echo information about the push
48+# and send it to the client.
49+
50+refname="$1"
51+oldrev="$2"
52+newrev="$3"
53+
54+# Safety check
55+if [ -z "$GIT_DIR" ]; then
56+        echo "Don't run this script from the command line." >&2
57+        echo " (if you want, you could supply GIT_DIR then run" >&2
58+        echo "  $0 <ref> <oldrev> <newrev>)" >&2
59+        exit 1
60+fi
61+
62+if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
63+        echo "usage: $0 <ref> <oldrev> <newrev>" >&2
64+        exit 1
65+fi
66+
67+# Check types
68+# if $newrev is 0000...0000, it's a commit to delete a ref.
69+zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
70+if [ "$newrev" = "$zero" ]; then
71+        newrev_type=delete
72+else
73+        newrev_type=$(git cat-file -t $newrev)
74+fi
75+
76+echo "Hi from Soft Serve update hook!"
77+echo
78+echo "RefName: $refname"
79+echo "Change Type: $newrev_type"
80+echo "Old SHA1: $oldrev"
81+echo "New SHA1: $newrev"
82+
83+exit 0
84+```
85+
86+Now, you should get a message after pushing changes to any repository.
87+
88 ## A note about RSA keys
89 
90 Unfortunately, due to a shortcoming in Go’s `x/crypto/ssh` package, Soft Serve