From 52fd7d8064ebe4e9744513fcd95bc69989461387 Mon Sep 17 00:00:00 2001 From: Vadim Troshchinskiy Date: Fri, 9 May 2025 13:33:00 +0200 Subject: [PATCH] Use annotated tags --- api/repo_api.py | 21 +++++++++++++++++++-- api/swagger.yaml | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/api/repo_api.py b/api/repo_api.py index b636e15..5591527 100644 --- a/api/repo_api.py +++ b/api/repo_api.py @@ -2616,7 +2616,20 @@ def git_list_tags(repo): tags = [] for tag in git_repo.tags: - tags = tags + [tag.name] + tag_info = { + "name" : tag.name, + "commit" : tag.commit.hexsha, + "committer" : tag.commit.committer.name, + "committed_datetime" : tag.commit.committed_datetime.timestamp() + } + + if not tag.tag is None: + tag_info["message"] = tag.tag.message + tag_info["tagged_date"] = tag.tag.tagged_date + tag_info["tagger"] = tag.tag.tagger.name + tag_info["tagger_tz_offset"] = tag.tag.tagger_tz_offset + + tags = tags + [ tag_info ] journal.send(f"Returning {len(tags)} branches", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") return { @@ -2655,11 +2668,15 @@ def git_create_tag(repo, tag): journal.send(f"Can't create tag. Commit parameter missing", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") return jsonify({"error" : "commit parameter missing"}), 400 + commit_message = "" + if "message" in data: + commit_message = data["message"] + if tag in git_repo.tags: journal.send(f"Can't create tag. Already found in repository {repo}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") return jsonify({"error": "Tag already exists"}), 409 - git_repo.create_tag(tag, ref = data["commit"]) + git_repo.create_tag(tag, ref = data["commit"], message = commit_message) journal.send(f"Tag {tag} created in repo {repo}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") return jsonify({"status": "created"}), 200 diff --git a/api/swagger.yaml b/api/swagger.yaml index 9e7d057..f79b0e6 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -2058,8 +2058,36 @@ paths: tags: type: array items: - type: string - example: v0.1 + type: object + properties: + name: + type: string + example: v0.1 + commit: + type: string + example: db8e84d5d2548f589ee503c1c6d5003cc6a0d803 + committer: + type: string + example: John Smith + committed_datetime: + type: int + example: 1745360193 + message: + type: string + example: "Initial release" + required: False + tagged_date: + type: int + example: 1745360194 + required: False + tagger: + type: string + example: John Smith + required: False + tagger_tz_offset: + type: int + example: -7200 + required: False "500": description: "Excepción" @@ -2095,12 +2123,18 @@ paths: required: true description: | * **commit** - Commit al que apunta el tag nuevo. Puede ser un nombre de otra rama/tag. + * **message** - Mensaje descriptivo para el tag. Opcional, si no se especifica se asume una cadena vacía. schema: type: object properties: commit: type: string example: HEAD + required: True + message: + type: string + example: Version 1.0 + required: False responses: "201": description: "Tag creado"