Created
September 24, 2015 04:30
-
-
Save atmb4u/ebab278291d5558a39e6 to your computer and use it in GitHub Desktop.
version info for django projects with git
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
#add this to your urls file | |
url(r'^version/$', 'api.views.code_version', name='code_version'), |
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
#add this view to your views.py file | |
def code_version(request): | |
""" | |
:param request: django request | |
:return: returns total commit counts as version | |
""" | |
try: | |
commit_count = int( | |
subprocess.Popen("git rev-list HEAD --count", | |
shell=True, stdout=subprocess.PIPE).stdout.read()) | |
return HttpResponse("v%s" % commit_count) | |
except: | |
return HttpResponse("None") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment