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

Commit 1975538

Browse files
authored
Merge pull request #86 from user-cont/release-bugfix
Bugfixes
2 parents f4d64c2 + 288d48e commit 1975538

File tree

6 files changed

+42
-18
lines changed

6 files changed

+42
-18
lines changed

Dockerfile.test

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,4 @@ RUN chown -R 1001:0 ${HOME}
2121

2222
USER 1001
2323

24-
RUN git config --global user.email "[email protected]" && \
25-
git config --global user.name "John Doe"
26-
2724
CMD make test

release_bot/fedora.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ def fedpkg_clone_repository(directory, name):
3838
else:
3939
return ''
4040

41+
@staticmethod
42+
def set_git_credentials(repo_path, name, email):
43+
"""
44+
Sets credentials fo git repo to keep git from resisting to commit
45+
:param repo_path: path to git repository
46+
:param name: committer name
47+
:param email: committer email
48+
:return: True on success False on fail
49+
"""
50+
email = shell_command(repo_path, f'git config user.email "{email}"', '', fail=False)
51+
name = shell_command(repo_path, f'git config user.name "{name}"', '', fail=False)
52+
return email and name
53+
4154
@staticmethod
4255
def fedpkg_switch_branch(directory, branch, fail=True):
4356
if not os.path.isdir(directory):
@@ -203,6 +216,12 @@ def release(self, new_release):
203216
if not fedpkg_root:
204217
return False
205218

219+
# set git credentials
220+
if not self.set_git_credentials(fedpkg_root,
221+
new_release['commit_name'],
222+
new_release['commit_email']):
223+
return False
224+
206225
# make sure the current branch is master
207226
if not self.fedpkg_switch_branch(fedpkg_root, "master"):
208227
return False

release_bot/github.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,9 @@ def make_release_pr(self, new_pr):
324324
changelog = repo.get_log_since_last_release(new_pr['previous_version'])
325325
repo.checkout_new_branch(branch)
326326
changed = look_for_version_files(repo.repo_path, new_pr['version'])
327-
changelog_changed = insert_in_changelog(f'{repo.repo_path}/CHANGELOG.md',
328-
new_pr['version'], changelog)
329-
if changelog_changed:
330-
changed.append(f'{repo.repo_path}/CHANGELOG.md')
327+
if insert_in_changelog(f'{repo.repo_path}/CHANGELOG.md',
328+
new_pr['version'], changelog):
329+
repo.add(['CHANGELOG.md'])
331330
if changed:
332331
repo.add(changed)
333332
repo.commit(f'{version} release', allow_empty=True)

release_bot/releasebot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ def release_handler(success):
234234
self.github.comment.append(msg)
235235

236236
try:
237+
name, email = self.github.get_user_contact()
238+
self.new_release['commit_name'] = name
239+
self.new_release['commit_email'] = email
237240
success_ = self.fedora.release(self.new_release)
238241
release_handler(success_)
239242
except ReleaseException:

tests/test_bot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,20 @@ def multiple_release_issues(self):
7272
self.g_utils.open_issue("0.0.1 release")
7373
self.g_utils.open_issue("0.0.2 release")
7474

75-
@pytest.fixture()
7675
def open_pr(self):
7776
"""Opens two release issues in a repository"""
7877
conf = yaml.safe_load(RELEASE_CONF) or {}
7978
self.release_bot.new_release.update(conf)
80-
self.open_issue()
79+
self.g_utils.open_issue("0.0.1 release")
8180
self.release_bot.find_open_release_issues()
8281
self.release_bot.make_release_pull_request()
8382
pr_number = self.release_bot.github.pr_exists("0.0.1 release")
8483
assert pr_number and self.g_utils.merge_pull_request(pr_number)
8584

85+
@pytest.fixture()
86+
def open_pr_fixture(self):
87+
self.open_pr()
88+
8689
@pytest.fixture()
8790
def github_release(self):
8891
"""Setups environment for releasing on Github"""
@@ -124,7 +127,7 @@ def test_pr_from_issue(self, open_issue):
124127
assert self.release_bot.make_release_pull_request()
125128
assert self.release_bot.github.pr_exists("0.0.1 release")
126129

127-
def test_github_release(self, open_pr):
130+
def test_github_release(self, open_pr_fixture):
128131
"""Tests releasing on Github"""
129132
assert self.release_bot.find_newest_release_pull_request()
130133
self.release_bot.make_new_github_release()

tests/test_fedora.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def fake_repository_clone_func(self, directory, name, non_ff=False):
7373
def create_fake_repository(self, directory, non_ff=False):
7474
self.run_cmd("git init .", directory)
7575
self.run_cmd("git checkout -b master", directory)
76+
assert self.fedora.set_git_credentials(directory, "Name", "[email protected]")
7677
spec_content = Path(__file__).parent.joinpath("src/example.spec").read_text()
7778
Path(directory).joinpath("example.spec").write_text(spec_content)
7879
self.run_cmd("git add .", directory)
@@ -93,6 +94,8 @@ def new_release(self):
9394
'commitish': '',
9495
'author_name': 'John Doe',
9596
'author_email': '[email protected]',
97+
'commit_name': 'Testy McTestFace',
98+
'commit_email': '[email protected]',
9699
'python_versions': [3],
97100
'fedora_branches': ["f28"],
98101
'fedora': True,
@@ -163,7 +166,7 @@ def package(self):
163166

164167
@pytest.fixture
165168
def non_existent_path(self, tmpdir):
166-
path = Path(str(tmpdir))/'fooo'
169+
path = Path(str(tmpdir)) / 'fooo'
167170
return str(path)
168171

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

178181
@pytest.fixture
179182
def example_spec(self, tmpdir):
180-
spec_content = (Path(__file__).parent/"src/example.spec").read_text()
181-
spec = Path(str(tmpdir))/"example.spec"
183+
spec_content = (Path(__file__).parent / "src/example.spec").read_text()
184+
spec = Path(str(tmpdir)) / "example.spec"
182185
spec.write_text(spec_content)
183186
return str(spec)
184187

@@ -220,8 +223,8 @@ def test_wrong_dir_lint(self, non_existent_path):
220223

221224
def test_clone(self, tmp, package, fake_clone):
222225
directory = Path(self.fedora.fedpkg_clone_repository(tmp, package))
223-
assert (directory/f"{package}.spec").is_file()
224-
assert (directory/".git").is_dir()
226+
assert (directory / f"{package}.spec").is_file()
227+
assert (directory / ".git").is_dir()
225228

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

232235
def test_commit(self, fake_repository):
233-
spec_path = fake_repository/"example.spec"
236+
spec_path = fake_repository / "example.spec"
234237
spec_content = spec_path.read_text() + "\n Test test"
235238
spec_path.write_text(spec_content)
236239

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

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

265268
def test_workflow(self, fake_repository):
266-
spec_path = fake_repository/"example.spec"
269+
spec_path = fake_repository / "example.spec"
267270
spec_content = spec_path.read_text() + "\n Test test"
268271
spec_path.write_text(spec_content)
269272

0 commit comments

Comments
 (0)