Skip to content

Commit

Permalink
Merge pull request #46 from norby4ever/master
Browse files Browse the repository at this point in the history
Add changelog to spec
  • Loading branch information
fedya authored Jun 25, 2024
2 parents 989b1ad + 815bf1d commit 411e2c8
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions abf.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,14 @@ def localbuild_rpmbuild():
log.error(_('Can not locate a spec file in %s') % src_dir)
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)

cmd = ['rpmbuild', '-b'+command_line.build, '--define', '_topdir '+src_dir, '--define', '_sourcedir '+src_dir, spec_path]
if command_line.verbose:
cmd.append('-v')
Expand Down Expand Up @@ -1730,6 +1738,47 @@ 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 = []
author = ''
tag = ''
lines_cnt = 0
for line in log:
lines_cnt += 1
if line.startswith('commit'):
if lines_cnt >= 15000:
return ['', '%changelog'] + res[1:]
if f'tag: {branch}-' in line:
tag = ' ' + line.replace(')', ',').split(f'tag: {branch}-')[1].split(',')[0]
else: tag = ''
res.append('')
elif line.startswith('Author: '):
author = line.lstrip('Author: ').strip()
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))
elif line.strip() != '':
res.append(remove_macros(line.strip()))
return ['', '%changelog'] + res[1:]


if __name__ == '__main__':
global projects_cfg
Expand Down

0 comments on commit 411e2c8

Please sign in to comment.