#!/usr/bin/env python3
|
# -*- coding: utf-8 -*-
|
|
##### To Do #####
|
# - handle different keywords/types (what to process/ignore?)
|
# - recognize tags
|
# - sort by tags
|
# - scopes
|
|
import os
|
|
# a multidimensional list containing the Changelog
|
log = []
|
# a multidimensional list containing all commits separated by lines
|
commitHistory = []
|
# a list of keywords used in the default conventional git (https://www.conventionalcommits.org/en/v1.0.0/)
|
# may later get converted into a dict
|
keywords = ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
|
|
# get the formatted output from git log with additional delimiter for easier splitting
|
stream = os.popen("git log --format=%B%H----DELIMITER----")
|
output = stream.read()
|
output = output.split("----DELIMITER----")
|
del output[-1]
|
|
# compute every commit
|
for commit in output:
|
# seperate lines
|
wholeCommit = commit.split("\n")
|
# delete empty strings
|
commit = [x for x in wholeCommit if x]
|
# delete long commit message
|
if len(commit) == 3:
|
del commit[1]
|
# put commit into list
|
commitHistory.append(commit)
|
|
# handle commit types (work in progress)
|
# variant a
|
if commit[0].startswith("feat"):
|
print("Feature recognized!")
|
elif commit[0].startswith("chore"):
|
print("Chore recognized!")
|
# variant b
|
for i in keywords:
|
if commit[0].startswith(i):
|
print(i)
|
|
|
|
# write into logfile for test purpose
|
with open("log.txt", "w") as file:
|
for commit in commitHistory:
|
for line in commit:
|
file.write(line)
|
file.write("\n")
|