Skip to content

Commit

Permalink
Initial work on adding a pre_import hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kostajh committed Mar 10, 2014
1 parent 833f7c5 commit 4a1304a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bugwarrior/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
#annotation_length = 45
#description_length = 35

# Use hooks to run commands prior to importing from bugwarrior-pull.
# bugwarrior-pull will run the commands in the order that they are specified
# below.
#
# pre_import: The pre_import hook is invoked after all issues have been pulled
# from remote sources, but before they are synced to the TW db. If your
# pre_import script has a non-zero exit code, the `bugwarrior-pull` command will
# exit early.
[hooks]
pre_import = /home/someuser/backup.sh, /home/someuser/sometask.sh

# This section is for configuring notifications when bugwarrior-pull runs,
# and when issues are created, updated, or deleted by bugwarrior-pull.
# Three backend are currently suported:
Expand Down
13 changes: 13 additions & 0 deletions bugwarrior/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import warnings
import subprocess

import bitlyapi
import dogpile.cache
Expand Down Expand Up @@ -328,6 +329,18 @@ def _bool_option(section, option, default):
'changed': [],
'closed': get_managed_task_uuids(tw, key_list, legacy_matching),
}

# Before running CRUD operations, call the pre_import hook(s).
if conf.has_option('hooks', 'pre_import'):
pre_import = [t.strip() for t in conf.get('hooks', 'pre_import').split(',')]
if pre_import is not None:
for hook in pre_import:
exit_code = subprocess.call(hook, shell=True)
if exit_code is not 0:
log.name('hooks:pre_import').error(
'Non-zero exit code %d on hook %s' % (exit_code, hook))
sys.exit(1)

for issue in issue_generator:
if isinstance(issue, tuple) and issue[0] == ABORT_PROCESSING:
raise RuntimeError(issue[1])
Expand Down

0 comments on commit 4a1304a

Please sign in to comment.