Skip to content

Commit

Permalink
Add support to export list of org repo
Browse files Browse the repository at this point in the history
Add option to export list of org repos into different formats.

Closes ksdme#6
  • Loading branch information
kx-chen committed Nov 8, 2018
1 parent d832331 commit 3189392
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
14 changes: 14 additions & 0 deletions org_status/encoders/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class OrgListEncoder:
NAME = None

@classmethod
def convert_org_list_to_format(cls, repos):
raise NotImplementedError()


def get_all_supported_exporters():
from org_status.encoders.gitman import GitManEncoder

return (
GitManEncoder,
)
20 changes: 20 additions & 0 deletions org_status/encoders/gitman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import yaml
from furl import furl

from org_status.encoders import OrgListEncoder


class GitManEncoder(OrgListEncoder):
NAME = 'gitman'

@classmethod
def convert_org_list_to_format(cls, repos):
repo_data = []

for repo in repos:
name = furl(repo.repo_url).path.segments[1]
repo_data.append({'name': name,
'repo': repo.repo_url,
'rev': 'master'})

return yaml.dump(repo_data)
20 changes: 20 additions & 0 deletions org_status/org_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from org_status.status_providers import Status
from org_status.org_hosts import get_all_supported_hosts
from org_status.encoders import get_all_supported_exporters


def get_host_token(host_name):
Expand Down Expand Up @@ -75,10 +76,25 @@ def get_argument_parser():
parser.add_argument('--verbose', '-v', action='store_true')
parser.add_argument('--hosts-only', '-o', action='store_true')
parser.add_argument('--skip-host-checks', action='store_true')
parser.add_argument('--export-orgs', action='store_true')
parser.add_argument('--format', type=str)

return parser


def export(repo_data, exporter_name):
exporters = get_all_supported_exporters()

for exporter in exporters:
if exporter.NAME == exporter_name:
try:
exporter.convert_org_list_to_format(repo_data)
except NotImplementedError:
print('exporter does not support exporting results')
else:
print('exporter format not found')


def main():
parser = get_argument_parser()
args = parser.parse_args()
Expand Down Expand Up @@ -137,4 +153,8 @@ def main():

org_host = Host(token, org, verbose=args.verbose)
org_status = aggregate_org_status(org_host, threads=args.threads)

if args.export_orgs:
export(org_status, args.format)

present_status(org_status, args.no_color)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
git+https://gitlab.com/gitmate/open-source/IGitt.git#egg=IGitt
requests
termcolor
furl
pyyaml

0 comments on commit 3189392

Please sign in to comment.