Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit aacf058

Browse files
authored
Merge pull request #22 from lendingblock/master
0.2.0
2 parents 76667f9 + fcf3dcf commit aacf058

File tree

6 files changed

+90
-64
lines changed

6 files changed

+90
-64
lines changed

agiletoolkit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Agile toolkit for devops and repository management"""
22

3-
__version__ = "0.1.8"
3+
__version__ = "0.2.0"

agiletoolkit/api/components.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,7 @@ class Pulls(Issues):
153153

154154
class Milestones(Issues):
155155
pass
156+
157+
158+
class Hooks(RepoComponents):
159+
pass

agiletoolkit/api/repo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .components import Commits, Pulls, Issues, Component, Milestones
1+
from .components import Commits, Pulls, Issues, Component, Milestones, Hooks
22
from .releases import Releases
33

44

@@ -13,6 +13,7 @@ def __init__(self, client, repo_path):
1313
self.issues = Issues(self)
1414
self.pulls = Pulls(self)
1515
self.milestones = Milestones(self)
16+
self.hooks = Hooks(self)
1617
self.headers = dict(
1718
accept='application/vnd.github.symmetra-preview+json'
1819
)

agiletoolkit/manager.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import os
2+
import asyncio
3+
from typing import Dict
4+
5+
import yaml
6+
7+
from jinja2 import Template
8+
9+
from . import utils
10+
11+
12+
NAMESPACES = {
13+
'local', 'development', 'dev', 'stage', 'prod', 'sandbox', 'production'
14+
}
15+
16+
17+
class Manager:
18+
19+
def __init__(self, config=None, path=None, yes=False, namespace=None):
20+
self.config = config or {}
21+
self.path = path or os.getcwd()
22+
self.deploy_path = os.path.join(self.path, 'deploy')
23+
self.yes = yes
24+
self.message_brokers = []
25+
self.namespace = namespace
26+
self.init()
27+
28+
def init(self):
29+
pass
30+
31+
def get(self, name: str, DataClass: type) -> object:
32+
cfg = self.config.get(name) or {}
33+
return DataClass(**cfg)
34+
35+
def load_data(self, *paths: str) -> Dict:
36+
filename = self.filename(*paths)
37+
if not os.path.isfile(filename):
38+
raise utils.CommandError('%s file missing' % filename)
39+
with open(filename, 'r') as fp:
40+
data = yaml.load(fp) or {}
41+
data_namespace = data.pop(self.namespace, None)
42+
for namespace in NAMESPACES:
43+
data.pop(namespace, None)
44+
if data_namespace:
45+
data.update(data_namespace)
46+
data['namespace'] = self.namespace
47+
return data
48+
49+
def manifest(self, values, *paths, filename=None):
50+
"""Load a manifest file and apply template values
51+
"""
52+
filename = filename or self.filename(*paths)
53+
with open(filename, 'r') as fp:
54+
template = Template(fp.read())
55+
return yaml.load(template.render(values))
56+
57+
def filename(self, *paths):
58+
if not os.path.isdir(self.deploy_path):
59+
raise utils.CommandError(
60+
"Path '%s' not available" % self.deploy_path
61+
)
62+
return os.path.join(self.deploy_path, *paths)
63+
64+
def copy_env(self, *args, **kw):
65+
env = os.environ.copy()
66+
env.update(*args, **kw)
67+
return env
68+
69+
def wait(self, coro):
70+
return asyncio.get_event_loop().run_until_complete(coro)

agiletoolkit/repo.py

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,25 @@
11
import os
22
import re
3-
import asyncio
4-
from typing import Dict
53
from dataclasses import dataclass
64
from urllib.parse import urlparse
75

8-
import yaml
9-
10-
from jinja2 import Template
11-
6+
from .manager import Manager
127
from .api import GithubApi, GithubException
138
from .slack import SlackIntegration
149
from . import utils
1510

1611

17-
NAMESPACES = {'local', 'dev', 'stage', 'sandbox', 'production'}
18-
19-
2012
@dataclass
2113
class Branches:
2214
dev: str = 'master'
2315
stage: str = 'deploy'
2416

2517

26-
class RepoManager:
18+
class RepoManager(Manager):
2719

28-
def __init__(self, config=None, path=None, yes=False, namespace=None):
29-
self.config = config or {}
30-
self.path = path or os.getcwd()
31-
self.deploy_path = os.path.join(self.path, 'deploy')
32-
self.yes = yes
33-
self.message_brokers = []
34-
self.namespace = namespace
20+
def init(self):
3521
self.info = utils.gitrepo(self.path)
3622
SlackIntegration.add(self)
37-
self.init()
38-
39-
def init(self):
40-
pass
4123

4224
def software_version(self):
4325
"""Software version
@@ -139,44 +121,3 @@ def github_repo(self) -> str:
139121
bits = path.split('.')
140122
bits.pop()
141123
return self.github().repo('.'.join(bits))
142-
143-
def get(self, name: str, DataClass: type) -> object:
144-
cfg = self.config.get(name) or {}
145-
return DataClass(**cfg)
146-
147-
def load_data(self, *paths: str) -> Dict:
148-
filename = self.filename(*paths)
149-
if not os.path.isfile(filename):
150-
raise utils.CommandError('%s file missing' % filename)
151-
with open(filename, 'r') as fp:
152-
data = yaml.load(fp) or {}
153-
data_namespace = data.pop(self.namespace, None)
154-
for namespace in NAMESPACES:
155-
data.pop(namespace, None)
156-
if data_namespace:
157-
data.update(data_namespace)
158-
data['namespace'] = self.namespace
159-
return data
160-
161-
def manifest(self, values, *paths, filename=None):
162-
"""Load a manifest file and apply template values
163-
"""
164-
filename = filename or self.filename(*paths)
165-
with open(filename, 'r') as fp:
166-
template = Template(fp.read())
167-
return yaml.load(template.render(values))
168-
169-
def filename(self, *paths):
170-
if not os.path.isdir(self.deploy_path):
171-
raise utils.CommandError(
172-
"Path '%s' not available" % self.deploy_path
173-
)
174-
return os.path.join(self.deploy_path, *paths)
175-
176-
def copy_env(self, *args, **kw):
177-
env = os.environ.copy()
178-
env.update(*args, **kw)
179-
return env
180-
181-
def wait(self, coro):
182-
return asyncio.get_event_loop().run_until_complete(coro)

agiletoolkit/test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
"""
3535

3636

37+
CODEBUILD = """\
38+
name: test
39+
description: test
40+
source:
41+
location: https://github.com/example/example.git
42+
"""
43+
44+
3745
@contextmanager
3846
def gitrepo(branch, pr=False, tag=None, head_id=None):
3947
"""
@@ -60,6 +68,8 @@ def mocker(root=None):
6068
os.makedirs('deploy')
6169
with open('Makefile', 'w') as f:
6270
f.write(MAKEFILE.replace('<tab>', '\t'))
71+
with open('deploy/codebuild.yaml', 'w') as f:
72+
f.write(CODEBUILD)
6373
with mock.patch('agiletoolkit.utils.gitrepo', side_effect=mocker) as m:
6474
try:
6575
yield m

0 commit comments

Comments
 (0)