我正在Rhodecode CI中实现自定义挂钩,该挂钩在每次推送时都会向Buildbot发送构建请求。该钩子为我提供了修订版本的commit-id,如何提取有关在此提交过程中更改的文件的信息。
@has_kwargs({
'commit_ids': 'list of pushed commit_ids (sha1)',})
def _push_hook(*args, **kwargs):
import mercurial # can I used this library to get this info?
some_function(commit_id) # should return files changed
我可以使用mercurial
库还是使用python以编程方式获取此信息的其他方法吗?
答案 0 :(得分:0)
使用rhodecode:
from rhodecode.model.db import Repository
from rhodecode.api.utils import build_commit_data, Optional
class Commit:
def __init__(self, repo_name, commit_id):
self._commit_id = commit_id
repo = Repository.get_by_repo_name(repo_name)
self.vcs_repo = repo.scm_instance(cache=False)
def files_changed(self):
changeset_details = self._changeset_details(self._commit_id)
files_changed_ = [diff.get("filename") for diff in changeset_details["diff"]]
return files_changed_
def _changeset_details(self, commit_id):
pre_load = ['author', 'branch', 'date', 'message', 'parents',
'status', '_commit', '_file_paths']
changes_details = Optional.extract("full")
changeset = self.vcs_repo.get_changeset(commit_id, pre_load=pre_load)
changeset_data = changeset.__json__()
changeset_data['diff'] = build_commit_data(changeset, changes_details)
return changeset_data
使用HG:
from mercurial import ui, hg
hg_repo = hg.repository(ui.ui(), repo_path)
node = hg_repo.changelog.node(revision)
log = hg_repo.changelog.read(node)
manifest, user, (time, timezone), files_changed, desc, extra = log