From 8c3b1c8c9550c9fec9a82a9afa1c4670fcf42e07 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 28 Jul 2018 14:48:03 +0100 Subject: [PATCH] Add commit hash to releases --- app/models.py | 1 + app/tasks/importtasks.py | 10 +++++---- app/templates/packages/release_edit.html | 4 ++++ app/templates/packages/view.html | 3 ++- migrations/versions/44e138485931_.py | 28 ++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 migrations/versions/44e138485931_.py diff --git a/app/models.py b/app/models.py index 0452009f..281867c6 100644 --- a/app/models.py +++ b/app/models.py @@ -591,6 +591,7 @@ class PackageRelease(db.Model): url = db.Column(db.String(200), nullable=False) approved = db.Column(db.Boolean, nullable=False, default=False) task_id = db.Column(db.String(37), nullable=True) + commit_hash = db.Column(db.String(41), nullable=True, default=None) def getEditURL(self): diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index 18ce2e6a..9afc8b69 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -344,9 +344,10 @@ def makeVCSReleaseFromGithub(id, branch, release, url): if len(commits) == 0 or not "sha" in commits[0]: raise TaskError("No commits found") - release.url = urlmaker.getCommitDownload(commits[0]["sha"]) + release.url = urlmaker.getCommitDownload(commits[0]["sha"]) + release.task_id = None + release.commit_hash = commits[0]["sha"] print(release.url) - release.task_id = None db.session.commit() return release.url @@ -374,9 +375,10 @@ def makeVCSRelease(id, branch): with open(destPath, "wb") as fp: repo.archive(fp, format="zip") - release.url = "/uploads/" + filename + release.url = "/uploads/" + filename + release.task_id = None + release.commit_hash = repo.head.object.hexsha print(release.url) - release.task_id = None db.session.commit() return release.url diff --git a/app/templates/packages/release_edit.html b/app/templates/packages/release_edit.html index a201a38b..faa475eb 100644 --- a/app/templates/packages/release_edit.html +++ b/app/templates/packages/release_edit.html @@ -21,6 +21,10 @@ Url: {{ release.url }}
{% endif %} + {% if release.commit_hash %} + Commit Hash: {{ release.commit_hash }}
+ {% endif %} + {% if release.task_id %} Importing... view task
{% if package.checkPerm(current_user, "CHANGE_RELEASE_URL") %} diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html index b118046e..181ae998 100644 --- a/app/templates/packages/view.html +++ b/app/templates/packages/view.html @@ -188,7 +188,8 @@
  • {% if not rel.approved %}{% endif %} - {{ rel.title }}, + {{ rel.title }}{% if rel.commit_hash %} + [{{ rel.commit_hash | truncate(5, end='') }}]{% endif %}, created {{ rel.releaseDate | datetime }}. {% if rel.task_id %} Importing... diff --git a/migrations/versions/44e138485931_.py b/migrations/versions/44e138485931_.py new file mode 100644 index 00000000..a865777e --- /dev/null +++ b/migrations/versions/44e138485931_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: 44e138485931 +Revises: 9e2ac631efb0 +Create Date: 2018-07-28 14:45:28.879331 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '44e138485931' +down_revision = '9e2ac631efb0' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('package_release', sa.Column('commit_hash', sa.String(length=41), nullable=True, server_default=None)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('package_release', 'commit_hash') + # ### end Alembic commands ###