diff --git a/README.rst b/README.rst index f899272..9008912 100644 --- a/README.rst +++ b/README.rst @@ -204,6 +204,27 @@ To work around API limitation, you must first generate a .. _Github API token: https://github.com/settings/tokens +Custom Run-in command +===================== + +gitaggregate allows you to execute any custom command on all the repositories + +For exemple, if you want to know all the local diffs run: + +.. code-block:: bash + + $ gitaggregate run-in --run-in-command 'git status --short' + +Result sample + +.. code-block:: bash + + (INFO) [11:04:04] git_aggregator.repo pos Repo /opt/grap_dev/grap-odoo-env-8.0/src/pos : + R pos_margin/__openerp__.py -> pos_margin/__manifest__.py + R pos_order_load/__openerp__.py -> pos_order_load/__manifest__.py + ?? test/ + + Changes ======= diff --git a/git_aggregator/main.py b/git_aggregator/main.py index 6bf7d41..d3cf567 100644 --- a/git_aggregator/main.py +++ b/git_aggregator/main.py @@ -27,6 +27,8 @@ _LOG_LEVEL_STRINGS = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'] +_COMMAND_LIST = ['aggregate', 'show-closed-prs', 'show-all-prs', 'run-in'] + def _log_level_string_to_int(log_level_string): if log_level_string not in _LOG_LEVEL_STRINGS: @@ -134,6 +136,15 @@ def get_parser(): ' a github.com remote and a\n' ' refs/pull/NNN/head ref in the merge section.\n' 'show-closed-prs: show pull requests that are not open anymore.\n' + 'run-in: run a custom shell command, defined in the.\n' + ' --run-in-command argument.' + ) + + main_parser.add_argument( + '-ric', '--run-in-command', + dest='run_in_command', + type=str, + help='Command to run for each repository' ) return main_parser @@ -153,9 +164,7 @@ def main(): ) try: - if args.config and \ - args.command in \ - ('aggregate', 'show-closed-prs', 'show-all-prs'): + if args.config and args.command in _COMMAND_LIST: run(args) else: parser.print_help() @@ -208,6 +217,8 @@ def aggregate_repo(repo, args, sem, err_queue): repo.show_closed_prs() elif args.command == 'show-all-prs': repo.show_all_prs() + elif args.command == 'run-in': + repo.run_in(args.run_in_command) except Exception: err_queue.put_nowait(sys.exc_info()) finally: diff --git a/git_aggregator/repo.py b/git_aggregator/repo.py index d199af6..7efff71 100644 --- a/git_aggregator/repo.py +++ b/git_aggregator/repo.py @@ -380,3 +380,16 @@ def show_all_prs(self): logger.info( '{url} in state {state} ({merged})'.format(**pr_info) ) + + def run_in(self, run_in_command): + """Run a custom shell command into the current repository + and log result, if any.""" + result = self.log_call( + run_in_command.split(" "), + callwith=subprocess.check_output, + cwd=self.cwd + ) + if result: + logger.info("{folder} : \n{result}".format( + folder=self.cwd, result=result)) + return result