Commit c49b31b3 authored by Pietro Albini's avatar Pietro Albini

Show the commit hash (with a link) of a branch

parent 3af66a35
......@@ -21,7 +21,7 @@ import shutil
import json
BRANCH_DIR_VERSION = "2"
BRANCH_DIR_VERSION = "3"
class Branch:
......@@ -82,7 +82,7 @@ class Branch:
return False
# All the files must be be present
files = ["version", "config.json"]
files = ["version", "commit", "config.json"]
for file in files:
file = root / file
if not (file.exists() and file.is_file()):
......@@ -130,6 +130,28 @@ class Branch:
with file.open() as f:
self.config = json.load(f)
def commit(self):
"""Load the commit of this branch"""
file = self.manager.root / "branches" / self.name / "commit"
if file.exists():
with file.open() as f:
return f.read().strip()
else:
return ""
def commit_url(self):
"""Get the URL of a commit"""
commit = self.commit()
if not commit:
return None
return "%s/%s/commit/%s" % (
self.manager.config["gitlab-url"],
self.manager.config["gitlab-project"],
commit,
)
def exec_command(self, raw_command, replaces=None, build=False):
"""Exec a command in the context of the branch"""
args, kwargs = self.command_popen_args(raw_command, replaces, build)
......@@ -212,6 +234,13 @@ class Branch:
"checkout", "-f", self.name,
], stdout=log_file.open("a"), stderr=subprocess.STDOUT)
# Get the commit of the branch
commit_file = branch / "commit"
subprocess.call(
["git", "--git-dir", git_dir, "rev-parse", self.name],
stdout=commit_file.open("w"), stderr=log_file.open("a"),
)
# Copy and load the configuration file
if not (build_dir / "managetests.json").exists():
log("[!] No managetests.json found in the branch!")
......
......@@ -61,7 +61,14 @@
<a href="{{ branch.mr_url }}">!{{ branch.mr_id }}</a>
</td>
{% endif %}
<td>-</td>
<td>
{% set commit = branch.commit() %}
{% if not commit %}-{% else %}
<a href="{{ branch.commit_url() }}">
{{ commit[:7] }}
</a>
{% endif %}
</td>
<td>
{% if branch.has_build_log() %}
<a href="{{ url_for("build_log", branch=branch.name) }}">Build log</a> {% endif %}
......@@ -101,6 +108,18 @@
</ul>
{% endif %}
{% set commit = branch.commit() %}
{% if commit %}
<ul class="inline">
<li>
Commit corrente:
<a href="{{ branch.commit_url() }}">
{{ commit[:7] }}
</a>
</li>
</ul>
{% endif %}
<ul class="inline">
{% if branch.has_build_log() %}
<li><a href="{{ url_for("build_log", branch=branch.name) }}">Build log</a></a>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment