Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/github/backfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1977,9 +1977,22 @@
}

const ciState: LiveCiAggregate["ciState"] = failingDetails.length > 0 ? "failed" : anyPending ? "pending" : total > 0 ? "passed" : "unverified";
return { ciState, failingDetails };

Check warning on line 1980 in src/github/backfill.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Missing test evidence

Code changed without an obvious test file in this PR. Add focused tests or explain why existing coverage is sufficient.

Check notice on line 1980 in src/github/backfill.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 1980 in src/github/backfill.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Open PR queue is busy

This repo has a busy open PR queue in the local Gittensory cache.

Check notice on line 1980 in src/github/backfill.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

PR author has maintainer association

This PR appears to come from a maintainer-associated account.
}

/**
* Fetch a PR's LIVE `mergeable_state` (clean / dirty / blocked / unstable / behind / has_hooks / unknown). The
* STORED value lags GitHub's async recompute — e.g. right after gittensory[bot]'s own APPROVE flips a `blocked`
* PR to `clean`, the stored row is still `blocked`, which stops an otherwise-eligible PR from auto-merging
* (observed: green+approved PRs stuck OPEN at `mergeState=CLEAN`). The auto-maintain planner uses this so the
* merge decision sees the CURRENT state. `unknown` (GitHub still computing) ⇒ caller treats as not-yet-clean and
* a later trigger / the sweep retries. Best-effort: a fetch error returns undefined (caller falls back to stored).
*/
export async function fetchLivePullRequestMergeState(env: Env, repoFullName: string, prNumber: number, token: string | undefined): Promise<string | undefined> {
const result = await githubJsonWithHeaders<{ mergeable_state?: string | null }>(env, repoFullName, `/pulls/${prNumber}`, token).catch(() => undefined);
return result?.data.mergeable_state ?? undefined;
}

async function fetchPullRequestDetailsFromGraphQl(
env: Env,
repoFullName: string,
Expand Down
8 changes: 6 additions & 2 deletions src/queue/processors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@
backfillOpenPullRequestDetails,
backfillRegisteredRepositories,
backfillRepositorySegment,
enqueueRepositoryOpenDataBackfill,

Check warning on line 65 in src/queue/processors.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Missing test evidence

Code changed without an obvious test file in this PR. Add focused tests or explain why existing coverage is sufficient.

Check notice on line 65 in src/queue/processors.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 65 in src/queue/processors.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Open PR queue is busy

This repo has a busy open PR queue in the local Gittensory cache.

Check notice on line 65 in src/queue/processors.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

PR author has maintainer association

This PR appears to come from a maintainer-associated account.
fetchAndStorePullRequestFilesForReview,
fetchLiveCiAggregate,
fetchLivePullRequestMergeState,
refreshContributorActivity,
refreshInstallationHealth,
refreshPullRequestDetails,
Expand Down Expand Up @@ -605,10 +606,13 @@
// planner uses this to NEVER approve/merge a PR whose CI isn't green, to CLOSE a red-CI non-owner PR (citing
// the failing checks) / HOLD the owner's, and to DEFER entirely while CI is still pending.
const ciToken = await createInstallationToken(env, installationId).catch(() => undefined);
const [changedFiles, hardGuardrailGlobs, ciAggregate] = await Promise.all([
const [changedFiles, hardGuardrailGlobs, ciAggregate, liveMergeState] = await Promise.all([
resolvePullRequestFilesForReview(env, { installationId, repoFullName, pullNumber: pr.number }),
loadHardGuardrailGlobs(env, repoFullName),
fetchLiveCiAggregate(env, repoFullName, pr.headSha, ciToken ?? env.GITHUB_PUBLIC_TOKEN),
// Live mergeable_state — the stored one lags GitHub's async recompute after the bot's own approve, which
// otherwise leaves a green+approved PR stuck OPEN at mergeState=CLEAN (never auto-merged).
fetchLivePullRequestMergeState(env, repoFullName, pr.number, ciToken ?? env.GITHUB_PUBLIC_TOKEN),
]);
const changedPaths = changedFiles.map((file) => file.path).filter((path) => path.length > 0);
const repoOwner = repoFullName.includes("/") ? repoFullName.slice(0, repoFullName.indexOf("/")) : "";
Expand All @@ -629,7 +633,7 @@
ciState: ciAggregate.ciState,
failingCheckNames: ciAggregate.failingDetails.map((detail) => detail.name),
pr: {
mergeableState: pr.mergeableState,
mergeableState: liveMergeState ?? pr.mergeableState,
reviewDecision: pr.reviewDecision,
slopRisk: pr.slopRisk,
labels: pr.labels,
Expand Down
Loading