Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display full commit in the version displayed in the UI #88 #91

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$Format:%(describe:tags)$
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Release notes
- Fix the logout link of the admin app.
https://github.com/nexB/dejacode/issues/89

- Display full commit in the version displayed in the UI
https://github.com/nexB/dejacode/issues/88

### Version 5.0.1

- Improve the stability of the "Check for new Package versions" feature.
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ RUN apt-get update \
libldap2-dev \
libsasl2-dev \
libpq5 \
git \
wait-for-it \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Expand Down
57 changes: 56 additions & 1 deletion dejacode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,64 @@
import os
import sys
import warnings
from contextlib import suppress
from pathlib import Path

import git

VERSION = "5.1.0-dev"
__version__ = VERSION

PROJECT_DIR = Path(__file__).resolve().parent
ROOT_DIR = PROJECT_DIR.parent


def get_version(version):
"""Return the version including the git describe tag when available."""
# The codebase is a git clone
if git_describe := get_git_describe_from_local_checkout():
return git_describe

# The codebase is an extracted git archive
if git_describe := get_git_describe_from_version_file():
return git_describe

return version


def get_git_describe_from_local_checkout():
"""
Return the git describe tag from the local checkout.
This will only provide a result when the codebase is a git clone.
"""
with suppress(git.GitError):
return git.Repo(".").git.describe(tags=True, always=True)


def get_git_describe_from_version_file(version_file_location=ROOT_DIR / ".VERSION"):
"""
Return the git describe tag from the ".VERSION" file.
This will only provide a result when the codebase is an extracted git archive
"""
try:
version = version_file_location.read_text().strip()
except (FileNotFoundError, UnicodeDecodeError):
return

if version and version.startswith("v"):
return version


def extract_short_commit(git_describe):
"""
Extract the short commit hash from a Git describe string while removing
any leading "g" character if present.
"""
short_commit = git_describe.split("-")[-1]
return short_commit.lstrip("g")


__version__ = get_version(VERSION)


# Turn off the warnings for the following modules.
warnings.filterwarnings("ignore", module="cyclonedx")
Expand Down
2 changes: 1 addition & 1 deletion dje/templates/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a class="dropdown-item" href="https://github.com/nexB/dejacode/releases" target="_blank" rel="noreferrer">{% trans 'Releases' %}</a>
<a class="dropdown-item" href="https://scancode-licensedb.aboutcode.org/agpl-3.0.html" target="_blank" rel="noreferrer">{% trans 'License' %}</a>
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">DejaCode: v{{ DEJACODE_VERSION }}</h6>
<h6 class="dropdown-header">{{ DEJACODE_VERSION }}</h6>
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion dje/templates/includes/navbar_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
</a>
{% endif %}
<div class="dropdown-divider"></div>
<div class="dropdown-header">DejaCode: v{{ DEJACODE_VERSION }}</div>
<div class="dropdown-header">{{ DEJACODE_VERSION }}</div>
<div class="dropdown-divider"></div>
<form id="logout-form" method="post" action="{% url 'logout' %}">
{% csrf_token %}
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ install_requires =
sortedcontainers==2.4.0
toml==0.10.2
py-serializable==1.0.3
# Git
gitpython==3.1.43
gitdb==4.0.11
smmap==5.0.1

[options.extras_require]
dev =
Expand Down
Binary file not shown.
Binary file added thirdparty/dist/gitdb-4.0.11-py3-none-any.whl
Binary file not shown.
Binary file added thirdparty/dist/smmap-5.0.1-py3-none-any.whl
Binary file not shown.