是否可以使用mercurial python库从提交ID获取文件更改信息?
我在Rhodecode CI中实现了一个自定义钩子,它在每次推送时都向Buildbot发送一个构建请求。钩子为我提供了修订提交id,如何提取作为提交一部分更改的文件的信息是否可以使用mercurial python库从提交ID获取文件更改信息?,mercurial,buildbot,mercurial-hook,rhodecode,Mercurial,Buildbot,Mercurial Hook,Rhodecode,我在Rhodecode CI中实现了一个自定义钩子,它在每次推送时都向Buildbot发送一个构建请求。钩子为我提供了修订提交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?
@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获取此信息?与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
含汞:
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
使用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
含汞:
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