def compare(self, old: str, old_date: str, new: str, new_date: str,
ctx: common.Context, meta: dict) \
-> ty.Tuple[bool, ty.Optional[str], ty.Optional[dict]]:
# pylint: disable=invalid-sequence-index
old_lines = old.split('\n')
res = list(difflib.context_diff(
old_lines, new.split('\n'),
fromfiledate=old_date, tofiledate=new_date,
lineterm='\n'))
changed_lines = sum(1 for line in res[2:]
if line and line[0] != ' ' and line[0] != '*')
if not _check_changes(ctx, changed_lines, len(old_lines),
self.conf.get("changes_threshold"),
self.conf.get("min_changed")):
return False, None, None
return True, "\n".join(res), self.opts
评论列表
文章目录