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 17, 2018
1 parent a805a81 commit 076c1c1
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 101 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.

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

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

def decode_repo_list(self, file_name):
raise NotImplementedError()


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

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

from org_status.formatters import RepoListFormatter


class GitManFormatter(RepoListFormatter):
NAME = 'gitman'

def encode_repo_list(self, urls):
for url in urls:
name = parse(url).repo
yield {'name': name,
'repo': url,
'rev': 'master'}

def decode_repo_list(self, file_name):
with open(file_name, 'r') as file:
yml_data = yaml.load(file)
for repo in yml_data['sources']:
yield [repo['name'], repo['repo']]
21 changes: 21 additions & 0 deletions org_status/formatters/gitshelf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import yaml
from giturlparse import parse

from org_status.formatters import RepoListFormatter


class GitShelfFormatter(RepoListFormatter):
NAME = 'gitshelf'

def encode_repo_list(self, urls):
for url in urls:
name = parse(url).repo
yield {'book': name,
'git': url,
'branch': 'master'}

def decode_repo_list(self, file_name):
with open(file_name, 'r') as file:
yml_data = yaml.load(file)
for repo in yml_data['books']:
yield [repo['book'], repo['git']]
24 changes: 15 additions & 9 deletions org_status/org_hosts/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,30 @@ class GitHubOrg(OrgHost):
HostName = 'github'
StatusProvider = [TravisBuildStatus, AppVeyorStatus]

def __init__(self, token, group, **kargs):
def __init__(self, token, group, sync=True, **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))

self._sync = sync
if sync:
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,8 +58,12 @@ 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):
return self._org.repositories
return [repo.web_url for repo in self._org.repositories]

@property
def sync(self):
return self._sync
19 changes: 10 additions & 9 deletions org_status/org_hosts/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@ 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, sync=True, **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 sync:
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):
return self._org.repositories
return [repo.web_url for repo in self._org.repositories]
Loading

0 comments on commit 076c1c1

Please sign in to comment.