Giter VIP home page Giter VIP logo

gitzilla's Introduction

GitZilla

NOTE : This project is no longer actively maintained.

GitZilla is Python magic to support Git-Bugzilla integration. There are various ways of using GitZilla.

Note that GitZilla must be installed on the machine receiving commits from everyone - home to the the "official" or the "central" repository.

There's a mailing list for GitZilla now, at [email protected]

Summary of features

GitZilla might be the right tool if you want to::

  • Automatically add commits to bugs referenced in the commit messages whenever changes are pushed to a central git repository.

  • Reject commits without a bug reference.

  • Only allow commits referring to active bugs (reject commits referring to CLOSED, RESOLVED or any other specific bug states).

  • (contributed, untested): Usable with Gerrit.

  • Some combination or all of the above.

With the above capabilities, GitZilla allows for::

  • Per-user, or system-wide authentication for Bugzilla.
  • Configurable bug comment formats and content.
  • Optional diffstat as part of the bug comments.
  • Configurable regexes for matching bug IDs in commit messages.

Usage

Simple ready scripts

To quickly start using GitZilla:

  • Install GitZilla. You may choose the .deb for easy installation on Debian/Ubuntu systems. Otherwise, just unpack the source and install in the usual setuptools way::

    sudo python3 ./setup.py install
    
  • Switch to the hooks directory (/path/to/central/repository/Example.git/hooks) and delete the post-receive and update hooks.

  • Link (or copy) the gitzilla provided hooks::

    ln -s $(which gitzilla-post-receive) post-receive
    ln -s $(which gitzilla-update) update
    
  • Read and edit the config file at /etc/gitzillarc. A simple (and sufficient for most cases) configuration is something like::

    [/path/to/repository/Example.git]
    bugzilla_url: https://repo.example.com/bugzilla/xmlrpc.cgi
    bugzilla_user: [email protected]
    bugzilla_password: blahblah
    allowed_bug_states: NEW, ASSIGNED, REOPENED
    

    (and even the last item is optional!)

  • Commit away!

Custom GitZilla

If you need the hooks to do other stuff apart from just the Bugzilla integration, you could write your hook as a Python script and leave the Bugzilla stuff to functions from gitzilla.hookscripts or gitzilla.hooks.

In fact with the defaults, are equivalent to the following:

post-receive::

#!/usr/bin/python
from gitzilla.hookscripts import post_receive
post_receive()

update::

#!/usr/bin/python
from gitzilla.hookscripts import update
update()

The functions from gitzilla.hookscripts parse and pick up values from the configuration files. If you want to taylor more use the functions from gitzilla.hooks.

post-receive::

#!/usr/bin/python
from gitzilla.hooks import post_receive
post_receive("https://repo.example.com/bugzilla", "username", "password")

update::

#!/usr/bin/python
from gitzilla.hooks import update
update("https://repo.example.com/bugzilla", "username", "password")

You could pass a custom bug id extraction regex and your own logging.Logger instance. The update hook function also accepts an array of allowed bug status strings.

Look at the module help for gitzilla.hooks for more information.

Configuration

GitZilla uses a global configuration file (at /etc/gitzillarc) as well as per-user configuration files (at ~/.gitzillarc). All the configuration options are picked up from the global config file, and the user specific config is allowed to override only the bugzilla_user and bugzilla_password parameters.

The configuration files themselves are in the ConfigParser format (see http://docs.python.org/library/configparser.html). A sample configuration looks like::

[DEFAULT]
user_config: deny
allowed_bug_states: NEW, ASSIGNED, REOPENED

[/path/to/repository/.git]
bugzilla_url: https://repo.example.com/bugzilla/xmlrpc.cgi
bugzilla_user: [email protected]
bugzilla_password: blahblah
logfile: /var/log/gitzilla.log
loglevel: info

Each git repository on the system MAY have its own section. The global config MUST specify the bugzilla_url parameter.

Default values (applied to each repository unless overridden) may be specified in a [DEFAULT] section.

The user specific files are entirely optional.

Mandatory parameters

  • bugzilla_url

Optional parameters

  • bugzilla_user

    the default username for Bugzilla.
    
  • bugzilla_password

    the default password for Bugzilla.
    
  • user_config

    allow/deny user specific bugzilla credentials. The legal values are
    ``allow``, ``deny`` and ``force``. Defaults to ``allow``.
    
  • require_bug_ref

    if True, the update hook will require that each commit message contains
    a bug number. If False, it will not. Defaults to True (same as historical
    behaviour).
    
  • allowed_bug_states

    a comma separated set of states that a bug must be in, in order for
    the commit to be allowed by the update hook.
    
  • formatspec

    appended to ``--pretty=format:`` and passed to ``git whatchanged``.
    See the ``git whatchanged`` manpage for more info. Newlines are
    automatically converted to '%n', which is what the git format spec
    requires.
    
  • include_diffstat

    include diffstat (a list of changed file with a histogram). If False, the diffstat is not included. Defaults to True to be consistent with previous behaviour.

  • separator

    a string which would never occur in commit messages. You should not
    need to set this, as it is already at a safe default.
    
  • bug_regex

    the (Python) regex for capturing bug numbers. MUST capture all the
    digits (and only the digits) of the bug id in a named group called
    ``bug``. This regex is compiled internally with the MULTILINE, DOTALL
    and IGNORECASE options set. The default regex captures from the
    following forms:
    
      * bug 123
      * Bug # 123
      * BUG123
      * bug# 123
      * Bug #123
    
  • git_ref_prefix

    the string which must start a git reference for its commits to be
    processed. Defaults to 'refs/heads/' so that we don't process 'tags/'
    and run the risk of processing many commits multiple times. You can
    set it to the empty string to process all git references.
    
  • logfile

    the file to log to. MUST be writable by the uid of the git process. In
    case of ssh pushes, tha usually means it should be writable by all.
    
  • loglevel

    can be ``info`` or ``debug``. Defaults to ``debug``.
    

Security note

Note that the global config would be readable by all and may contain a bugzilla credentials. If you think this is a problem, you may rely on per-user auth.

If the user_config option is set to allow or force, then auth credentials are picked up from the user specific ~/.gitzillarc file.

If the user_config option is force and the ~/.gitzillarc does not contain bugzilla credentials, then the ~/.bugz_cookie file is used for authentication. To generate a cookie file, a user may use the gitzilla-gencookie script. The cookie validity will of course be dependent on your Bugzilla configuration. If neither credentials nor the cookie file are present (and valid), Bugzilla interactions will fail and the commits will be rejected.

If the user_config option is allow, then user specific credentials are used if available. Only if credentials are unavailable in both the user-specific as well as the systemwide configs, the cookie file is used. This configuration is the default because of the closeness of behaviour from version 1.0.

To summarize:

  • To allow (but not force) users to use their own auth/credentials set user_config to allow and set bugzilla_user and bugzilla_password in the system wide config.

  • To enforce user credentials, set user_config to force and leave the Bugzilla credentials out of the system wide config.

  • To use system wide credentials only, set user_config to deny.

  • To enforce Bugzilla integration, use the update hook. The update hook will check the validity of the credentials (system or user, depending on the config), regardless of the allowed_bug_states option. This is a change in behaviour from version 1.0.

*cookies are no longer used since Bugzilla 4.4.3

Requirements

To install and run GitZilla, you need:

  • Python 3 (tested with 3.4.0)
  • pybugz >= 0.11.1

This combination has been tested with Bugzilla 4.4.6 & 4.2.11

If you wish to use python 2:

  • Python (tested with 2.6.4, should work with >=2.5)
  • Pybugz (tested with 0.8.0)
  • Gitzilla <= 2.0

This python 2 combination works with Bugzilla 3.0.11, and with pybugz 0.9.3 it may support up to Bugzilla 4.4.2

The excellent pybugz can be obtained from http://github.com/williamh/pybugz and http://github.com/williamh/pybugz/releases

Download

GitZilla is hosted at GitHub : http://github.com/gera/gitzilla

You can access the downloads at : http://github.com/gera/gitzilla/downloads

The download page contains a .deb which should work on Debian and Ubuntu systems.

Mailing list

The official GitZilla mailing list: [email protected]

gitzilla's People

Contributors

avtobiff avatar gera avatar gtait avatar kconnor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gitzilla's Issues

remote: UnboundLocalError: local variable 'cookie_file' referenced before assignment

I am trying to install gitzilla and I get this error. I managed to install it successfully on another machine - and the settings seem the same - but on a push I get an error

[adrian@localhost cpp11]$ git push
Counting objects: 15, done.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.49 KiB, done.
Total 10 (delta 6), reused 0 (delta 0)
remote: Traceback (most recent call last):
remote: File "hooks/update", line 9, in
remote: load_entry_point('gitzilla==2.0', 'console_scripts', 'gitzilla-update')()
remote: File "/usr/lib/python2.7/site-packages/gitzilla-2.0-py2.7.egg/gitzilla/hookscripts.py", line 213, in update
remote: bRequireBugNumber)
remote: File "/usr/lib/python2.7/site-packages/gitzilla-2.0-py2.7.egg/gitzilla/hooks.py", line 184, in update
remote: oBZ = bz_init(sBZUrl, sBZUser, sBZPasswd)
remote: File "/usr/lib/python2.7/site-packages/gitzilla-2.0-py2.7.egg/gitzilla/hookscripts.py", line 125, in bz_init
remote: oBZ = bugz.bugzilla.Bugz(sBZUrl, user=sBZUser, password=sBZPasswd)
remote: File "/usr/lib/python2.7/site-packages/bugz/bugzilla.py", line 181, in init
remote: self.warn('Unable to save session cookies in %s' % cookie_file)
remote: UnboundLocalError: local variable 'cookie_file' referenced before assignment
remote: error: hook declined to update refs/heads/master
To git://idbs-src/cpp11.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'git://idbs-src/cpp11.git'

gitzillarc
[/var/lib/git/cpp11.git]
bugzilla_url: http://idbs-src/bugzilla
bugzilla_user: *************
bugzilla_password: ********
formatspec: cpp11.git commit %H%d%n%aE%n%s%n%n%b
allowed_bug_states: NEW, ASSIGNED, REOPENED, CONFIRMED

No errors in git-daemon
Oct 20 13:23:11 localhost xinetd[20293]: START: git pid=20400 from=::ffff:192.168.124.50
Oct 20 13:23:11 localhost git-daemon[20400]: Extended attributes (15 bytes) exist <host=idbs-src>
Oct 20 13:23:11 localhost git-daemon[20400]: Request receive-pack for '/cpp11.git'
Oct 20 13:23:11 localhost xinetd[20293]: EXIT: git status=0 pid=20400 duration=0(sec)

My commit message
Bug #1 Minor changes for testing of

Added a new file that has nothing to do with C++11
Random changes to other files
Added file for reviewboard config

Any help appreciated -
TIA.

Adrian

triggers "Suspicious Action" in Bugzilla

The hook fails silently instead of adding a comment to the bug report. With ngrep, I can see that Bugzilla returns a "Suspicious Action" page after the POST, with a form that has to be submitted again for verification.

GitZilla HEAD, Bugzilla 3.6.2.0 on Debian.

Partial returned document:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                      "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>Suspicious Action</title>
    ................. long document with form ..............

    <input type="hidden" name="token" value="1301373485-475674a36a6cfe4de0e3af7aa3a5aa3a">
    <input type="submit" id="confirm" value="Yes, Confirm Changes">
</form>

<p><a href="index.cgi">No, throw away these changes</a> (you will be redirected to the home page).</p>
</div>

Missing import re - Using a custom re in the config file is failing

remote: Traceback (most recent call last):
remote: File "/usr/bin/gitzilla-update", line 9, in
remote: load_entry_point('gitzilla==2.0', 'console_scripts', 'gitzilla-update')()
remote: File "/usr/lib/python2.5/site-packages/gitzilla-2.0-py2.5.egg/gitzilla/hookscripts.py", line 174, in update
remote: oBugRegex = get_bug_regex(siteconfig)
remote: File "/usr/lib/python2.5/site-packages/gitzilla-2.0-py2.5.egg/gitzilla/hookscripts.py", line 86, in get_bug_regex
remote: oBugRegex = re.compile(siteconfig.get(sRepo, "bug_regex"),
remote: NameError: global name 're' is not defined
remote: error: hook declined to update refs/heads/master

Unable to push files - "fatal: unrecognized argument: --format"

I'm trying to install gitzilla, but am not really familiar with git administration - so apologies if I'm doing something stupid. When I attempt a "git push" I get the error message:

Counting objects: 23, done.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (21/21), 2.18 KiB, done.
Total 21 (delta 6), reused 0 (delta 0)
Failed to execute command: ['git', 'whatchanged', '--format=format:................%ncommit %H%nparents %P%nAuthor %aN (%aE)%nDate %aD%nCommit By %cN (%cE)%nCommit Date %cD%n%n%s%n%n%b%n', '51db39eaf3c2d7e978f89959c402532319bfa9e6..2c80cb8de2b8bef51e0218895c133f3173acfafd']
fatal: unrecognized argument: --format=format:................%ncommit %H%nparents %P%nAuthor %aN (%aE)%nDate %aD%nCommit By %cN (%cE)%nCommit Date %cD%n%n%s%n%n%b%n

error: hooks/update exited with error code 255

error: hook declined to update refs/heads/master

I've got debug logging on, but that just show old and new revision hashes.

I've re-visited the installation instructions, but don't see anything I've omitted. Any guidance as to how to track down the problem would be much appreciated.

Describe what gitzilla actually does

Hi there,
we (ScummVM) have been thinking about moving our issue tracking from Sourceforge to a new system; a potential contender is Bugzilla. Some folks would like our issue tracker to be integrated with our git(hub) repository, however. E.g. being able to auto-close tracker items based on the commit message and stuff.

Googling around for "bugzilla git" of course I came across this tool, gitzilla.

However, after having read the README and homepage, I am still rather in the dark about what kind of integration gitzilla provides; and I am pretty sure other people will have the same problem.

Thus, my request: Could you please insert a brief description into your README (or wherever else you deem appropriate) that sketches what kind of features / integration gitzilla actually provides? E.g. does it allow closing reports based on commit messages (I assume it does, but this doesn't seem to be stated explicitly anywhere) ? What format does the commit message need to have for this to work? What other features are there?

Config file does not include some default values, difficult to find them in source to make small changes

I think that the default regex for bug_regex should be mentioned in the config file so you dont have to hunt through the source code to find it if you want to tweak it slightly.

Similarly for formatspec, which i had to manually create, as the git whatchanged man page doesn't give you it.

bug_regex: bug\s*(?:#|)\s*(?P\d+)
formatspec: commit      %H%nparents     %P%nAuthor      %an (%ad)%nDate        %ad%nCommit By   %cn (%ce)%nCommit Date %cd%n%n%s%n%b

cannot change status of a bug

It would be nice if it were possible to actually close bugs through the gitzilla interface.
I.e. something like:
[bug 123: CLOSED] my commit message

pushing merged topic branches duplicates bugzilla comments

from Pierce Lopez:

"""
We use gitzilla here where I work, and we ran into this issue
where someone would be working on a topic branch, and whenever
they merged in the master branch and then pushed the update to
the topic branch to our central git server, all commits that
were on master with bug numbers would be re-posted by gitzilla,
because they were new to the topic branch. ...
"""

Does not update Bugzilla

For a few months, some bug id are not updated and some are...

Using:
gitzilla==2.0
Bugzilla==4.0.4

I don't have any error in my bugzilla.log

Bugzilla access.log looks like:

[29/Feb/2012:01:07:47 -0500] "GET /index.cgi?GoAheadAndLogIn=1 HTTP/1.1" 200 9940
[29/Feb/2012:01:07:48 -0500] "GET /index.cgi?GoAheadAndLogIn=1 HTTP/1.1" 200 9940
[29/Feb/2012:01:07:49 -0500] "GET /show_bug.cgi?id=33&ctype=xml HTTP/1.1" 200 359

This is a working call:

74.86.0.126 - - [26/Feb/2012:13:32:20 -0500] "GET /index.cgi?GoAheadAndLogIn=1 HTTP/1.1" 200 9940
74.86.0.126 - - [26/Feb/2012:13:32:22 -0500] "GET /index.cgi?GoAheadAndLogIn=1 HTTP/1.1" 200 9940
74.86.0.126 - - [26/Feb/2012:13:32:23 -0500] "GET /show_bug.cgi?id=18&ctype=xml HTTP/1.1" 200 17652
74.86.0.126 - - [26/Feb/2012:13:32:25 -0500] "POST /process_bug.cgi HTTP/1.1" 200 8046

Bug 33 depends on other bugs.. bug 18 does not (second call)

But, process_bug is not call on the failing first one.

typo on the main page

"Automatically add commits to bugs referenced in the commit messages whenever changes are pushed to a central git repository."

Probably you meant "Automatically add comments..."?

Include hyperlink to gitweb for commit

It would be nice if the message that gitzilla posted to Bugzilla included a hyperlink to gitweb (or cgit, etc) for viewing of the diff in more detail.

Error messages don't say they're from GitZilla

Reported by Don Lindsay [email protected]:

I deliberately caused an error, by writing a commit message that
GitZilla would not parse.

But when I did the 'git push', the resulting error messages didn't
mention parsing, much less GItZilla. I'm worried about users getting
clued much more slowly than necessary.

Commit details not appearing in bugzilla bug

When I do a git push the gitzilla hooks are successfully checking that I have entered a bug ID in the commit comments and that it's a valid ID (ie. bugzilla communication is OK). However, I'm not seeing any details being posted against this bug ID in bugzilla. Any ideas on how to troubleshoot this issue?

My /etc/gitzillarc contains:

[/var/www/dev-services/playground/.git]
bugzilla_url: http://bugzilla.dev.XXX.com/
bugzilla_user: [email protected]
bugzilla_password: XXX
allowed_bug_states: NEW, ASSIGNED, REOPENED
logfile: /tmp/gitzilla.log
loglevel: debug

Having set the loglevel to debug I am seeing the following on a successful push:

Found bugid 2
oldrev: '6323829cd680dcdf8b9bba3e6626aebc3d2b811c', newrev: 'be4dc5392f55b43d2fb83bf81cd809d94d0b3b97'
Checking for bug refs in commit:

commit be4dc5392f55b43d2fb83bf81cd809d94d0b3b97
parents 6323829cd680dcdf8b9bba3e6626aebc3d2b811c
Author XXX XXX (XXX@XXX)
Date Wed, 20 Oct 2010 08:33:20 +0100
Commit By XXX XXX (XXX@XXX)
Commit Date Wed, 20 Oct 2010 08:33:20 +0100

bug 2 Wednesday

:100644 100644 9228a12... 0812859... M README

Found bug id 2
status for bug 2 is NEW
oldrev: '6323829cd680dcdf8b9bba3e6626aebc3d2b811c', newrev: 'be4dc5392f55b43d2fb83bf81cd809d94d0b3b97'
Considering commit:

commit be4dc5392f55b43d2fb83bf81cd809d94d0b3b97
parents 6323829cd680dcdf8b9bba3e6626aebc3d2b811c
Author XXX XXX (XXX.XXX@XXX)
Date Wed, 20 Oct 2010 08:33:20 +0100
Commit By XXX XXX (XXX.XXX@XXX)
Commit Date Wed, 20 Oct 2010 08:33:20 +0100

bug 2 Wednesday

:100644 100644 9228a12... 0812859... M README

Found bugid 2

hooks fail on new repositories

If the target repository has zero commits, the hooks fail.

This is due to an error in the way "git whatchanged" is invoked.

git push --tags creates duplicate Bugzilla comments

The hooks run every time a ref is updated (usually due to a push to the repository).

Unfortunately this means that if I do:

git push # Push my changes
git tag new-tag-name
git push --tags # Push my tags

I end up with the same commit messages appearing twice against each Bugzilla issue.

Not sure how to work round this issue. Possible approaches might be:

  • Limit gitzilla to only paying attention to certain refs (like /refs/heads/master)
  • Do a search on the comments to check that Bugzilla doesn't already contain a reference to each commit in the 'update' and 'post-receive' hooks before performing other checks/operations. However, I imagine this could really slow things down, especially with tags where the 'whatchanged' log would get larger and larger with each tag.

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.