From e0b9a036ca96f55a74e390bf6e645ff5e912a90e Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Thu, 18 Sep 2025 13:52:34 +0200 Subject: [PATCH] refs #2830 create tags via a query to the forgejo API --- CHANGELOG.md | 21 ++++++++++++++++----- api/repo_api.py | 35 ++++++++++++++--------------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a996426..2fdc09a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,22 @@ # Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.10.3] - 2025-09-18 + +### Changed + +- Create tags via a query to the forgejo API + ## [0.10.2] - 2025-09-01 -## Fixed +### Fixed -- Corregida la logica en el endpoint create torrent sum -- Mejoras en los mensajes de logs +- Corregida la logica en el endpoint create torrent sum +- Mejoras en los mensajes de logs - Mejoras en la validación de los archivos info e info.checked ## [0.10.1] - 2025-08-25 @@ -21,13 +32,13 @@ - OgGit functionality (#2371, #2363, #2363, #2317) -### Removed +### Removed - Removed unused BitTorrent-related packages and logic ## [0.9.0] - 2025-06-25 -## Added +### Added - Changed old tools for tools non dependant of Pyhton2 in repo - mktorrent to handle creation of torrent files diff --git a/api/repo_api.py b/api/repo_api.py index 2b4ca96..16a80c6 100644 --- a/api/repo_api.py +++ b/api/repo_api.py @@ -2301,6 +2301,12 @@ def git_forgejo_create_repo(repo): "private" : False }) +def git_forgejo_create_tag(repo,tag,msg,target): + return git_forgejo_post_command(f"/api/v1/repos/oggit/{repo}/tags", { + "message": msg, + "tag_name": tag, + "target": target + }) def git_forgejo_add_sshkey(pubkey, description = ""): return git_forgejo_post_command("/api/v1/user/keys", @@ -2818,14 +2824,6 @@ def git_create_tag(repo): - 409: A JSON object with an "error" key containing the message "Tag already exists" """ - repo_path = os.path.join(REPOSITORIES_BASE_PATH, OGGIT_USER, repo + ".git") - if not os.path.isdir(repo_path): - journal.send(f"Can't create tag. Repository storage at {REPOSITORIES_BASE_PATH} not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - return jsonify({"error": "Repository not found"}), 404 - - git_repo = git.Repo(repo_path) - git_repo.git.config('--global', '--add', 'safe.directory', repo_path) - data = request.json if data is None: journal.send(f"Can't create tag. JSON post data missing", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") @@ -2845,21 +2843,16 @@ def git_create_tag(repo): 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 - try: - git_repo.create_tag(tag, ref = data["commit"], message = commit_message) - except git.exc.GitCommandError as ge: - if "not a valid tag name" in ge.stderr: - journal.send(f"Tag name {tag} is invalid", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - return jsonify({"error" : "Invalid tag name"}), 400 - else: - journal.send(f"Git error {ge}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - return jsonify({"error" : "Error when performing git command"}), 500 - + res = git_forgejo_create_tag(repo,tag,commit_message,data["commit"]) + except Exception as e: + journal.send (str(e), PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + return jsonify({"error" : f"git_forgejo_create_tag failed: {e}"}), 500 + if 200 != res[0]: + j = json.loads(res[1]) + journal.send (j["message"], PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + return jsonify({"error" : j["message"]}), 409 journal.send(f"Tag {tag} created in repo {repo}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") return jsonify({"status": "created"}), 200 -- 2.40.1