I have my source code hosted on gitlab repository, and I intend to run a python script if it detects any new push or commit in that gitlab repository. How can I catch this event ?
You can use Jenkins or AWS CodeStar to check for commits and then invoke your function inside Jenkins or AWS code build, or if you have a serverless function you can invoke it there. Setting a complete pipeline you will need some knowledge of CI/CD and DevOps. This is a pretty standard way of doing it.
A more get-around of doing this would be to use Gitlab API to check for commits every few minutes and invoke your code.
How can I execute a python script as soon as there is a new commit on my gitlab repository?