我使用 Gerrit API (/changes/64/revisions/current/files/my_file/content) 访问文件内容。有什么方法可以获取该文件的“基本”内容,即更改所基于的内容?
我尝试过使用
/更改/64/修订/0/文件/my_file/内容
但运气不好。有什么想法吗?
也许使用 get-diff API,从那里你可以导出原始文件内容
Gerrit 应该对此有原生支持......
但这里是如何欺骗它在 python 中返回任何给定 {tag,branch,commit} 处的任何文件:
# pip install python-gerrit-api
from gerrit import GerritClient
import base64
client = GerritClient(
base_url=url,
username=username,
password=password
)
# `project` is project name
# `version` is tag/branch/commit
# `path` is path to a file, relative to project root
b64 = client.gitiles.gerrit.get(client.gitiles.endpoint+ f"/{project}/+/{version}/{path}", params={"format": "TEXT"})
content = base64.b64decode(b64)
您可以使用“GET /projects/{project-name}/commits/{commit-id}/files/{file-id}/content”
参见: https://gerrit.sio2project.mimuw.edu.pl/Documentation/rest-api-projects.html#get-content-from-commit