改了几个文件
按变更模型,PR 动了 a.py、b.py、c.py,files_touched 交回几?
贯穿本节的变更/PR 模型:files={文件名: (加了几行, 删了几行)}。total_changes 交回改动总行数、files_touched 改了几个文件;mergeable(批准数, 改动请求数)——至少 1 个批准、且没有「请改」才能合并。
def total_changes(files):
# files: {文件名: (加了几行, 删了几行)};交回改动总行数
return sum(a + r for a, r in files.values())
def files_touched(files):
return len(files)
def mergeable(approvals, changes_requested):
# 至少 1 个批准、且没有「请改」才能合并
return approvals >= 1 and changes_requested == 0
print(files_touched({"a.py": (1, 0), "b.py": (2, 2), "c.py": (0, 3)}))
全部评论