From c3e3b0800a174b565ca4426bd74f8d707b3b1dfb Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Wed, 26 May 2021 21:13:28 +0200 Subject: [PATCH] Moved logic to own function Allows importing from another file --- latest-tags.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/latest-tags.py b/latest-tags.py index 05fdb6f..3da55d7 100755 --- a/latest-tags.py +++ b/latest-tags.py @@ -20,13 +20,7 @@ import subprocess - -def main(): - # # TODO: Add user defined keywords to the list. - # ignored_keywords = ["pre", "rc", "beta", "alpha", "dev"] - # # TODO: Add a ability for the user to customize this. - # default_branch = "main" - +def sorted_tags(): # Retrieve all tags in the repo (that are fetched...) tags = subprocess.run(["git", "tag"], stdout=subprocess.PIPE) allowedTags = {} @@ -39,12 +33,20 @@ def main(): # Strip away the encloding quotes as well as some whitespace allowedTags[tag] = date.stdout.decode('utf-8').strip(" \n'") # Sort by keys, which are the retrieved timestampes - allowedTags = sorted(allowedTags.items(), key=lambda item: item[1]) + return sorted(allowedTags.items(), key=lambda item: item[1]) + +def main(): + # # TODO: Add user defined keywords to the list. + # ignored_keywords = ["pre", "rc", "beta", "alpha", "dev"] + # # TODO: Add a ability for the user to customize this. + # default_branch = "main" + + tags = sorted_tags() # Printing out - for k,v in allowedTags: + for k,_ in tags: print(k) - print("Latest tag: {}\nSecond latest tag: {}".format(allowedTags[-1][0],allowedTags[-2][0])) + print("Latest tag: {}\nSecond latest tag: {}".format(tags[-1][0],tags[-2][0])) if __name__ == "__main__":