Skip to content

Commit

Permalink
rewrite changelog generator
Browse files Browse the repository at this point in the history
  • Loading branch information
fedya committed Jul 16, 2024
1 parent 411e2c8 commit 78411ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
38 changes: 14 additions & 24 deletions abf.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,13 @@ def localbuild_rpmbuild():
exit(1)
spec_path = os.path.join(src_dir, spec_path)
spec_lines = open(spec_path, 'r').readlines()
if '%changelog' not in [line.strip() for line in spec_lines]:
log_lines = subprocess.run(f'cd "{src_dir}" && LC_ALL=C.UTF-8 git log --decorate=short', shell=True, capture_output=True).stdout.decode().split('\n')
branch = subprocess.run(f'cd "{src_dir}" && LC_ALL=C.UTF-8 git branch --show-current', shell=True, capture_output=True).stdout.decode().strip()
changelog_lines = create_changelog_from_log(log_lines, branch)
with open(spec_path, 'a') as out:
print(*changelog_lines, sep='\n', file=out)
if default_changelog == 'enabled':
if '%changelog' not in [line.strip() for line in spec_lines]:
log_lines = subprocess.run(f'cd "{src_dir}" && LC_ALL=C.UTF-8 git log --decorate=short', shell=True, capture_output=True).stdout.decode().split('\n')
branch = subprocess.run(f'cd "{src_dir}" && LC_ALL=C.UTF-8 git branch --show-current', shell=True, capture_output=True).stdout.decode().strip()
changelog_lines = create_changelog_from_log(log_lines, branch)
with open(spec_path, 'a') as out:
print(*changelog_lines, sep='\n', file=out)

cmd = ['rpmbuild', '-b'+command_line.build, '--define', '_topdir '+src_dir, '--define', '_sourcedir '+src_dir, spec_path]
if command_line.verbose:
Expand Down Expand Up @@ -1738,20 +1739,6 @@ def clean():
_update_location()
find_spec_problems(auto_remove=command_line.auto_remove)

def remove_macros(line):
line = list(line)
for i in range(len(line)):
if line[i] == '%':
if i == 0:
if len(line) > 1 and line[i + 1] != '%':
line[0] = '🤶🏿'
elif i == len(line) - 1:
if len(line) > 1 and line[-2] != '%':
line[-1] = '🤶🏿'
else:
if line[i - 1] != '%' and line[i + 1] != '%':
line[i] = '🤶🏿'
return ''.join(line).replace('🤶🏿', '%%')

def create_changelog_from_log(log, branch):
res = []
Expand All @@ -1765,18 +1752,20 @@ def create_changelog_from_log(log, branch):
return ['', '%changelog'] + res[1:]
if f'tag: {branch}-' in line:
tag = ' ' + line.replace(')', ',').split(f'tag: {branch}-')[1].split(',')[0]
else: tag = ''
else:
tag = ''
res.append('')
elif line.startswith('Author: '):
author = line.lstrip('Author: ').strip()
author = line.split(': ')[1].strip()
print(author)
elif line.startswith('Date: '):
date_words = line.split()
if len(date_words) < 6:
continue
date = ' '.join([date_words[1], date_words[2], date_words[3], date_words[5]])
res.append(remove_macros('* ' + date + ' ' + author + tag))
res.append('* ' + date + ' ' + author + tag)
elif line.strip() != '':
res.append(remove_macros(line.strip()))
res.append(line.strip().replace('%', '%%'))
return ['', '%changelog'] + res[1:]


Expand Down Expand Up @@ -1810,6 +1799,7 @@ def create_changelog_from_log(log, branch):
login = cfg['user']['login']
password = cfg['user']['password']
default_group = cfg['user']['default_group']
default_changelog = cfg['user']['changelog']
default_build_platform = cfg['user']['default_build_platform']
default_branch = cfg['user']['default_branch']
models_params = ((abf_url, file_store_url, login, password))
Expand Down
1 change: 1 addition & 0 deletions abf/console/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def first_start(self):
git_uri = "ssh://[email protected]/OpenMandrivaAssociation"

self['user']['git_uri'] = git_uri
self['user']['changelog'] = 'disabled'

if 'default_branch' not in self['user']:
def_br = 'master'
Expand Down

0 comments on commit 78411ae

Please sign in to comment.