UNPKG

github-pr-automation

Version:

MCP server and CLI for automated GitHub PR management, review resolution, and workflow optimization

80 lines 2.73 kB
import { parsePRIdentifier, formatPRIdentifier } from "../../utils/parser.js"; /** * Check if a pull request is ready to merge * @param client - GitHub client instance * @param input - Input containing PR identifier * @returns Promise resolving to merge readiness status */ export async function handleCheckMergeReadiness(client, input) { const pr = parsePRIdentifier(input.pr); const octokit = client.getOctokit(); // Fetch PR and check runs const [pullRequest, checkRuns] = await Promise.all([ octokit.pulls.get({ owner: pr.owner, repo: pr.repo, pull_number: pr.number, }), octokit.checks.listForRef({ owner: pr.owner, repo: pr.repo, ref: (await octokit.pulls.get({ owner: pr.owner, repo: pr.repo, pull_number: pr.number, })).data.head.sha, }), ]); const data = pullRequest.data; // Check CI status const ciPassing = checkRuns.data.check_runs.length === 0 || checkRuns.data.check_runs.every((r) => r.status === "completed" && r.conclusion === "success"); // Check conflicts const noConflicts = data.mergeable !== false; // Simple checks (enhanced in later phases) const checks = { ci_passing: ciPassing, approvals_met: true, // Simplified - would need branch protection rules no_conflicts: noConflicts, up_to_date: true, // Simplified }; const blockingIssues = []; const nextSteps = []; if (!ciPassing) { blockingIssues.push({ category: "ci", description: "CI checks are failing", action_required: "Fix failing tests", }); nextSteps.push({ action: "fix_ci", description: "Review and fix failing CI checks", }); } if (!noConflicts) { blockingIssues.push({ category: "conflicts", description: "PR has merge conflicts", action_required: "Resolve conflicts with base branch", }); nextSteps.push({ action: "resolve_conflicts", description: "Merge or rebase with base branch to resolve conflicts", }); } // If ready to merge, provide merge action if (Object.values(checks).every((v) => v)) { nextSteps.push({ action: "merge", description: "PR is ready to merge", }); } return { pr: formatPRIdentifier(pr), ready_to_merge: Object.values(checks).every((v) => v), checks, blocking_issues: blockingIssues, next_steps: nextSteps, }; } //# sourceMappingURL=handler.js.map