From 2bd2002210c36d9d299c710e97f327aefc76ce39 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Mon, 28 Oct 2019 11:13:08 +0100 Subject: [PATCH 1/2] [ADD] show-status command --- README.rst | 20 ++++++++++++++++++++ git_aggregator/main.py | 9 ++++++--- git_aggregator/repo.py | 17 +++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index f899272..e312ec1 100644 --- a/README.rst +++ b/README.rst @@ -204,6 +204,26 @@ To work around API limitation, you must first generate a .. _Github API token: https://github.com/settings/tokens +Show local status +================= + +gitaggregate allows you to log all the local changes with the command +``show-status`` + +.. code-block:: bash + + $ gitaggregate show-status -c repos.yaml + +Result sample + +.. code-block:: bash + + (INFO) [11:04:04] git_aggregator.repo pos Repo /opt/grap_dev/grap-odoo-env-8.0/src/pos: 3 changes found. + 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..af55a18 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', 'show-status'] + def _log_level_string_to_int(log_level_string): if log_level_string not in _LOG_LEVEL_STRINGS: @@ -134,6 +136,7 @@ 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' + 'show-status: show status in each repositories.\n' ) return main_parser @@ -153,9 +156,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 +209,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 == 'show-status': + repo.show_status() except Exception: err_queue.put_nowait(sys.exc_info()) finally: diff --git a/git_aggregator/repo.py b/git_aggregator/repo.py index d199af6..2991325 100644 --- a/git_aggregator/repo.py +++ b/git_aggregator/repo.py @@ -380,3 +380,20 @@ def show_all_prs(self): logger.info( '{url} in state {state} ({merged})'.format(**pr_info) ) + + def show_status(self): + """Log status in each repository, if there are local changes""" + status = self.log_call( + ['git', 'status', '--short'], + callwith=subprocess.check_output, + cwd=self.cwd + ) + if status: + logger.info( + "{folder} : {qty} local change(s) found.\n" + "{status}".format( + folder=self.cwd, + qty=len(status.splitlines()), + status=status, + )) + return status From ffa99608456d769fe67df272c7ed330a0a088ed6 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 1 Nov 2019 12:01:47 +0100 Subject: [PATCH 2/2] fixup! [ADD] show-status command --- README.rst | 13 +++++++------ git_aggregator/main.py | 16 ++++++++++++---- git_aggregator/repo.py | 22 +++++++++------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/README.rst b/README.rst index e312ec1..9008912 100644 --- a/README.rst +++ b/README.rst @@ -204,21 +204,22 @@ To work around API limitation, you must first generate a .. _Github API token: https://github.com/settings/tokens -Show local status -================= +Custom Run-in command +===================== -gitaggregate allows you to log all the local changes with the command -``show-status`` +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 show-status -c repos.yaml + $ 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: 3 changes found. + (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/ diff --git a/git_aggregator/main.py b/git_aggregator/main.py index af55a18..d3cf567 100644 --- a/git_aggregator/main.py +++ b/git_aggregator/main.py @@ -27,7 +27,7 @@ _LOG_LEVEL_STRINGS = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'] -_COMMAND_LIST = ['aggregate', 'show-closed-prs', 'show-all-prs', 'show-status'] +_COMMAND_LIST = ['aggregate', 'show-closed-prs', 'show-all-prs', 'run-in'] def _log_level_string_to_int(log_level_string): @@ -136,7 +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' - 'show-status: show status in each repositories.\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 @@ -209,8 +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 == 'show-status': - repo.show_status() + 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 2991325..7efff71 100644 --- a/git_aggregator/repo.py +++ b/git_aggregator/repo.py @@ -381,19 +381,15 @@ def show_all_prs(self): '{url} in state {state} ({merged})'.format(**pr_info) ) - def show_status(self): - """Log status in each repository, if there are local changes""" - status = self.log_call( - ['git', 'status', '--short'], + 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 status: - logger.info( - "{folder} : {qty} local change(s) found.\n" - "{status}".format( - folder=self.cwd, - qty=len(status.splitlines()), - status=status, - )) - return status + if result: + logger.info("{folder} : \n{result}".format( + folder=self.cwd, result=result)) + return result