Giter Club home page Giter Club logo

git-hooks-bootstrap's Introduction

git hooks bootstrap

This is a collection of git "server" hooks (i.e. hooks to check commits being pushed to the server).

The collection is built for Atlassian Bitbucket Server (formerly known as Atlassian Stash) with the External Hooks plugin, which implements pre- and post- (async) hooks on git push á la gitolite.

Beyond the dependencies on the environment variables below, the scripts are abstract and can be used in any other environment. They should also run with minimal intervention/configuration, but they are not meant to be an off-the-shelf product - merely a bootstrap and a FAQ solution for a common set of questions: filtering branch names, filtering whitespace commits, notifying external systems of commits referencing a ticket, etc.

Structure

Hooks should be organized by project/repository.

Each project/repository folder should contain a pre and post symlinking to the root hook.tpl, and then implement pre.process_range.<function> and/or post.process_range.<function> scripts, which will be run in alphabetical order.

These process_range scripts will be called once per range i.e. ref being updated from one SHA to another. Each process_range script has a process_range, process_sha (and maybe a process_file), process_ref functions that are run in a flow like this:

  • process range
    • each range has 1+ commits (SHAs), so process those
      • each commits has 1+ files, so process those
  • process ref

Have a look at the existing hooks on how to write new ones. A template for the *.process_range.* scripts exist in hook.process_range.tpl.

Environment variables

Each shell script can make use of the following environment variables:

From https://github.com/ngsru/atlassian-external-hooks/wiki/Configuration:

Also, there are number of environment variables, that will be passed to executable:

  • STASH_USER_NAME --- name of the user that invokes a push;
  • STASH_USER_EMAIL --- e-mail of that user;
  • STASH_REPO_NAME --- repository name, without .git part;
  • STASH_IS_ADMIN --- either "true" or "false", when user either is repo admin or not.
  • STASH_PROJECT_NAME --- human-readable name of the project repository belongs to;
  • STASH_PROJECT_KEY --- project key for the repository;
  • STASH_BASE_URL --- base URL where Stash instance is hosted;
  • STASH_REPO_CLONE_SSH --- SSH URL which can be used for cloning repo;
  • STASH_REPO_CLONE_HTTP --- same, but for HTTP;

As well as

STASH_ADMIN_HOME --- e.g. /home/atlstash/stash-admin STASH_WWW_BASE_URL --- e.g. https://stash.example.com STASH_GIT_BASE_URL --- e.g. [email protected] STASH_REPO_MAIN_REFS --- e.g. refs/heads/master refs/heads/develop

Defaults for these environment variables are provided in the root of env.sh, that can be overridden by project/repository/env.sh.

Install stash-admin as a gitolite-admin counterpart

Gitolite has a special gitolite-admin repository that hosts the gitolite configuration.

Similarly, you can clone this repository and push it as INFRA/stash-admin to your Atlassian Stash/Bitbucket Server instance. Set up the post External Hook to point to INFRA/stash-admin/post. Next time you push changes, your changes will take effect immediately.

Integration

jenkins-reset-atlassian-pr and jenkins-notify-atlassian-pr are two shell scripts meant to be run as part of a Jenkins job (build step, and post-build step respectively) and report to Stash. In a similar fashion, when adapted, they can be used from within a post- (async) hook, and report back to Atlassian BitBucket Server.

git-hooks-bootstrap's People

Contributors

andreineculau avatar

Stargazers

Kristian Sällberg avatar

Watchers

 avatar James Cloos avatar  avatar

git-hooks-bootstrap's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.