Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] run-in command #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
21 changes: 21 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======

Expand Down
17 changes: 14 additions & 3 deletions git_aggregator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions git_aggregator/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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