Skip to content

Commit

Permalink
Store additional context
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljoseph committed Dec 9, 2014
1 parent facba40 commit f457cf5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ def generate_changelog(context):
dry_run=context.dry_run
)
log.info('Added content to CHANGELOG.md')
context.changelog_content = changelog_content
26 changes: 25 additions & 1 deletion changes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
import click
from giturlparse import parse
from plumbum.cmd import git
from plumbum import local
import yaml

CONFIG_FILE = '.changes'
DEFAULTS = {
'changelog': 'CHANGELOG.md',
'readme': 'README.md',
'gh_token': None,
}


class CLI(object):
test_command = None
pypi = None
skip_changelog = None
changelog_content = None
parsed_repo = None

def __init__(self, module_name, dry_run, debug, no_input, requirements,
new_version, current_version, repo_url, version_prefix):
Expand All @@ -32,8 +36,28 @@ def __init__(self, module_name, dry_run, debug, no_input, requirements,
self.current_version = current_version
self.repo_url = repo_url

self.parsed_repo = parse(git('config --get remote.origin.url'.split(' ')))

@property
def repo(self):
return self.parsed_repo.repo

@property
def owner(self):
return self.parsed_repo.owner

@property
def github(self):
return self.parsed_repo.github

@property
def bitbucket(self):
return self.parsed_repo.bitbucket


@property
def parsed_repo(self):
with local.cwd(local.cwd / self.module_name):
return parse(git('config --get remote.origin.url'.split(' ')))

@property
def repo(self):
Expand Down
7 changes: 5 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

module_name = 'test_app'
context = CLI(module_name, True, True, True, '%s/requirements.txt' % module_name, '0.0.2', '0.0.1', 'https://github.com/someuser/test_app', None)
context.gh_token = 'foo'
context.requirements = '%s/requirements.txt' % module_name
context.tmp_file = '%s/__init__.py' % module_name
context.initial_init_content = [
Expand All @@ -31,8 +32,10 @@ def setup():
with open(context.requirements, 'w') as req_file:
req_file.write('pytest')

with local.cwd(local.cwd / module_name):
git('init', module_name)
with local.cwd(local.cwd / context.module_name):
git('init')
git('remote', 'add', 'origin', 'https://github.com/michaeljoseph/test_app.git')


def teardown():
if os.path.exists(context.tmp_file):
Expand Down
1 change: 1 addition & 0 deletions tests/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ def test_replace_sha_with_commit_link():

def test_generate_changelog():
changelog.generate_changelog(context)
assert isinstance(context.changelog_content, list)
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ def test_malformed_config_returns_none():

def test_parsed_repo_url():
assert context.owner == 'michaeljoseph'
assert context.repo == 'test_app'
assert context.github
assert not context.bitbucket

0 comments on commit f457cf5

Please sign in to comment.