How to use custom Git Hooks


#1

Important Notes

  • This post is based on Gogs 0.10.8.0307.

This feature currently is not working on Windows

Gogs provides custom Git hooks functionality to limited users. By default, only admin users are allowed to setting custom Git hooks. Regular users can grant permission by admins from Admin Panel - Users:

After that, users are able to see the Git hook management panel in repository settings:

Where green dot means you have customized corresponding type of Git hook, and grey dot represents currently not in use.

The hook content is exactly the same as native Git hooks:

For convenience, Gogs also provides Gogs-related values via environment variables:

+------------------------+-----------------------------------------------------+
|          name          |                     description                     |
+------------------------+-----------------------------------------------------+
| `GOGS_AUTH_USER_ID`    | User ID who made the push                           |
| `GOGS_AUTH_USER_NAME`  | User name who made the push (can have mixed cases)  |
| `GOGS_AUTH_USER_EMAIL` | User email who made the push (can have mixed cases) |
| `GOGS_REPO_OWNER_NAME` | Owner name of the repository                        |
| `GOGS_REPO_ID`         | Repository ID                                       |
| `GOGS_REPO_NAME`       | Repository name                                     |
+------------------------+-----------------------------------------------------+

:speech_balloon: Please leave comments if you have any questions or concerns about this post.