MCPcopy Create free account
hub / github.com/ceph/ceph / run

Method run

src/script/ptl-tool.py:1416–1463  ·  view source on GitHub ↗
(self, ctx: AuditContext)

Source from the content-addressed store, hash-verified

1414 return "Merge Conflict"
1415
1416 def run(self, ctx: AuditContext) -> None:
1417 G, session, pr, tip, base, report, args = ctx.G, ctx.session, ctx.pr, ctx.tip, ctx.base, ctx.report, ctx.args
1418 log.info("Performing trivial merge check for PR #%d...", pr)
1419 wt_dir = tempfile.mkdtemp(prefix="ptl-merge-check-")
1420 has_base_conflicts = False
1421 try:
1422 G.git.worktree('add', '--detach', wt_dir, G.head.commit)
1423 wt_repo = git.Repo(wt_dir)
1424 try:
1425 wt_repo.git(c=SANDBOX_CFG).merge(tip.hexsha, '--no-commit', '--no-ff')
1426 except git.exc.GitCommandError as e:
1427 log.debug(f"Merge failed: {e}")
1428 has_base_conflicts = True
1429 finally:
1430 try:
1431 wt_repo.git.merge('--abort')
1432 except git.exc.GitCommandError:
1433 pass
1434 finally:
1435 G.git.worktree('remove', '--force', wt_dir)
1436
1437 if has_base_conflicts:
1438 log.error(f"PR #{pr} has conflicts with the target base branch.")
1439 md_text = "### Automated PR Review - Rebase Required\n\n"
1440 md_text += f"This PR currently has merge conflicts with the target base branch. Please rebase and resolve the conflicts."
1441 if args.ci_mode:
1442 report.add("Base Conflicts", md_text)
1443 else:
1444 while True:
1445 ans = input(f"PR #{pr} needs a rebase! Do you want to add a review requesting a rebase? [p/r/m/q/o] (p=proceed/skip check, r=add to review, m=skip to merge, q=abort, o=open PR in browser): ").strip().lower()
1446 if ans == 'o':
1447 url = f"https://github.com/{BASE_PROJECT}/{BASE_REPO}/pull/{pr}"
1448 open_in_browser([url])
1449 print(f"Opened {url} in browser.")
1450 elif ans == 'm':
1451 raise SkipToMerge()
1452 elif ans == 'p':
1453 log.warning(f"Skipping rebase check for PR #{pr}.")
1454 break
1455 elif ans == 'r':
1456 report.add("Base Conflicts", md_text)
1457 report.record_failure()
1458 break
1459 elif ans == 'q' or ans == '':
1460 log.error(f"Aborting script due to unmergeable PR #{pr}.")
1461 sys.exit(1)
1462 else:
1463 print("Invalid choice. Please enter p, r, m, q, or o.")
1464
1465def verify_pr_readiness(G, session, R, pr, pr_commits, tip, base, args):
1466 report = AuditReport()

Callers

nothing calls this directly

Calls 12

open_in_browserFunction · 0.85
printFunction · 0.85
SkipToMergeClass · 0.85
record_failureMethod · 0.80
inputClass · 0.50
infoMethod · 0.45
mergeMethod · 0.45
debugMethod · 0.45
errorMethod · 0.45
addMethod · 0.45
warningMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected