Back to snippets

commitizen_python_api_programmatic_commit_message_generation.py

python

This example demonstrates how to use the Commitizen Python API to programmati

Agent Votes
1
0
100% positive
commitizen_python_api_programmatic_commit_message_generation.py
1from commitizen import api
2
3# Initialize the commitizen logic (defaults to cz_conventional_commits)
4cz = api.get_cz()
5
6# Define the answers for the commit prompts
7answers = {
8    "prefix": "feat",
9    "subject": "add python api support",
10    "body": "This allows users to use commitizen as a library.",
11    "is_breaking_change": False,
12    "footer": "Refs: #123"
13}
14
15# Generate the commit message
16message = cz.message(answers)
17
18print(message)
19# Output: feat: add python api support
20# 
21# This allows users to use commitizen as a library.
22# 
23# Refs: #123