Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Simon Chabot
hg-autochangelog
Commits
316d8f183520
Commit
48d6c712
authored
Apr 05, 2020
by
Simon Chabot
Browse files
feat: show the version release date in the changelog
parent
76ef4e904a54
Changes
2
Hide whitespace changes
Inline
Side-by-side
hg_autochangelog/main.py
View file @
316d8f18
...
...
@@ -5,6 +5,7 @@ import re
import
pathlib
import
sys
from
enum
import
Enum
from
datetime
import
datetime
from
dataclasses
import
dataclass
from
collections
import
defaultdict
...
...
@@ -21,6 +22,12 @@ with open(ROOT / "templates" / "changelog.md") as fobj:
CHANGE_LOG_TEMPLATE
=
Template
(
fobj
.
read
())
@
dataclass
(
frozen
=
True
)
class
Version
:
label
:
str
=
"upcoming"
release_date
:
datetime
=
datetime
.
now
()
class
ChangeType
(
Enum
):
chore
=
"chore"
ci
=
"ci"
...
...
@@ -103,7 +110,7 @@ class Changelog:
def
__init__
(
self
):
self
.
changes_by_version
=
defaultdict
(
lambda
:
defaultdict
(
list
))
def
add_commit
(
self
,
commit
,
version
=
None
):
def
add_commit
(
self
,
commit
,
version
=
Version
()
):
change
=
self
.
_change_from_commit
(
commit
)
if
not
change
:
return
...
...
@@ -131,7 +138,7 @@ class Changelog:
)
def
autochangelog
(
ui
,
repo
,
**
opts
):
changelog
=
Changelog
()
version
=
"upcoming"
version
=
Version
()
user_revs
=
opts
[
"revs"
].
decode
(
"utf-8"
)
for
rev
in
repo
.
revs
(
f
"sort(
{
user_revs
}
, -date)"
.
encode
(
"utf-8"
)):
...
...
@@ -142,7 +149,10 @@ def autochangelog(ui, repo, **opts):
tags
=
[
t
for
t
in
commit
.
tags
()
if
t
!=
b
"tip"
]
if
tags
:
version
=
tags
[
0
].
decode
(
"utf-8"
)
version
=
Version
(
tags
[
0
].
decode
(
"utf-8"
),
datetime
.
fromtimestamp
(
commit
.
date
()[
0
])
)
changelog
.
add_commit
(
commit
,
version
)
print
(
changelog
.
render
())
hg_autochangelog/templates/changelog.md
View file @
316d8f18
...
...
@@ -13,10 +13,10 @@
{%- endmacro %}
# CHANGELOG
{% for version, changes in changelog.changes_by_version.items() %}
{%- if version == "upcoming" %}
{%- if version
.label
== "upcoming" %}
## Upcoming version
{% else %}
## Version {{ version
}}
## Version {{ version
.label }} ({{ version.release_date.strftime('%Y-%m-%d') }})
{%- endif %}
{{- new_section(changes, ChangeType.feat, "New features") }}
{{- new_section(changes, ChangeType.perf, "Performance improvements") }}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment