Skip to content

Commit

Permalink
Add gitshelf as a format and fetch certain repos
Browse files Browse the repository at this point in the history
This adds support for gitshelf as a format for a list
of repositories. This also adds support for fetching
only repos that are listed in a list of repositories,
as specified by --import-repos and --format.

Closes ksdme#29
  • Loading branch information
CLiu13 committed Nov 15, 2018
1 parent a805a81 commit dcc0a50
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 91 deletions.
13 changes: 0 additions & 13 deletions org_status/encoders/__init__.py

This file was deleted.

19 changes: 0 additions & 19 deletions org_status/encoders/gitman.py

This file was deleted.

15 changes: 15 additions & 0 deletions org_status/formatters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class RepoListFormatter:
NAME = None

def convert_repo_list_to_format(self, repos):
raise NotImplementedError()


def get_all_supported_formatters():
from org_status.formatters.gitman import GitManFormatter
from org_status.formatters.gitshelf import GitShelfFormatter

return (
GitManFormatter,
GitShelfFormatter,
)
32 changes: 32 additions & 0 deletions org_status/formatters/gitman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import yaml
from giturlparse import parse

from org_status.formatters import RepoListFormatter


class GitManFormatter(RepoListFormatter):
NAME = 'gitman'

def convert_repo_list_to_format(self, repos):
yml_data = {'sources': []}

for repo in repos:
name = parse(repo.web_url).repo
yml_data['sources'].append({'name': name,
'repo': repo.web_url,
'rev': 'master'})

return yaml.dump(yml_data, default_flow_style=False)

def convert_format_to_repo_list(self, file_name):
repos = []

try:
with open(file_name, 'r') as file:
yml_data = yaml.load(file)

for repo in yml_data['sources']:
repos.append([repo['name'], repo['repo']])
return repos
except FileNotFoundError:
print(f'unable to find file {file_name}')
32 changes: 32 additions & 0 deletions org_status/formatters/gitshelf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import yaml
from giturlparse import parse

from org_status.formatters import RepoListFormatter


class GitShelfFormatter(RepoListFormatter):
NAME = 'gitshelf'

def convert_repo_list_to_format(self, repos):
yml_data = {'books': []}

for repo in repos:
name = parse(repo.web_url).repo
yml_data['books'].append({'book': name,
'git': repo.web_url,
'branch': 'master'})

return yaml.dump(yml_data, default_flow_style=False)

def convert_format_to_repo_list(self, file_name):
repos = []

try:
with open(file_name, 'r') as file:
yml_data = yaml.load(file)

for repo in yml_data['books']:
repos.append([repo['book'], repo['git']])
return repos
except FileNotFoundError:
print(f'unable to find file {file_name}')
17 changes: 9 additions & 8 deletions org_status/org_hosts/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@ class GitHubOrg(OrgHost):
HostName = 'github'
StatusProvider = [TravisBuildStatus, AppVeyorStatus]

def __init__(self, token, group, **kargs):
def __init__(self, token, group, fetch, **kargs):
super().__init__(**kargs)

self._group = group
self._token = GitHubToken(token)
self._org = GitHubOrganization(self._token, self._group)

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

if fetch:
self._token = GitHubToken(token)
self._org = GitHubOrganization(self._token, self._group)

@classmethod
def get_host_status(cls):
status = requests.get('https://status.github.com/api/status.json')
status = json.loads(status.text)
return status['status'] == 'good'

def process_repository(self, repo, branch='master'):
self.print_status(repo.web_url)
def process_repository(self, web_url, branch='master'):
self.print_status(web_url)

# reliable enough?
repo_name = repo.web_url.split('/')[-1]
repo_name = web_url.split('/')[-1]
repo_status = []
for i in enumerate(self._status_provider):
repo_status.append(self._status_provider[i[0]]
Expand All @@ -56,7 +57,7 @@ def process_repository(self, repo, branch='master'):
elif Status.ERROR in repo_status:
repo_status = Status.ERROR

return RepoStatus(repo.web_url, repo_status)
return RepoStatus(web_url, repo_status)

@property
def repositories(self):
Expand Down
17 changes: 9 additions & 8 deletions org_status/org_hosts/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@ class GitLabOrg(OrgHost):
HOST_STATUS_URL = ('https://api.status.io/1.0/status'
'/5b36dc6502d06804c08349f7')

def __init__(self, token, group, **kargs):
def __init__(self, token, group, fetch, **kargs):
super().__init__(**kargs)

self._group = group
self._token = GitLabPrivateToken(token)
self._org = GitLabOrganization(self._token, self._group)

self._status_provider = self.StatusProvider(self._group)

if fetch:
self._token = GitLabPrivateToken(token)
self._org = GitLabOrganization(self._token, self._group)

@classmethod
def get_host_status(cls):
status = requests.get(cls.HOST_STATUS_URL)
status = json.loads(status.text)
return status['result']['status_overall']['status'] == 'Operational'

def process_repository(self, repo, branch='master'):
self.print_status(repo.web_url)
def process_repository(self, web_url, branch='master'):
self.print_status(web_url)

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

return RepoStatus(repo.web_url, repo_status)
return RepoStatus(web_url, repo_status)

@property
def repositories(self):
Expand Down
Loading

0 comments on commit dcc0a50

Please sign in to comment.