Git Integration With The Bug Genie On Windows

The project management software The Bug Genie has a useful module which integrates Version Control Systems (VCS) into its Issue Tracker to allow for source-code committals to be linked to tracked issues.

The process for setting up this module on Windows requires a number of undocumented modifications. In all honesty the modifications are so simple that I suspect most people make them without much deliberation, however in the hope of saving someone some time I have documented my process below.

The terse process I've documented is for setting up a local git repository with The Bug Genie v3.2.0 by using the PHP CLI method. All of which I did on Windows 7.

  1. Set up The Bug Genie's git hook

    1. Created a symbolic link in the git repository's "hooks" directory with the name "post-receive" which pointed to the file named "tbg-post-receive" in "thebuggenie\modules\vcs_integration\hooks\git"

    2. Modified the file's contents so that the projectid and tbg_cli_path variables contained the correct values according their respective comment.

    3. Prefixed the path to the PHP CLI executable on the line that calls The Bug Genie's CLI interface (the "tbg_cli" file).

      Below is my modified post-receive file...

      #!/bin/sh
      # TheBugGenie post-receive hook for git, for direct access (git and tbg on same machine)
      # To use, this needs to be marked executable, and linked in to your git repo,
      # user@server:/path/to/repo/.git/hooks $
      #   ln -s /tbg_install/modules/vcs_integration/hooks/git/tbg-post-receive post-receive
      #   chmod +x /tbg_install/modules/vcs_integration/hooks/git/tbg-post-receive
      
      #>>>>>> User config
      
      # projectid comes from http://tbg_server/configure/module/vcs_integration
      # on the project settings tab
      projectid=2
      
      # this is the path to the installed thebuggenie.
      tbg_cli_path=M:/WebSer~1/www/bug-genie/
      # this is the path to the PHP CLI
      php_cli_path=M:/WebSer~1/php5/php.exe
      
      #<<<<< End of user config
      
      update_tbg()
      {
          oldhash=$1
          newhash=$2
          refname=$3
      
          # Not working? uncomment the echos and see what's not arriving properly
      
          #echo "Attempting to update tbg with oldhash:$oldhash newhash:$newhash"
          changedfiles=`git diff-tree --name-status -r $newhash --no-commit-id`
          name=`git log ^$oldhash $newhash --pretty=format:"%an <%ae>"`
          log=`git log ^$oldhash $newhash --pretty=format:"%s %b"`
          time=`git log ^$oldhash $newhash --pretty=format:"%ct"`
      
          #echo "updating with name: $name"
          #echo "updating with log: $log"
          #echo "updating with time: $time"
          #echo "updating files: $changedfiles"
      
          cd $tbg_cli_path
          $php_cli_path ./tbg_cli vcs_integration:report_commit $projectid "$name" $newhash "$log" "$changedfiles" $oldhash $time
      }
      
      if [ -n "$1" -a -n "$2" ]; then
          # we seem to be in command line mode...
          update_tbg $1 $2
      else
          while read oldhash newhash refname
          do
              # we seem to be operating as a git post-receive hook
              update_tbg $oldhash $newhash $refname
          done
      fi
  2. Removed POSIX dependancy

    If you're using version 3.2.5 or higher then you don't need to do this step as my code changes were committed to the official The Bug Genie repository.

    When the git-hook is executed it calls the PHP file named tbg_cli (located in The Bug Genie's main directory). Unfortunately this file has a dependency on the POSIX extension, which isn't available for the Windows OS

    In order to stop this unfulfilled dependency from throwing errors I tracked down the POSIX dependent code to a static method named getCurrentCLIusername residing in "thebuggenie\core\classes\TBGContext.class.php" and changed the method to look like the following...

    // Modified to allow use on Windows platform
    public static function getCurrentCLIusername()
    {
        if(extension_loaded('posix'))
        {
            // Original code
            $processUser = posix_getpwuid(posix_geteuid());
                return $processUser['name'];
        }
        else
        {
            // Try to get CLI process owner without the POSIX extension
            $environmentUser = getenv('USERNAME');
            if($environmentUser === false)
            {
                $environmentUser = 'Unknown';
            }
            return $environmentUser;
        }
    }
  3. Finished

    Screenshot of VCS commits in The Bug Genie

    Once the aforementioned changes had been made I was able to push commits to my designated repository and have The Bug Genie display information about relevant commits.