Created
April 11, 2019 06:59
-
-
Save aviadlevy/175e533f58abe913eb70a162b595f5e0 to your computer and use it in GitHub Desktop.
print changes between 2 last tags
This file contains hidden or 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 subprocess | |
import sys | |
def git(*args): | |
""" | |
:param args: the parameters for the git command | |
:return: the result of the git command as string | |
""" | |
return subprocess.check_output(["git"] + list(args)).decode().strip() | |
def get_latest_tags(): | |
""" | |
:return: latest 2 tags | |
""" | |
git1 = git("tag", "--sort=-version:refname").split("\n")[:2] | |
return git1 | |
def get_filtered_commits_rules(line): | |
""" | |
:param line the commit message we're checking if we need to filter | |
:return true iff we want to include line in notify message | |
""" | |
return not line.startswith("- Merge") | |
def get_commits_messages(old, new, format_of_commit="%H %s"): | |
""" | |
:param old: old tag | |
:param new: new tag | |
:param format_of_commit: format for commit message. see here: https://git-scm.com/docs/pretty-formats | |
:return: the commit messages between the tags in the specified format | |
""" | |
commit_msg = git("log", ("--pretty=format:" + format_of_commit), old + "..." + new) | |
commit_msg = "\n".join([line for line in commit_msg.split("\n") if get_filtered_commits_rules(line)]) | |
return commit_msg | |
def main(): | |
new, old = get_latest_tags() | |
msg = get_commits_messages(old.strip(), new.strip(), "• %s") | |
print(msg) | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment