Skip to content

Commit

Permalink
Return the changelog from the changelog module
Browse files Browse the repository at this point in the history
Additionally changes the changelog module parameter from changelog
to entry to better reflect what the parameter being supplied is
and reduce the occurrances of the word changelog. The intent is for
changelog to represent the whole changelog and entry to represent
an item in the changelog.
  • Loading branch information
ehelms committed Mar 30, 2021
1 parent 158cf11 commit cb78080
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
29 changes: 17 additions & 12 deletions obal/data/modules/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def main():
module = AnsibleModule(
argument_spec=dict(
spec=dict(required=True),
changelog=dict(default='- rebuilt')
entry=dict(required=False)
)
)

spec = module.params['spec']
changelog = module.params['changelog']
entry = module.params['entry']

user = subprocess.check_output(['rpmdev-packager'], universal_newlines=True).strip()
evr = get_specfile_evr(spec)
Expand All @@ -50,22 +50,27 @@ def main():

changed = False

if not changelog.startswith('-'):
changelog = '- ' + changelog
if entry and not entry.startswith('-'):
entry = '- ' + entry

for i, line in enumerate(lines):
if line.startswith("%changelog"):
with en_locale():
date = time.strftime("%a %b %d %Y", time.gmtime())
entry = "* %s %s - %s\n%s\n\n" % (date, user, evr, changelog)
lines[i] += entry
changed = True
if entry:
with en_locale():
date = time.strftime("%a %b %d %Y", time.gmtime())
entry = "* %s %s - %s\n%s\n\n" % (date, user, evr, entry)
lines[i] += entry
changed = True
changelog = lines[i+1:]
break

with open(spec, "w") as spec_file:
spec_file.writelines(lines)
if changed:
with open(spec, "w") as spec_file:
spec_file.writelines(lines)

module.exit_json(changed=changed)
changelog = ''.join(changelog).rstrip()

module.exit_json(changed=changed, changelog=changelog)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion obal/data/playbooks/changelog/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
- name: 'ensure changelog'
changelog:
spec: "{{ spec_file_path }}"
changelog: "{{ changelog | default('- rebuilt') }}"
entry: "{{ changelog | default('- rebuilt') }}"
2 changes: 1 addition & 1 deletion obal/data/roles/update_spec_file/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@
- name: 'add changelog entry'
changelog:
spec: "{{ spec_file_path }}"
changelog: "{{ changelog }}"
entry: "{{ changelog }}"
when: changelog is defined

0 comments on commit cb78080

Please sign in to comment.