Created
May 5, 2022 09:49
-
-
Save jsenin/0a53b0d6bd30a8ba65e267d01005f36e to your computer and use it in GitHub Desktop.
script for finding versio releases in java code, build a changelog and launch tags to git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from pydriller import Repository | |
def extract_version(content): | |
regex = r"<artifactId>myapp<\/artifactId>.*\n^\-.*<version>(.*)<\/version>.*\n^\+.*<version>(.*)<\/version>" | |
matches = re.findall(regex, content, re.MULTILINE) | |
if matches: | |
return matches[0][0], matches[0][1] | |
return None, None | |
def run(): | |
for commit in Repository('.').traverse_commits(): | |
# print(commit.hash, [message for message in commit.msg.split("\n")][0]) | |
for file in commit.modified_files: | |
if 'pom' in file.filename: | |
if '<artifactId>myapp</artifactId>' in file.diff: | |
prev, new = extract_version(file.diff) | |
if new: | |
#print ("Bump version from ", prev , "-->", new, commit.hash, "\n") | |
version = new | |
hash = commit.hash | |
print(f"git tag -a {version} {hash} -m \"Release version {version}\"") | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment