Compare commits
3 Commits
2c869ea524
...
52fd7d8064
Author | SHA1 | Date |
---|---|---|
|
52fd7d8064 | |
|
25877533e8 | |
|
f2a90ce574 |
|
@ -60,6 +60,7 @@ import sys
|
|||
import git
|
||||
import pkgutil
|
||||
import importlib
|
||||
import paramiko
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------------------------
|
||||
|
@ -2254,6 +2255,31 @@ def git_sync_repository_task(repo, remote_repository, job_id):
|
|||
journal.send(f"Calling function 'recall_ogcore' (JOB_ID: {job_id}, SUCCESS: True)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
recall_ogcore(data)
|
||||
|
||||
def git_backup_repository_task(repo, params, job_id):
|
||||
journal.send("Running function 'git_sync_repository_task'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
|
||||
git_repo_path = os.path.join(REPOSITORIES_BASE_PATH, repo + ".git")
|
||||
git_repo = git.Repo(git_repo_path)
|
||||
git_repo.git.config('--global', '--add', 'safe.directory', git_repo_path)
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
ssh.connect(params["ssh_server"], params["ssh_port"], params["ssh_user"])
|
||||
sftp = ssh.open_sftp()
|
||||
|
||||
with sftp.file(params["filename"], mode='wb+') as remote_file:
|
||||
git_repo.archive(remote_file, format="tar.gz")
|
||||
|
||||
data = {
|
||||
'job_id': job_id,
|
||||
'success': True,
|
||||
}
|
||||
|
||||
journal.send(f"Calling function 'recall_ogcore' (JOB_ID: {job_id}, SUCCESS: True)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
recall_ogcore(data)
|
||||
|
||||
|
||||
|
||||
@app.route("/ogrepository/v1/git/repositories", methods=['GET'])
|
||||
def git_list_repositories():
|
||||
|
@ -2404,7 +2430,45 @@ def git_sync_repository(repo):
|
|||
|
||||
@app.route("/ogrepository/v1/git/repositories/<string:repo>/backup", methods=['POST'])
|
||||
def git_backup_repository(repo):
|
||||
return jsonify({"error" : "Not implemented"}), 500
|
||||
journal.send("Running endpoint 'Backup de repositorio Git'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
|
||||
if not os.path.isdir(REPOSITORIES_BASE_PATH):
|
||||
journal.send(f"Can't backup repositories. Repository storage at {REPOSITORIES_BASE_PATH} not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return jsonify({"error": "Repository storage not found, git functionality may not be installed."}), 500
|
||||
|
||||
data = request.json
|
||||
|
||||
if data is None:
|
||||
journal.send(f"Can't backup repository, JSON post data missing", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return jsonify({"error" : "Parameters missing"}), 400
|
||||
|
||||
if not "ssh_server" in data:
|
||||
journal.send(f"Can't sync repository, JSON ssh_server parameter missing", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return jsonify({"error" : "Parameters missing"}), 400
|
||||
|
||||
if not "ssh_port" in data:
|
||||
journal.send(f"Can't sync repository, JSON ssh_port parameter missing", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return jsonify({"error" : "Parameters missing"}), 400
|
||||
|
||||
if not "ssh_user" in data:
|
||||
journal.send(f"Can't sync repository, JSON ssh_user parameter missing", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return jsonify({"error" : "Parameters missing"}), 400
|
||||
|
||||
if not "filename" in data:
|
||||
journal.send(f"Can't sync repository, JSON filename parameter missing", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return jsonify({"error" : "Parameters missing"}), 400
|
||||
|
||||
|
||||
job_id = f"GitBackup_{''.join(random.choice('0123456789abcdef') for char in range(8))}"
|
||||
|
||||
threading.Thread(target=git_backup_repository_task, args=(repo, data, job_id,)).start()
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"output": "Backing up...",
|
||||
"job_id": job_id
|
||||
}), 200
|
||||
|
||||
|
||||
@app.route("/ogrepository/v1/git/repositories/<string:repo>/compact", methods=['POST'])
|
||||
def git_compact_repository(repo):
|
||||
|
@ -2552,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 {
|
||||
|
@ -2591,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
|
||||
|
|
|
@ -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:
|
||||
name:
|
||||
commit:
|
||||
type: string
|
||||
example: HEAD
|
||||
required: True
|
||||
message:
|
||||
type: string
|
||||
example: Version 1.0
|
||||
required: False
|
||||
responses:
|
||||
"201":
|
||||
description: "Tag creado"
|
||||
|
@ -2254,7 +2288,7 @@ paths:
|
|||
schema:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
commit:
|
||||
type: string
|
||||
example: HEAD
|
||||
responses:
|
||||
|
|
Loading…
Reference in New Issue