Skip to content

Instantly share code, notes, and snippets.

@nebil
Last active February 11, 2020 11:10
Show Gist options
  • Save nebil/b4c469580f2667762a3adda97adb4d9a to your computer and use it in GitHub Desktop.
Save nebil/b4c469580f2667762a3adda97adb4d9a to your computer and use it in GitHub Desktop.
📦 releasetype -- a function to get the release type of a version
"""
releasetype.py -- a function to get the release type of a version
This source code is licensed under a Creative Commons CC0 license.
More info at <https://creativecommons.org/publicdomain/zero/1.0/>.
"""
def get_release_type(version):
"""
>>> get_release_type('3.1.4')
'patch'
>>> get_release_type('4.2.0')
'minor'
>>> get_release_type('5.0.0')
'major'
"""
# NOTE: I think this is an elegant implementation.
major, minor, patch = map(int, version.split("."))
if patch: return "patch"
if minor: return "minor"
if major: return "major"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment