本文整理汇总了Python中changes.utils.diff_parser.DiffParser.get_changed_files方法的典型用法代码示例。如果您正苦于以下问题:Python DiffParser.get_changed_files方法的具体用法?Python DiffParser.get_changed_files怎么用?Python DiffParser.get_changed_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类changes.utils.diff_parser.DiffParser
的用法示例。
在下文中一共展示了DiffParser.get_changed_files方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_changed_files_simple_diff
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def test_get_changed_files_simple_diff(self):
parser = DiffParser(SIMPLE_DIFF)
files = parser.get_changed_files()
assert files == set([
'changes/utils/diff_parser.py',
])
lines_by_file = parser.get_lines_by_file()
assert lines_by_file == {'changes/utils/diff_parser.py': {74}}
示例2: get_changed_files
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def get_changed_files(self):
vcs = self.repository.get_vcs()
if not vcs:
raise NotImplementedError
diff = vcs.export(self.revision.sha)
diff_parser = DiffParser(diff)
return diff_parser.get_changed_files()
示例3: test_get_changed_files_complex_diff
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def test_get_changed_files_complex_diff(self):
parser = DiffParser(COMPLEX_DIFF)
files = parser.get_changed_files()
assert files == set(["ci/run_with_retries.py", "ci/server-collect", "ci/not-real"])
lines_by_file = parser.get_lines_by_file()
assert set(lines_by_file) == files
assert lines_by_file["ci/not-real"] == {1}
assert lines_by_file["ci/server-collect"] == {24, 31, 39, 46}
assert lines_by_file["ci/run_with_retries.py"] == {2, 45} | set(range(53, 63)) | set(range(185, 192))
示例4: get_changed_files
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def get_changed_files(self, id):
"""Returns the list of files changed in a revision.
Args:
id (str): The id of the revision.
Returns:
A set of filenames
Raises:
UnknownRevision: If the revision wan't found.
"""
diff = self.export(id)
diff_parser = DiffParser(diff)
return diff_parser.get_changed_files()
示例5: test_add_empty_file
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def test_add_empty_file(self):
patch = """diff --git a/diff-from/__init__.py b/diff-from/__init__.py
new file mode 100644
index 0000000..e69de29
"""
parser = DiffParser(patch)
(file_dict,) = parser.parse()
diff = parser.reconstruct_file_diff(file_dict)
assert diff == ""
assert file_dict["old_filename"] is None
assert parser.get_changed_files() == set(["diff-from/__init__.py"])
assert parser.get_lines_by_file() == {}
示例6: test_remove_empty_file
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def test_remove_empty_file(self):
patch = """diff --git a/diff-from/__init__.py b/diff-from/__init__.py
deleted file mode 100644
index e69de29..0000000
"""
parser = DiffParser(patch)
(file_info,) = parser.parse()
diff = parser.reconstruct_file_diff(file_info)
assert diff == ""
assert file_info.new_filename is None
assert parser.get_changed_files() == set(['diff-from/__init__.py'])
assert parser.get_lines_by_file() == {}
示例7: test_add_multiple_empty_files
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def test_add_multiple_empty_files(self):
patch = """diff --git a/diff-from/__init__.py b/diff-from/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/diff-from/other.py b/diff-from/other.py
new file mode 100644
index 0000000..e69de29
"""
parser = DiffParser(patch)
(first_dict, second_dict) = parser.parse()
assert first_dict["new_filename"] == "b/diff-from/__init__.py"
assert first_dict["old_filename"] is None
assert second_dict["new_filename"] == "b/diff-from/other.py"
assert second_dict["old_filename"] is None
assert parser.get_changed_files() == set(["diff-from/__init__.py", "diff-from/other.py"])
assert parser.get_lines_by_file() == {}
示例8: _get_revision_changed_files
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def _get_revision_changed_files(repository, revision):
vcs = repository.get_vcs()
if not vcs:
raise NotImplementedError
try:
diff = vcs.export(revision.sha)
except UnknownRevision:
vcs.update()
try:
diff = vcs.export(revision.sha)
except UnknownRevision:
raise MissingRevision('Unable to find revision %s' % (revision.sha,))
diff_parser = DiffParser(diff)
return diff_parser.get_changed_files()
示例9: test_add_multiple_empty_files
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def test_add_multiple_empty_files(self):
patch = """diff --git a/diff-from/__init__.py b/diff-from/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/diff-from/other.py b/diff-from/other.py
new file mode 100644
index 0000000..e69de29
"""
parser = DiffParser(patch)
(first_info, second_info,) = parser.parse()
assert first_info.new_filename == 'b/diff-from/__init__.py'
assert first_info.old_filename is None
assert second_info.new_filename == 'b/diff-from/other.py'
assert second_info.old_filename is None
assert parser.get_changed_files() == set(['diff-from/__init__.py', 'diff-from/other.py'])
assert parser.get_lines_by_file() == {}
示例10: post
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def post(self, diff_id):
"""
Ask Changes to restart all builds for this diff. The response will be
the list of all builds.
"""
diff = self._get_diff_by_id(diff_id)
if not diff:
return error("Diff with ID %s does not exist." % (diff_id,))
diff_parser = DiffParser(diff.source.patch.diff)
files_changed = diff_parser.get_changed_files()
try:
projects = self._get_projects_for_diff(diff, files_changed)
except InvalidDiffError:
return error('Patch does not apply')
except ProjectConfigError:
return error('Project config is not in a valid format.')
collection_id = uuid.uuid4()
builds = self._get_builds_for_diff(diff)
new_builds = []
for project in projects:
builds_for_project = [x for x in builds if x.project_id == project.id]
if not builds_for_project:
logging.warning('Project with id %s does not have a build.', project.id)
continue
build = max(builds_for_project, key=lambda x: x.number)
if build.status is not Status.finished:
continue
if build.result is Result.passed:
continue
new_build = create_build(
project=project,
collection_id=collection_id,
label=build.label,
target=build.target,
message=build.message,
author=build.author,
source=diff.source,
cause=Cause.retry,
selective_testing_policy=build.selective_testing_policy,
)
new_builds.append(new_build)
return self.respond(new_builds)
示例11: get_changed_files
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def get_changed_files(self):
vcs = self.repository.get_vcs()
if not vcs:
raise NotImplementedError
# Make sure the repo exists on disk.
if not vcs.exists():
vcs.clone()
diff = None
try:
diff = vcs.export(self.revision.sha)
except UnknownRevision:
# Maybe the repo is stale; update.
vcs.update()
# If it doesn't work this time, we have
# a problem. Let the exception escape.
diff = vcs.export(self.revision.sha)
diff_parser = DiffParser(diff)
return diff_parser.get_changed_files()
示例12: test_dev_null_target
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def test_dev_null_target(self):
patch = """diff --git a/whitelist/blacklist/b.txt b/whitelist/blacklist/b.txt
deleted file mode 100644
index 038d718..0000000
--- a/whitelist/blacklist/b.txt
+++ /dev/null
@@ -1 +0,0 @@
-testing
"""
parser = DiffParser(patch)
(file_dict,) = parser.parse()
diff = parser.reconstruct_file_diff(file_dict)
assert diff == """
--- a/whitelist/blacklist/b.txt
+++ /dev/null
@@ -1 +0,0 @@
-testing
"""
assert file_dict['new_filename'] is None
assert parser.get_changed_files() == set(['whitelist/blacklist/b.txt'])
assert parser.get_lines_by_file() == {}
示例13: test_dev_null_source
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def test_dev_null_source(self):
patch = """diff --git a/whitelist/blacklist/a.txt b/whitelist/blacklist/a.txt
new file mode 100644
index 0000000..038d718
--- /dev/null
+++ b/whitelist/blacklist/a.txt
@@ -0,0 +1 @@
+testing
"""
parser = DiffParser(patch)
(file_dict,) = parser.parse()
diff = parser.reconstruct_file_diff(file_dict)
assert diff == """
--- /dev/null
+++ b/whitelist/blacklist/a.txt
@@ -0,0 +1 @@
+testing
"""
assert file_dict['old_filename'] is None
assert parser.get_changed_files() == set(['whitelist/blacklist/a.txt'])
assert parser.get_lines_by_file() == {'whitelist/blacklist/a.txt': {1}}
示例14: post_impl
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
def post_impl(self):
"""
Notify Changes of a newly created diff.
Depending on system configuration, this may create 0 or more new builds,
and the resulting response will be a list of those build objects.
"""
args = self.parser.parse_args()
repository = args.repository
if not args.repository:
return error("Repository not found")
projects = list(Project.query.options(
subqueryload_all('plans'),
).filter(
Project.status == ProjectStatus.active,
Project.repository_id == repository.id,
))
# no projects bound to repository
if not projects:
return self.respond([])
options = dict(
db.session.query(
ProjectOption.project_id, ProjectOption.value
).filter(
ProjectOption.project_id.in_([p.id for p in projects]),
ProjectOption.name.in_([
'phabricator.diff-trigger',
])
)
)
projects = [
p for p in projects
if options.get(p.id, '1') == '1'
]
if not projects:
return self.respond([])
statsreporter.stats().incr('diffs_posted_from_phabricator')
label = args.label[:128]
author = args.author
message = args.message
sha = args.sha
target = 'D{}'.format(args['phabricator.revisionID'])
try:
identify_revision(repository, sha)
except MissingRevision:
# This may just be a broken request (which is why we respond with a 400) but
# it also might indicate Phabricator and Changes being out of sync somehow,
# so we err on the side of caution and log it as an error.
logging.error("Diff %s was posted for an unknown revision (%s, %s)",
target, sha, repository.url)
return error("Unable to find commit %s in %s." % (
sha, repository.url), problems=['sha', 'repository'])
source_data = {
'phabricator.buildTargetPHID': args['phabricator.buildTargetPHID'],
'phabricator.diffID': args['phabricator.diffID'],
'phabricator.revisionID': args['phabricator.revisionID'],
'phabricator.revisionURL': args['phabricator.revisionURL'],
}
patch = Patch(
repository=repository,
parent_revision_sha=sha,
diff=''.join(line.decode('utf-8') for line in args.patch_file),
)
db.session.add(patch)
source = Source(
patch=patch,
repository=repository,
revision_sha=sha,
data=source_data,
)
db.session.add(source)
phabricatordiff = try_create(PhabricatorDiff, {
'diff_id': args['phabricator.diffID'],
'revision_id': args['phabricator.revisionID'],
'url': args['phabricator.revisionURL'],
'source': source,
})
if phabricatordiff is None:
logging.warning("Diff %s, Revision %s already exists",
args['phabricator.diffID'], args['phabricator.revisionID'])
return error("Diff already exists within Changes")
project_options = ProjectOptionsHelper.get_options(projects, ['build.file-whitelist'])
diff_parser = DiffParser(patch.diff)
files_changed = diff_parser.get_changed_files()
collection_id = uuid.uuid4()
#.........这里部分代码省略.........
示例15: post
# 需要导入模块: from changes.utils.diff_parser import DiffParser [as 别名]
# 或者: from changes.utils.diff_parser.DiffParser import get_changed_files [as 别名]
#.........这里部分代码省略.........
else:
patch_file = None
if patch_file:
patch = Patch(
repository=repository,
parent_revision_sha=sha,
diff=patch_file.getvalue(),
)
db.session.add(patch)
else:
patch = None
project_options = ProjectOptionsHelper.get_options(projects, ['build.file-whitelist'])
# mark as commit or diff build
if not patch:
is_commit_build = True
else:
is_commit_build = False
apply_project_files_trigger = args.apply_project_files_trigger
if apply_project_files_trigger is None:
apply_project_files_trigger = args.apply_file_whitelist
if apply_project_files_trigger is None:
if is_commit_build:
apply_project_files_trigger = False
else:
apply_project_files_trigger = True
if apply_project_files_trigger:
if patch:
diff_parser = DiffParser(patch.diff)
files_changed = diff_parser.get_changed_files()
elif revision:
try:
files_changed = _get_revision_changed_files(repository, revision)
except MissingRevision:
return error("Unable to find commit %s in %s." % (
args.sha, repository.url), problems=['sha', 'repository'])
else:
# the only way that revision can be null is if this repo does not have a vcs backend
logging.warning('Revision and patch are both None for sha %s. This is because the repo %s does not have a VCS backend.', sha, repository.url)
files_changed = None
else:
# we won't be applying file whitelist, so there is no need to get the list of changed files.
files_changed = None
collection_id = uuid.uuid4()
builds = []
for project in projects:
plan_list = get_build_plans(project)
if not plan_list:
logging.warning('No plans defined for project %s', project.slug)
continue
# 4. apply project whitelist as appropriate
if args.project_whitelist is not None and project.slug not in args.project_whitelist:
logging.info('Project %s is not in the supplied whitelist', project.slug)
continue
forced_sha = sha
# TODO(dcramer): find_green_parent_sha needs to take branch
# into account
# if patch_file:
# forced_sha = find_green_parent_sha(
# project=project,
# sha=sha,