Skip to content

Commit

Permalink
Add status-provider Flag
Browse files Browse the repository at this point in the history
This commit adds a status-provider flag to mix and match between hosts
and status providers

closes #17
  • Loading branch information
suggoitanoshi committed Nov 25, 2018
1 parent 45df0fd commit 7305d9d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
3 changes: 2 additions & 1 deletion org_status/org_hosts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class OrgHost:
HostName = None
StatusProvider = None

def __init__(self, verbose=False, **kargs):
def __init__(self, verbose=False, status_provider=None, **kargs):
self.StatusProvider = status_provider or self.StatusProvider
if self.StatusProvider is None:
raise NotImplementedError()

Expand Down
26 changes: 14 additions & 12 deletions org_status/org_hosts/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,21 @@ def process_repository(self, repo, branch='master'):
.get_status(repo_name,
self.HostName,
branch=branch))

# if one result is passing, return that one
if Status.PASSING in repo_status:
repo_status = Status.PASSING
# if statuses are identical, just return one of them
elif repo_status[0] == repo_status[1]:
if len(repo_status) > 1:
# if one result is passing, return that one
if Status.PASSING in repo_status:
repo_status = Status.PASSING
# if statuses are identical, just return one of them
elif repo_status[0] == repo_status[1]:
repo_status = repo_status[0]
# return the failing result out of the 2 results
elif Status.FAILING in repo_status:
repo_status = Status.FAILING
# return the error result out of the 2 results
elif Status.ERROR in repo_status:
repo_status = Status.ERROR
else:
repo_status = repo_status[0]
# return the failing result out of the 2 results
elif Status.FAILING in repo_status:
repo_status = Status.FAILING
# return the error result out of the 2 results
elif Status.ERROR in repo_status:
repo_status = Status.ERROR

return RepoStatus(repo.web_url, repo_status)

Expand Down
32 changes: 26 additions & 6 deletions org_status/org_hosts/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

from org_status.org_hosts import OrgHost, RepoStatus
from org_status.status_providers.gitlab_ci import GitLabCIStatus
from org_status.status_providers import Status


class GitLabOrg(OrgHost):
HostName = 'gitlab'
StatusProvider = GitLabCIStatus
StatusProvider = [GitLabCIStatus]

HOST_STATUS_URL = ('https://api.status.io/1.0/status'
'/5b36dc6502d06804c08349f7')
Expand All @@ -22,7 +23,9 @@ def __init__(self, token, group, **kargs):
self._token = GitLabPrivateToken(token)
self._org = GitLabOrganization(self._token, self._group)

self._status_provider = self.StatusProvider(self._group)
self._status_provider = []
for i in enumerate(self.StatusProvider):
self._status_provider.append(self.StatusProvider[i[0]](self._group))

@classmethod
def get_host_status(cls):
Expand All @@ -35,10 +38,27 @@ def process_repository(self, repo, branch='master'):

# reliable enough?
repo_name = '/'.join(repo.web_url.split('/')[4:])
repo_status = self._status_provider.get_status(repo_name,
self.HostName,
branch=branch)

repo_status = []
for i in enumerate(self._status_provider):
repo_status.append(self._status_provider[i[0]]
.get_status(repo_name,
self.HostName,
branch=branch))
if len(repo_status) > 1:
# if one result is passing, return that one
if Status.PASSING in repo_status:
repo_status = Status.PASSING
# if statuses are identical, just return one of them
elif repo_status[0] == repo_status[1]:
repo_status = repo_status[0]
# return the failing result out of the 2 results
elif Status.FAILING in repo_status:
repo_status = Status.FAILING
# return the error result out of the 2 results
elif Status.ERROR in repo_status:
repo_status = Status.ERROR
else:
repo_status = repo_status[0]
return RepoStatus(repo.web_url, repo_status)

@property
Expand Down
22 changes: 20 additions & 2 deletions org_status/org_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def generate_fetch_jobs(org_strings):
for supported_host in get_all_supported_hosts():
if host == supported_host.HostName:
yield (supported_host, org)
raise StopIteration
# raise StopIteration
else:
for available_host in get_all_supported_hosts():
yield (available_host, org)
Expand Down Expand Up @@ -87,6 +87,7 @@ def get_argument_parser():
parser.add_argument('--export-repos', type=str)
parser.add_argument('--format', type=str, default='gitman')
parser.add_argument('--check-providers-only', action='store_true')
parser.add_argument('--status-provider', type=str)

return parser

Expand Down Expand Up @@ -146,6 +147,22 @@ def main():
print(styled('no organizations to check', 'red'))
return

status_provider = []

if args.status_provider:
status_providers = args.status_provider.split(',')
for provider in status_providers:
found = False
for supported_provider in get_supported_status_providers():
if provider == supported_provider.NAME:
status_provider.append(supported_provider)
found = True
break
if found:
continue
else:
print(styled(f'no provider named {provider}', 'red'))

all_repositories = []

for Host, org in generate_fetch_jobs(args.orgs):
Expand Down Expand Up @@ -189,7 +206,8 @@ def main():

raise exp

org_host = Host(token, org, verbose=args.verbose)
org_host = Host(token, org, status_provider=status_provider,
verbose=args.verbose)

if args.export_repos:
all_repositories += org_host.repositories
Expand Down

0 comments on commit 7305d9d

Please sign in to comment.