Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #86 from user-cont/release-bugfix
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
jpopelka authored Sep 14, 2018
2 parents f4d64c2 + 288d48e commit 1975538
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
3 changes: 0 additions & 3 deletions Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@ RUN chown -R 1001:0 ${HOME}

USER 1001

RUN git config --global user.email "[email protected]" && \
git config --global user.name "John Doe"

CMD make test
19 changes: 19 additions & 0 deletions release_bot/fedora.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ def fedpkg_clone_repository(directory, name):
else:
return ''

@staticmethod
def set_git_credentials(repo_path, name, email):
"""
Sets credentials fo git repo to keep git from resisting to commit
:param repo_path: path to git repository
:param name: committer name
:param email: committer email
:return: True on success False on fail
"""
email = shell_command(repo_path, f'git config user.email "{email}"', '', fail=False)
name = shell_command(repo_path, f'git config user.name "{name}"', '', fail=False)
return email and name

@staticmethod
def fedpkg_switch_branch(directory, branch, fail=True):
if not os.path.isdir(directory):
Expand Down Expand Up @@ -203,6 +216,12 @@ def release(self, new_release):
if not fedpkg_root:
return False

# set git credentials
if not self.set_git_credentials(fedpkg_root,
new_release['commit_name'],
new_release['commit_email']):
return False

# make sure the current branch is master
if not self.fedpkg_switch_branch(fedpkg_root, "master"):
return False
Expand Down
7 changes: 3 additions & 4 deletions release_bot/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,9 @@ def make_release_pr(self, new_pr):
changelog = repo.get_log_since_last_release(new_pr['previous_version'])
repo.checkout_new_branch(branch)
changed = look_for_version_files(repo.repo_path, new_pr['version'])
changelog_changed = insert_in_changelog(f'{repo.repo_path}/CHANGELOG.md',
new_pr['version'], changelog)
if changelog_changed:
changed.append(f'{repo.repo_path}/CHANGELOG.md')
if insert_in_changelog(f'{repo.repo_path}/CHANGELOG.md',
new_pr['version'], changelog):
repo.add(['CHANGELOG.md'])
if changed:
repo.add(changed)
repo.commit(f'{version} release', allow_empty=True)
Expand Down
3 changes: 3 additions & 0 deletions release_bot/releasebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def release_handler(success):
self.github.comment.append(msg)

try:
name, email = self.github.get_user_contact()
self.new_release['commit_name'] = name
self.new_release['commit_email'] = email
success_ = self.fedora.release(self.new_release)
release_handler(success_)
except ReleaseException:
Expand Down
9 changes: 6 additions & 3 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,20 @@ def multiple_release_issues(self):
self.g_utils.open_issue("0.0.1 release")
self.g_utils.open_issue("0.0.2 release")

@pytest.fixture()
def open_pr(self):
"""Opens two release issues in a repository"""
conf = yaml.safe_load(RELEASE_CONF) or {}
self.release_bot.new_release.update(conf)
self.open_issue()
self.g_utils.open_issue("0.0.1 release")
self.release_bot.find_open_release_issues()
self.release_bot.make_release_pull_request()
pr_number = self.release_bot.github.pr_exists("0.0.1 release")
assert pr_number and self.g_utils.merge_pull_request(pr_number)

@pytest.fixture()
def open_pr_fixture(self):
self.open_pr()

@pytest.fixture()
def github_release(self):
"""Setups environment for releasing on Github"""
Expand Down Expand Up @@ -124,7 +127,7 @@ def test_pr_from_issue(self, open_issue):
assert self.release_bot.make_release_pull_request()
assert self.release_bot.github.pr_exists("0.0.1 release")

def test_github_release(self, open_pr):
def test_github_release(self, open_pr_fixture):
"""Tests releasing on Github"""
assert self.release_bot.find_newest_release_pull_request()
self.release_bot.make_new_github_release()
Expand Down
19 changes: 11 additions & 8 deletions tests/test_fedora.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def fake_repository_clone_func(self, directory, name, non_ff=False):
def create_fake_repository(self, directory, non_ff=False):
self.run_cmd("git init .", directory)
self.run_cmd("git checkout -b master", directory)
assert self.fedora.set_git_credentials(directory, "Name", "[email protected]")
spec_content = Path(__file__).parent.joinpath("src/example.spec").read_text()
Path(directory).joinpath("example.spec").write_text(spec_content)
self.run_cmd("git add .", directory)
Expand All @@ -93,6 +94,8 @@ def new_release(self):
'commitish': '',
'author_name': 'John Doe',
'author_email': '[email protected]',
'commit_name': 'Testy McTestFace',
'commit_email': '[email protected]',
'python_versions': [3],
'fedora_branches': ["f28"],
'fedora': True,
Expand Down Expand Up @@ -163,7 +166,7 @@ def package(self):

@pytest.fixture
def non_existent_path(self, tmpdir):
path = Path(str(tmpdir))/'fooo'
path = Path(str(tmpdir)) / 'fooo'
return str(path)

@pytest.fixture
Expand All @@ -177,8 +180,8 @@ def fake_repository(self, tmpdir):

@pytest.fixture
def example_spec(self, tmpdir):
spec_content = (Path(__file__).parent/"src/example.spec").read_text()
spec = Path(str(tmpdir))/"example.spec"
spec_content = (Path(__file__).parent / "src/example.spec").read_text()
spec = Path(str(tmpdir)) / "example.spec"
spec.write_text(spec_content)
return str(spec)

Expand Down Expand Up @@ -220,8 +223,8 @@ def test_wrong_dir_lint(self, non_existent_path):

def test_clone(self, tmp, package, fake_clone):
directory = Path(self.fedora.fedpkg_clone_repository(tmp, package))
assert (directory/f"{package}.spec").is_file()
assert (directory/".git").is_dir()
assert (directory / f"{package}.spec").is_file()
assert (directory / ".git").is_dir()

def test_switch_branch(self, fake_repository):
self.fedora.fedpkg_switch_branch(fake_repository, "f28", False)
Expand All @@ -230,7 +233,7 @@ def test_switch_branch(self, fake_repository):
assert "master" == self.run_cmd("git rev-parse --abbrev-ref HEAD", fake_repository).stdout.strip()

def test_commit(self, fake_repository):
spec_path = fake_repository/"example.spec"
spec_path = fake_repository / "example.spec"
spec_content = spec_path.read_text() + "\n Test test"
spec_path.write_text(spec_content)

Expand All @@ -244,7 +247,7 @@ def test_lint(self, tmp, package, fake_clone):
directory = Path(self.fedora.fedpkg_clone_repository(tmp, package))
assert self.fedora.fedpkg_lint(str(directory), "master", False)

spec_path = directory/f"{package}.spec"
spec_path = directory / f"{package}.spec"
with spec_path.open('r+') as spec_file:
spec = spec_file.read() + "\n Test test"
spec_file.write(spec)
Expand All @@ -263,7 +266,7 @@ def test_spectool(self, tmp, package, fake_clone):
assert file_number != len(os.listdir(directory))

def test_workflow(self, fake_repository):
spec_path = fake_repository/"example.spec"
spec_path = fake_repository / "example.spec"
spec_content = spec_path.read_text() + "\n Test test"
spec_path.write_text(spec_content)

Expand Down

0 comments on commit 1975538

Please sign in to comment.