Skip to content
This repository was archived by the owner on Mar 16, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ Optional parameters

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

- http_user

Basic Auth username if required

- http_password

Basic Auth password if required

Security note
-------------
Expand Down
8 changes: 4 additions & 4 deletions hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import traceback


def post_receive(sBZUrl, sBZUser=None, sBZPasswd=None, sFormatSpec=None, oBugRegex=None, sSeparator=None, logger=None, bz_init=None, sRefPrefix=None, bIncludeDiffStat=True, aasPushes=None):
def post_receive(sBZUrl, sBZUser=None, sBZPasswd=None, sBZHTTPUser=None, sBZHTTPPasswd=None, sFormatSpec=None, oBugRegex=None, sSeparator=None, logger=None, bz_init=None, sRefPrefix=None, bIncludeDiffStat=True, aasPushes=None):
"""
a post-recieve hook handler which extracts bug ids and adds the commit
info to the comment. If multiple bug ids are found, the comment is added
Expand Down Expand Up @@ -77,7 +77,7 @@ def post_receive(sBZUrl, sBZUser=None, sBZPasswd=None, sFormatSpec=None, oBugReg
if sRefPrefix is None:
sRefPrefix = sDefaultRefPrefix

oBZ = bz_init(sBZUrl, sBZUser, sBZPasswd)
oBZ = bz_init(sBZUrl, sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd)

def gPushes():
for sLine in iter(sys.stdin.readline, ""):
Expand Down Expand Up @@ -114,7 +114,7 @@ def gPushes():



def update(oBugRegex=None, asAllowedStatuses=None, sSeparator=None, sBZUrl=None, sBZUser=None, sBZPasswd=None, logger=None, bz_init=None, sRefPrefix=None, bRequireBugNumber=True):
def update(oBugRegex=None, asAllowedStatuses=None, sSeparator=None, sBZUrl=None, sBZUser=None, sBZPasswd=None, sBZHTTPUser=None, sBZHTTPPasswd=None, logger=None, bz_init=None, sRefPrefix=None, bRequireBugNumber=True):
"""
an update hook handler which rejects commits without a bug reference.
This looks at the sys.argv array, so make sure you don't modify it before
Expand Down Expand Up @@ -181,7 +181,7 @@ def update(oBugRegex=None, asAllowedStatuses=None, sSeparator=None, sBZUrl=None,
raise ValueError("Bugzilla info required for status checks")

# create and cache bugzilla instance
oBZ = bz_init(sBZUrl, sBZUser, sBZPasswd)
oBZ = bz_init(sBZUrl, sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd)
# check auth
try:
oBZ.auth()
Expand Down
28 changes: 17 additions & 11 deletions hookscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ def has_option_or_default(conf, section, option):
def bz_auth_from_config(config, sRepo):
sBZUser = None
sBZPasswd = None
sBZHTTPUser = None
sBZHTTPPasswd = None

if has_option_or_default(config, sRepo, "bugzilla_user") and has_option_or_default(config, sRepo, "bugzilla_password"):
sBZUser = get_or_default(config, sRepo, "bugzilla_user")
sBZPasswd = get_or_default(config, sRepo, "bugzilla_password")

return (sBZUser, sBZPasswd)
if has_option_or_default(config, sRepo, "http_user") and has_option_or_default(config, sRepo, "http_password"):
sBZHTTPUser = get_or_default(config, sRepo, "http_user")
sBZHTTPPasswd = get_or_default(config, sRepo, "http_password")

return (sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd)



Expand All @@ -59,7 +65,7 @@ def get_bz_data(siteconfig, userconfig):
sUserOption = get_or_default(siteconfig, sRepo, "user_config", "allow")
sUserOption = {"deny": "deny", "force": "force"}.get(sUserOption, "allow")

(sBZUser, sBZPasswd) = bz_auth_from_config(userconfig, sRepo)
(sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd) = bz_auth_from_config(userconfig, sRepo)

# ignore auth from site-config if "force"
if sUserOption == "force":
Expand All @@ -71,11 +77,11 @@ def get_bz_data(siteconfig, userconfig):

# ignore auth from user config is "deny"
if sUserOption == "deny":
(sBZUser, sBZPasswd) = bz_auth_from_config(siteconfig, sRepo)
(sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd) = bz_auth_from_config(siteconfig, sRepo)
if None in (sBZUser, sBZPasswd):
raise ValueError("No default Bugzilla auth found. Cannot use user-auth because user_config is set to 'deny'")

return (sBZUrl, sBZUser, sBZPasswd, bAllowDefaultAuth)
return (sBZUrl, sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd, bAllowDefaultAuth)



Expand Down Expand Up @@ -105,7 +111,7 @@ def get_bug_regex(siteconfig):
def make_bz_init(siteconfig, bAllowDefaultAuth):
# return a bz_init function which does the right thing.

def bz_init(sBZUrl, sBZUser, sBZPasswd):
def bz_init(sBZUrl, sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd):
# if username/passwd are none, then modify the Bugz instance so that
# Bugz.get_input and getpass.getpass get the username and passwd
# from the siteconfig.
Expand All @@ -120,9 +126,9 @@ def bz_init(sBZUrl, sBZUser, sBZPasswd):
if None in (sBZUser, sBZPasswd):
if bAllowDefaultAuth:
# get data from siteconfig
(sSiteUser, sSitePasswd) = bz_auth_from_config(siteconfig, sRepo)
(sSiteUser, sSitePasswd, sBZHTTPUser, sBZHTTPPasswd) = bz_auth_from_config(siteconfig, sRepo)

oBZ = bugz.bugzilla.Bugz(sBZUrl, user=sBZUser, password=sBZPasswd)
oBZ = bugz.bugzilla.Bugz(sBZUrl, user=sBZUser, password=sBZPasswd, httpuser=sBZHTTPUser, httppassword=sBZHTTPPasswd)

def auth_error(*args):
raise ValueError("no Bugzilla auth found!")
Expand Down Expand Up @@ -160,7 +166,7 @@ def post_receive(aasPushes=None):
userconfig = ConfigParser.RawConfigParser()
userconfig.read(os.path.expanduser("~/.gitzillarc"))

(sBZUrl, sBZUser, sBZPasswd, bAllowDefaultAuth) = get_bz_data(siteconfig, userconfig)
(sBZUrl, sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd, bAllowDefaultAuth) = get_bz_data(siteconfig, userconfig)

logger = get_logger(siteconfig)
oBugRegex = get_bug_regex(siteconfig)
Expand All @@ -171,7 +177,7 @@ def post_receive(aasPushes=None):

bz_init = make_bz_init(siteconfig, bAllowDefaultAuth)

gitzilla.hooks.post_receive(sBZUrl, sBZUser, sBZPasswd, sFormatSpec,
gitzilla.hooks.post_receive(sBZUrl, sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd, sFormatSpec,
oBugRegex, sSeparator, logger, bz_init,
sRefPrefix, bIncludeDiffStat, aasPushes)

Expand Down Expand Up @@ -204,12 +210,12 @@ def update():
# and the bugzilla info.
userconfig = ConfigParser.RawConfigParser()
userconfig.read(os.path.expanduser("~/.gitzillarc"))
(sBZUrl, sBZUser, sBZPasswd, bAllowDefaultAuth) = get_bz_data(siteconfig, userconfig)
(sBZUrl, sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd, bAllowDefaultAuth) = get_bz_data(siteconfig, userconfig)

bz_init = make_bz_init(siteconfig, bAllowDefaultAuth)

gitzilla.hooks.update(oBugRegex, asAllowedStatuses, sSeparator, sBZUrl,
sBZUser, sBZPasswd, logger, bz_init, sRefPrefix,
sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd, logger, bz_init, sRefPrefix,
bRequireBugNumber)


8 changes: 4 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def execute(asCommand, bSplitLines=False, bIgnoreErrors=False):
return data


def init_bugzilla(sBZUrl, sBZUser, sBZPasswd):
def init_bugzilla(sBZUrl, sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd):
"""
initializes and returns a bugz.bugzilla.Bugz instance.

Expand All @@ -46,7 +46,7 @@ def init_bugzilla(sBZUrl, sBZUser, sBZPasswd):
if sBZUrl is None:
raise ValueError("No Bugzilla URL specified")

oBZ = bugz.bugzilla.Bugz(sBZUrl, user=sBZUser, password=sBZPasswd)
oBZ = bugz.bugzilla.Bugz(sBZUrl, user=sBZUser, password=sBZPasswd, httpuser=sBZHTTPUser, httppassword=sBZHTTPPasswd)
return oBZ


Expand Down Expand Up @@ -99,14 +99,14 @@ def get_changes(sOldRev, sNewRev, sFormatSpec, sSeparator, bIncludeDiffStat, sRe



def post_to_bugzilla(iBugId, sComment, sBZUrl, sBZUser, sBZPasswd):
def post_to_bugzilla(iBugId, sComment, sBZUrl, sBZUser, sBZPasswd, sBZHTTPUser, sBZHTTPPasswd ):
"""
posts the comment to the given bug id.
"""
if sBZUrl is None:
raise ValueError("No Bugzilla URL specified")

oBZ = bugz.bugzilla.Bugz(sBZUrl, user=sBZUser, password=sBZPasswd)
oBZ = bugz.bugzilla.Bugz(sBZUrl, user=sBZUser, password=sBZPasswd, httpuser=sBZHTTPUser, httppassword=sBZHTTPPasswd)
oBZ.modify(iBugId, comment=sComment)


Expand Down