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

Commit a54333e

Browse files
author
Jan Koscielniak
committed
Fix git credentials for Fedora releasing
1 parent f4d64c2 commit a54333e

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
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/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_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)