7.9 KiB
Usage
Theory
This lib will try to extract normalized changes from a given raw history.
It’s up to the user to provide this merged history.
To realize this job, parsing is done in two rounds:
- first round extrats formal changes messages: e.g.:
<change_type>(<change_target>): <change_message> - secound round extracts lines from remaining ones, based on keywords dictionnaries
/// warning | searching policy When formal search (1), lines must contain at least 2 words When keywords search (2), lines must contain at least 3 words ///
/// note | ignored lines lines with comment tags are ignored:
[0..N space]//[0..N space]#///
Installation
From pypi repository (prefered):
python -m pip install pychangelogfactory
From downloaded .whl file:
python -m pip install pychangelogfactory-<VERSION>-py3-none-any.whl
From master git repository:
python -m pip install git+https://chacha.ddns.net/gitea/chacha/pychangelogfactory.git@master
Use in your project
Sample code
from pychangelogfactory import ChangelogFactory
raw_changelog = (
"feat: add a nice feature to the project\n"
"style: reindent the full Foo class\n"
"security: fix a security issue on the Foo2 component\n"
"security: fix another security problem on the Foo2 component\n"
"improve core performances by reducing complexity\n"
"some random changes in the text content\n"
)
hdlr = ChangelogFactory()
hdlr.ProcessFullChangelog(self.raw_changelog)
changelog = hdlr.RenderFullChangelog()
print(changelog)Or shorted version:
hdlr = ChangelogFactory(self.raw_changelog)
changelog = hdlr.RenderFullChangelog()Or one-liner version:
changelog = ChangelogFactory(self.raw_changelog).RenderFullChangelog()Output(Raw)
#### Features :sparkles: :
> add a nice feature to the project
#### Security :shield: :
> security: fix a security issue on the Foo2 component
> security: fix another security problem on the Foo2 component
#### Performance Enhancements :rocket: :
> improve core performances by reducing complexity
#### Style :art: :
> reindent the full Foo class
Output (rendered)
Features ✨ :
add a nice feature to the project #### Security 🛡️ : security: fix a security issue on the Foo2 component
security: fix another security problem on the Foo2 component #### Performance Enhancements 🚀 : improve core performances by reducing complexity #### Style 🎨 : reindent the full Foo class
Options
Display unknown messages types
from pychangelogfactory import ChangelogFormater
raw_changelog = (
"feat: add a nice feature to the project\n"
"style: reindent the full Foo class\n"
"security: fix a security issue on the Foo2 component\n"
"security: fix another security problem on the Foo2 component\n"
"improve core performances by reducing complexity\n"
"some random changes in the text content\n"
)
changelog = ChangelogFactory(self.raw_changelog).RenderFullChangelog(include_unknown=True)
print(changelog)Output (rendered)
Features :sparkles::
add a nice feature to the project #### Security :shield:: fix a security issue on the Foo2 component fix another security problem on the Foo2 component #### Performance Enhancements :rocket:: improve core performances by reducing complexity #### Style :art:: reindent the full Foo class #### Others :question:: some random changes in the text content
Supported types
| Type/Tag | Priority | Keywords | Title | Class Name |
|---|---|---|---|---|
| break | 20 | break | 🚨 Breaking changes 🚨 : | ChangelogFormater_break |
| feat | 20 | feat, new, create, add | Features ✨ : | ChangelogFormater_feat |
| fix | 0 | fix, issue, problem | Fixes 🔧 : | ChangelogFormater_fix |
| security | 20 | safe, leak | Security 🛡️ : | ChangelogFormater_security |
| chore | 10 | task, refactor, build, better, improve | Chore 🏗️ : | ChangelogFormater_chore |
| perf | 15 | fast, perf | Performance Enhancements 🚀 : | ChangelogFormater_perf |
| wip | 0 | temp | Work in progress changes 🚧 : | ChangelogFormater_wip |
| doc | 0 | doc, manual | Documentations 📖 : | ChangelogFormater_wip |
| style | 5 | beautify | Style 🎨 : | ChangelogFormater_style |
| refactor | 0 | Refactorings ♻️ : | ChangelogFormater_refactor |
|
| ci | 0 | jenkins, git | Continuous Integration 🌀 : | ChangelogFormater_ci |
| test | -5 | unittest, check, testing | Testings 🚦 : | ChangelogFormater_test |
| build | 0 | compile, version | Builds 📦 : | ChangelogFormater_build |
| revert | 0 | revert, fallback | Reverts 🔙 : | ChangelogFormater_revert |
| other | -20 | Others ❓ : | ChangelogFormater_others |
Add new types
New formaters can be easily added by subclassing
ChangelogFormater:
Inject custom formater locally (prefered way)
from pychangelogfactory import ChangelogFormater,ChangelogFactory
class ChangelogFormater_others(ChangelogFormater):
"""My formater"""
prefix: str = "mytag"
title: str = "My Title :"
keywords: list[str] = ["foo","42"]
priority: int = 10
hdlr = ChangelogFactory()
hdlr.RegisterFormater(ChangelogFormater_others)
...Inject custom formater module-wide
from pychangelogfactory import ChangelogFormater,ChangelogFormaterRecordType
@ChangelogFormaterRecordType
class ChangelogFormater_others(ChangelogFormater):
"""My formater"""
prefix: str = "mytag"
title: str = "My Title :"
keywords: list[str] = ["foo","42"]
priority: int = 10
hdlr = ChangelogFactory()
.../// note | Scope This will register your new formater for all next new factories, maybe not only in your own code ! /// ### Test
raw_changelog = ("mytag: add a nice feature to the project\n"
"foo modification in my file\n"
"need 42 coffee\n"
)
hdlr = ChangelogFactory(raw_changelog)
changelog = hdlr.RenderFullChangelog(include_unknown=True)
print(changelog)Output
My Title :
add a nice feature to the project
foo modification in my file
need 42 coffee
Revert changes
Reset to original list class-wise (all modules):
ChangelogFactory.ResetBaseFormaterList()
...Reset to original list instance-wise:
hdlr = ChangelogFactory()
hdlr.ResetFormaterList()
...Removing a specific formater:
hdlr = ChangelogFactory()
hdlr.unRegisterFormater(ChangelogFormater_others)
.../// warning There is no way to remove a specific formater class-wise (all modules) except using ResetFormaterList(). ///