in apichanges/repo.py [0:0]
def process(self, commit, change_diff):
if self.debug:
log.debug(
(
"commit:{commit_id:.8} tag:{tag} date:{created_at:%Y/%m/%d %H:%M}\n"
" stats: {stats}"
).format(
stats=change_diff.stats.format(
pygit2.GIT_DIFF_STATS_SHORT, 80
).strip(),
**commit
)
)
service_changes = []
change_path = change_log = None
if self.change_dir:
change_path = os.path.join(
self.change_dir, "%s.json" % commit["tag"].lstrip("v")
)
# Get file map so we can ensure change log first.
file_map = {d.new_file.path: d for d in change_diff.deltas}
if change_path and change_path in file_map:
change_log = self.load_change_log(file_map.get(change_path).new_file.id)
for dpath, d in [
(f, d)
for f, d in file_map.items()
if f.startswith(self.model_prefix) and f.endswith(self.model_suffix)
]:
if self.services:
found = False
for s in self.services:
if s in dpath:
found = True
if not found:
continue
if self.debug:
log.debug(
"api model change {} change: {}".format(dpath, d.status_char())
)
if d.status_char() == "A":
new = json.loads(self.repo[d.new_file.id].read_raw().decode("utf8"))
old = None
elif d.status_char() == "M":
new = json.loads(self.repo[d.new_file.id].read_raw().decode("utf8"))
old = json.loads(self.repo[d.old_file.id].read_raw().decode("utf8"))
else:
log.warning(
"service file unknown change commit:%s file:%s change:%s",
commit["commit_id"],
dpath,
d.status_char(),
)
continue
try:
svc_change = diff_model(new, old)
except Exception:
log.error("commit:%s error processing %s", commit["commit_id"], dpath)
raise
continue
if not svc_change:
continue
svc_change.model_file = str(d.new_file.id)
svc_change.commit = commit
svc_change.associate_logs(change_log)
log.info(svc_change)
service_changes.append(svc_change)
return service_changes