Skip to content

Instantly share code, notes, and snippets.

@jsenin
Created May 5, 2022 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsenin/0a53b0d6bd30a8ba65e267d01005f36e to your computer and use it in GitHub Desktop.
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
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