yo1995 / My_programming_question_list

🏈 A *curated* list for my daily wonders about programming. Post in issues, categorize in repo.
0 stars 0 forks source link

Git hooks vs web hooks #6

Open yo1995 opened 4 years ago

yo1995 commented 4 years ago

General

image

As we are looking for server-side solutions for README style check, local pre-commit hooks are ruled out in the first place, even though they might work well for this purpose. Nevertheless, I'll cover a little bit on that.

Local pre-commit hooks

Local hooks affect only the repository in which they reside. As you read through this section, remember that each developer can alter their own local hooks, so you can’t use them as a way to enforce a commit policy.

The pre-commit script is executed every time you run git commit before Git asks the developer for a commit message or generates a commit object. You can use this hook to inspect the snapshot that is about to be committed. For example, you may want to run some automated tests that make sure the commit doesn’t break any existing functionality.

In short, pre-commit hooks are setup locally, and can perform whatever task you want, since it is just like to trigger a Python script once you use git commit.

Remote/Server-side pre-receive hooks

image

👆 Looks like in console

The pre-receive hook is executed every time somebody uses git push to push commits to the repository. It should always reside in the remote repository that is the destination of the push, not in the originating repository.

pre-receive hooks are most suitable for commit metadata related checks that are very lightweight, as the script need to run really fast on each incoming commit. For example, tasks such as enforcing commit message format, check committed file extensions, check file size, etc, can be run with pre-receive hook scripts.

🌟 Remote GitHub status check web-hook

Take a look at ../settings/hooks/new

Finally we come to status check. The basic idea is also to trigger a script when certain events take place, but it is highly customizable with GitHub APIs. The most common web hooks are for push events - when each push happens, the web hook get triggered, and a script such that

etc. can be executed sequentially. GitHub Actions is a lightweight tool for creating web hooks, and per DevOps we seem to use Jenkins as the server.

This is my recommended option.

GitHub best practices references

yo1995 commented 4 years ago

A running list of steps I took