Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a custom git hook to a GitHub Enterprise repo?

I've fired up an instance of GitHub Enterprise (11.10.272) and created a repository. I've written a pre-receive hook in Ruby which I'd like to use with that repository.

GitHub Enterprise, like regular GitHub, allows the configuration of service hooks. I tried to SSH into the GitHub Enterprise server to create a hook file, but I couldn't find the repo directory. Furthemore, GitHub Enterprise's terms forbid modifying the VM, so I'm not confident this is a great approach.

It seems GitHub:FI supported hooks. The current version of the FI to Enterprise migration tool does not currently support hooks according to Migrating from GitHub:FI.

like image 981
afternoon Avatar asked Jul 08 '12 17:07

afternoon


People also ask

How do you add a hook to GitHub?

To set up a webhook, go to the settings page of your repository or organization. From there, click Webhooks, then Add webhook. Alternatively, you can choose to build and manage a webhook through the Webhooks API. Webhooks require a few configuration options before you can make use of them.

How do I add a pre-commit hook to my repository?

The pre-commit npm package handles this elegantly, allowing you to specify pre-commit hooks in your package. json file. Show activity on this post. Here's a script, add-git-hook.sh, which you can ship as a regular file in the repository and can be executed to append the Git hook to the script file.

How do I add a pre-commit hook to GitHub?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.


3 Answers

I know that this is really old, but GitHub Enterprise 2.6 just came out with pre-receive hooks. More information can be learned here: https://help.github.com/enterprise/admin/guides/developer-workflow/using-pre-receive-hooks-to-enforce-policy/.

I'm fairly certain this will perfectly align with the things you are looking for. Hopefully this either helps OP, or anyone else who stumbles upon this later!

like image 58
brntbeer Avatar answered Oct 02 '22 18:10

brntbeer


Based on my email with GitHub customer support, pre-receive hooks aren't supported for GitHub Enterprise as of May 2013.

We don't have admin access on our GHE box, so we couldn't go in and "fix" this if we wanted to.

They claim that things they do would break if you could reject commits. I assume they mean things like automatic merging of pull requests, but I'm not sure.

They have an extensive set of post-commit webhooks which you could use for post-commit functionality.

I'm looking into building a "pass-through git server" -- basically, poll the GHE API frequently to make a local clone of any repo that exists on certain GHE accounts, and then auto-clone it with custom pre-recieve and post-receive hooks. This would let us clone off the pass-through server, do our pre-receive hooks there, and push approved changes through to GHE. There doesn't seem to be any kind of standard pass-through server for git out there yet, probably because you need to know what repos to clone, which doesn't seem to have a standard git API.

like image 39
Noah Gibbs Avatar answered Oct 02 '22 16:10

Noah Gibbs


GitHub Enterprise seems to store repostories in /data/repositories. Each repository has hooks generated by a template. I can modify these hooks, but that would surely break something. The template hooks seem to look for hooks in another location, but that location is defined in config and I can't find it.

like image 26
afternoon Avatar answered Oct 02 '22 17:10

afternoon