@h-rig/runtime 0.0.6-alpha.11 → 0.0.6-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1939,8 +1939,9 @@ function defaultPrCloseoutLine(taskId, repoNameWithOwner) {
1939
1939
  const sourceIssueId = loadRuntimeContextFromEnv()?.sourceTask?.sourceIssueId;
1940
1940
  if (sourceIssueId) {
1941
1941
  const match = sourceIssueId.match(/^([^#]+)#(\d+)$/);
1942
- if (match) {
1943
- const [, sourceRepo, issueNumber] = match;
1942
+ if (match?.[1] && match[2]) {
1943
+ const sourceRepo = match[1];
1944
+ const issueNumber = match[2];
1944
1945
  return sourceRepo.toLowerCase() === repoNameWithOwner.toLowerCase() ? `Closes #${issueNumber}` : `Closes ${sourceRepo}#${issueNumber}`;
1945
1946
  }
1946
1947
  }
@@ -2035,56 +2036,43 @@ function gitMergePr(options) {
2035
2036
  if (isDraft) {
2036
2037
  throw new Error(`Cannot auto-merge draft PR ${options.pr.url}.`);
2037
2038
  }
2039
+ const strictGateHeadSha = options.strictGateHeadSha?.trim();
2040
+ if (!strictGateHeadSha) {
2041
+ throw new Error(`Refusing to merge PR ${options.pr.url}: strict merge gate did not provide a current head SHA.`);
2042
+ }
2038
2043
  const mergeArgs = withGhRepo([gh, "pr", "merge", options.pr.url], repoNameWithOwner);
2039
2044
  const method = options.method || "squash";
2040
2045
  mergeArgs.push(method === "merge" ? "--merge" : method === "rebase" ? "--rebase" : "--squash");
2046
+ mergeArgs.push("--match-head-commit", strictGateHeadSha);
2041
2047
  if (options.deleteBranch !== false) {
2042
2048
  mergeArgs.push("--delete-branch");
2043
2049
  }
2044
- const autoMergeArgs = [...mergeArgs, "--auto"];
2045
- const autoMerge = runCapture2(autoMergeArgs, repoRoot);
2046
- if (autoMerge.exitCode === 0) {
2047
- const postAutoMergeState = readPrViewState(gh, repoRoot, repoNameWithOwner, options.pr.url);
2048
- if (postAutoMergeState.state === "MERGED" || postAutoMergeState.mergedAt) {
2049
- console.log(`Merged PR (${options.pr.repoLabel}): ${options.pr.url}`);
2050
- return { status: "merged", url: options.pr.url };
2051
- }
2052
- if (postAutoMergeState.state === "OPEN" && postAutoMergeState.autoMergeRequest) {
2053
- if (canAdminMergeApprovedPr(postAutoMergeState)) {
2054
- const adminMergeArgs = [...mergeArgs];
2055
- if (postAutoMergeState.headRefOid) {
2056
- adminMergeArgs.push("--match-head-commit", postAutoMergeState.headRefOid);
2057
- }
2058
- adminMergeArgs.push("--admin");
2059
- const adminMerge = runCapture2(adminMergeArgs, repoRoot);
2060
- if (adminMerge.exitCode === 0) {
2061
- const postAdminMergeState = readPrViewState(gh, repoRoot, repoNameWithOwner, options.pr.url);
2062
- if (postAdminMergeState.state === "MERGED" || postAdminMergeState.mergedAt) {
2063
- console.log(`Merged PR (${options.pr.repoLabel}) with admin fallback: ${options.pr.url}`);
2064
- return { status: "merged", url: options.pr.url };
2065
- }
2066
- throw new Error(`Admin merge command succeeded for PR ${options.pr.url} in ${options.pr.repoLabel}, but GitHub still reports it open.`);
2067
- }
2068
- const adminMergeMessage = `${adminMerge.stderr}
2069
- ${adminMerge.stdout}`.trim();
2070
- if (!/admin|administrator|permission|not permitted|not allowed/i.test(adminMergeMessage)) {
2071
- throw new Error(`Failed to admin-merge PR ${options.pr.url} in ${options.pr.repoLabel}: ${adminMergeMessage}`);
2072
- }
2050
+ const directMerge = runCapture2(mergeArgs, repoRoot);
2051
+ if (directMerge.exitCode === 0) {
2052
+ console.log(`Merged PR (${options.pr.repoLabel}): ${options.pr.url}`);
2053
+ return { status: "merged", url: options.pr.url };
2054
+ }
2055
+ const postDirectState = readPrViewState(gh, repoRoot, repoNameWithOwner, options.pr.url);
2056
+ if (canAdminMergeApprovedPr(postDirectState)) {
2057
+ const adminMergeArgs = [...mergeArgs, "--admin"];
2058
+ const adminMerge = runCapture2(adminMergeArgs, repoRoot);
2059
+ if (adminMerge.exitCode === 0) {
2060
+ const postAdminMergeState = readPrViewState(gh, repoRoot, repoNameWithOwner, options.pr.url);
2061
+ if (postAdminMergeState.state === "MERGED" || postAdminMergeState.mergedAt) {
2062
+ console.log(`Merged PR (${options.pr.repoLabel}) with admin fallback: ${options.pr.url}`);
2063
+ return { status: "merged", url: options.pr.url };
2073
2064
  }
2074
- console.log(`Auto-merge enabled (${options.pr.repoLabel}): ${options.pr.url}`);
2075
- return { status: "auto-merge-enabled", url: options.pr.url };
2065
+ throw new Error(`Admin merge command succeeded for PR ${options.pr.url} in ${options.pr.repoLabel}, but GitHub still reports it open.`);
2066
+ }
2067
+ const adminMergeMessage = `${adminMerge.stderr}
2068
+ ${adminMerge.stdout}`.trim();
2069
+ if (!/admin|administrator|permission|not permitted|not allowed/i.test(adminMergeMessage)) {
2070
+ throw new Error(`Failed to admin-merge PR ${options.pr.url} in ${options.pr.repoLabel}: ${adminMergeMessage}`);
2076
2071
  }
2077
- throw new Error(`Auto-merge command succeeded for PR ${options.pr.url} in ${options.pr.repoLabel}, but GitHub did not report a merged or auto-merge-enabled state.`);
2078
- }
2079
- const autoMergeMessage = `${autoMerge.stderr}
2080
- ${autoMerge.stdout}`.trim();
2081
- const autoMergeUnsupported = /auto.?merge.*(not enabled|not allowed|disabled|unsupported)|enablePullRequestAutoMerge|Auto merge is not allowed/i.test(autoMergeMessage);
2082
- if (!autoMergeUnsupported) {
2083
- throw new Error(`Failed to auto-merge PR ${options.pr.url} in ${options.pr.repoLabel}: ${autoMergeMessage}`);
2084
2072
  }
2085
- runOrThrow(options.projectRoot, mergeArgs, `Failed to merge PR ${options.pr.url} in ${options.pr.repoLabel}`);
2086
- console.log(`Merged PR (${options.pr.repoLabel}): ${options.pr.url}`);
2087
- return { status: "merged", url: options.pr.url };
2073
+ const directMergeMessage = `${directMerge.stderr}
2074
+ ${directMerge.stdout}`.trim();
2075
+ throw new Error(`Failed to merge PR ${options.pr.url} in ${options.pr.repoLabel}: ${directMergeMessage}`);
2088
2076
  }
2089
2077
  function assertPrHasNoGitConflicts(prState, repoLabel, baseRef) {
2090
2078
  const mergeable = prState.mergeable.toUpperCase();