-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchanellog.py
66 lines (55 loc) · 1.83 KB
/
chanellog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
from datetime import date
from os.path import exists
today=date.today()
version="1.2.3"
item = "## [{}] - {}".format(version, today)
# use below to correspond with your tagged version
# version=subprocess.check_output(["git", "describe", "--long"]).strip()
changelog_start="""# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
{}
### Added
- ADD CHANGE HERE!
""".format(item)
def read_changelog():
changelog = open('CHANGELOG.md', 'r')
changelog_items = changelog.readlines()
return changelog_items
def write_changelog_lines(changelog_items):
with open('CHANGELOG.md', 'w') as changelog:
changelog.writelines(changelog_items)
def changelog_helper(item):
changelog_items=read_changelog()
does_exist=False
for line in changelog_items:
if item.strip() in line.strip():
does_exist=True
break
return does_exist
def new_changelog_item():
is_found=changelog_helper(item)
if (is_found):
print("Changelog item already exists for \n {}".format(item))
else:
index = -1
changelog_items=read_changelog()
for line in changelog_items:
index+=1
if "## [Unreleased]" in line:
changelog_items[index] = "## [Unreleased]\n{}\n### Added\n- ADD CHANGE HERE!\n".format(item)
write_changelog_lines(changelog_items)
break
def new_changelog():
changelog = open("CHANGELOG.md", "w")
changelog.write(changelog_start)
changelog.close()
def init():
if exists('CHANGELOG.md'):
new_changelog_item()
else:
new_changelog()
init()