Add commit listing
parent
c403668209
commit
ee300b846b
|
@ -2562,6 +2562,74 @@ def git_get_branches(repo):
|
|||
"branches": branches
|
||||
}
|
||||
|
||||
@app.route("/ogrepository/v1/git/repositories/<string:repo>/branches/<string:branch>/commits", methods=['GET'])
|
||||
def git_get_commits(repo, branch):
|
||||
"""
|
||||
Retrieve the list of commits in a branch in a given repository.
|
||||
|
||||
Args:
|
||||
repo (str): The name of the repository.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response containing a list of commits
|
||||
- 200: A JSON object with a "branches" key containing a list of branch names.
|
||||
- 404: A JSON object with an "error" key containing the message "Repository not found" if the repository does not exist.
|
||||
"""
|
||||
repo_path = os.path.join(REPOSITORIES_BASE_PATH, OGGIT_USER, repo + ".git")
|
||||
if not os.path.isdir(repo_path):
|
||||
journal.send(f"Can't list repositories. Repository storage at {REPOSITORIES_BASE_PATH} not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return jsonify({"error": "Repository not found"}), 404
|
||||
|
||||
|
||||
max_commits = request.args.get('max_commits') or 100
|
||||
skip_commits = request.args.get('skip') or 0
|
||||
|
||||
|
||||
git_repo = git.Repo(repo_path)
|
||||
git_repo.git.config('--global', '--add', 'safe.directory', repo_path)
|
||||
|
||||
|
||||
if not branch in git_repo.branches:
|
||||
journal.send(f"Branch {branch} not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return jsonify({"error": "Branch not found"}), 404
|
||||
|
||||
|
||||
# Lookup table for hash/tag
|
||||
hash_to_tag = {}
|
||||
for tag in git_repo.tags:
|
||||
sha = tag.commit.hexsha
|
||||
if not sha in hash_to_tag:
|
||||
hash_to_tag[sha] = []
|
||||
|
||||
hash_to_tag[sha] = hash_to_tag[sha] + [ tag.name ]
|
||||
|
||||
|
||||
commits = []
|
||||
for com in git_repo.iter_commits(branch, max_count = max_commits, skip = skip_commits):
|
||||
tag_list = []
|
||||
|
||||
if com.hexsha in hash_to_tag:
|
||||
tag_list = hash_to_tag[com.hexsha]
|
||||
|
||||
|
||||
commits = commits + [
|
||||
{
|
||||
"hexsha" : com.hexsha,
|
||||
"message" : com.message,
|
||||
"committed_date" : com.committed_date,
|
||||
"tags" : tag_list,
|
||||
"size" : com.size,
|
||||
"stats_total" : com.stats.total
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
journal.send(f"Returning {len(commits)} commits", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return {
|
||||
"commits": commits
|
||||
}
|
||||
|
||||
|
||||
@app.route("/ogrepository/v1/git/repositories/<string:repo>/branches", methods=['POST'])
|
||||
def git_create_branch(repo):
|
||||
"""Create a given branch in a given repository
|
||||
|
|
|
@ -2266,6 +2266,96 @@ paths:
|
|||
exception:
|
||||
type: string
|
||||
example: "(Exception description)"
|
||||
/ogrepository/v1/git/repositories/{repository}/branches/{branch}/commits:
|
||||
get:
|
||||
summary: "Obtener lista de commits en una rama"
|
||||
description: |
|
||||
Devuelve una lista de commits de Git
|
||||
tags:
|
||||
- "Git"
|
||||
parameters:
|
||||
- name: repository
|
||||
in: path
|
||||
required: true
|
||||
type: string
|
||||
description: "Nombre de repositorio"
|
||||
- name: branch
|
||||
in: path
|
||||
required: true
|
||||
type: string
|
||||
description: "Rama dentro del repositorio"
|
||||
- name: max_commits
|
||||
in: query
|
||||
required: false
|
||||
type: int
|
||||
description: "Máximo de commits a obtener"
|
||||
- name: skip
|
||||
in: query
|
||||
required: false
|
||||
type: int
|
||||
description: "Commits a saltar (para paginación)"
|
||||
responses:
|
||||
"200":
|
||||
description: "Lista de commits"
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
commits:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
committed_date:
|
||||
type: int
|
||||
example: 1745360193
|
||||
hexsha:
|
||||
type: string
|
||||
example: "db8e84d5d2548f589ee503c1c6d5003cc6a0d803"
|
||||
message:
|
||||
type: string
|
||||
example: "Install updates"
|
||||
size:
|
||||
type: int
|
||||
example: 67108864
|
||||
tags:
|
||||
type: array
|
||||
example: ["updates"]
|
||||
stats_total:
|
||||
type: object
|
||||
properties:
|
||||
deletion:
|
||||
type: int
|
||||
example: 0
|
||||
files:
|
||||
type: int
|
||||
example: 1
|
||||
insertions:
|
||||
type: int
|
||||
example: 1
|
||||
lines:
|
||||
type: int
|
||||
example: 100
|
||||
|
||||
"500":
|
||||
description: "Excepción"
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
example: false
|
||||
exception:
|
||||
type: string
|
||||
example: "(Exception description)"
|
||||
"404":
|
||||
description: "El repositorio o branch no existe"
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: string
|
||||
example: "Repository not found"
|
||||
|
||||
/ogrepository/v1/git/repositories/{repository}/branches:
|
||||
get:
|
||||
summary: "Obtener lista de branches"
|
||||
|
|
Loading…
Reference in New Issue