Skip to content

Commit aef25be

Browse files
committed
Fix the commit message
* first letter in uppercase * Signed-off-by trailer Signed-off-by: Gaëtan Lehmann <[email protected]>
1 parent 90009aa commit aef25be

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

scripts/rpm_owners/set_github_code_owners.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77
import re
88
import sys
99
from contextlib import suppress
10+
from subprocess import check_output
1011

1112
import github as gh
1213
from github.Repository import Repository
1314

1415
BRANCHES = ['master']
1516
CODEOWNERS = '.github/CODEOWNERS'
17+
USER = check_output(['git', 'config', 'user.name']).decode().strip()
18+
EMAIL = check_output(['git', 'config', 'user.email']).decode().strip()
19+
assert USER and len(USER.splitlines()) == 1
20+
assert EMAIL and len(EMAIL.splitlines()) == 1
21+
MESSAGE = f"""Set team owner
1622
23+
Signed-off-by: {USER} <{EMAIL}>
24+
"""
1725

1826
def to_gh_team(maintainer: str):
1927
return '@xcp-ng-rpms/' + re.sub(r'\W+', '-', maintainer.lower())
@@ -42,17 +50,23 @@ def set_gh_code_owners(repo: Repository, rpm, force: bool) -> bool:
4250
ok = True
4351
for branch in BRANCHES:
4452
current_content = None
53+
current_content_sha = ''
4554
with suppress(gh.UnknownObjectException):
46-
current_content = repo.get_contents(CODEOWNERS, branch).decoded_content.decode() # type: ignore
47-
if current_content is None or (force and current_content != content):
48-
action = "creating" if current_content is None else "updating"
49-
print(f'{action} {pkg} CODEOWNERS file in {branch}...', end='', file=sys.stderr)
50-
repo.create_file(CODEOWNERS, "set team owner", content, branch)
55+
gh_content = repo.get_contents(CODEOWNERS, branch)
56+
current_content_sha = gh_content.sha # type: ignore
57+
current_content = gh_content.decoded_content.decode() # type: ignore
58+
if current_content is None:
59+
print(f'creating {pkg} CODEOWNERS file in {branch}...', end='', file=sys.stderr, flush=True)
60+
repo.create_file(CODEOWNERS, MESSAGE, content, branch)
61+
print(' done', file=sys.stderr)
62+
elif force and current_content != content:
63+
print(f'updating {pkg} CODEOWNERS file in {branch}...', end='', file=sys.stderr, flush=True)
64+
repo.update_file(CODEOWNERS, MESSAGE, content, current_content_sha, branch)
5165
print(' done', file=sys.stderr)
5266
elif current_content == content:
53-
print(f'{pkg} CODEOWNERS is already OK in {branch}', file=sys.stderr)
67+
print(f'{pkg} CODEOWNERS is already OK in {branch}', file=sys.stderr, flush=True)
5468
else:
55-
print(f'error: {pkg} CODEOWNERS is not synced in {branch}', file=sys.stderr)
69+
print(f'error: {pkg} CODEOWNERS is not synced in {branch}', file=sys.stderr, flush=True)
5670
print(diff(current_content, content))
5771
ok = False
5872
return ok

0 commit comments

Comments
 (0)