Surface GitHub auto-merge actions (#1001)
* Surface GitHub auto-merge actions * Namespace GitHub auto-merge RPC * Update workspace git refresh test expectation * Avoid redundant GitHub refresh queue
This commit is contained in:
@@ -1708,6 +1708,30 @@ const x = 1;
|
||||
expect(callCount).toBe(1);
|
||||
});
|
||||
|
||||
it("passes forced PR status reads through to the GitHub service", async () => {
|
||||
execFileSync("git", ["checkout", "-b", "feature"], { cwd: repoDir });
|
||||
execFileSync("git", ["remote", "add", "origin", "https://github.com/getpaseo/paseo.git"], {
|
||||
cwd: repoDir,
|
||||
});
|
||||
|
||||
const requested: Array<{ force?: boolean; reason?: string }> = [];
|
||||
const github = createGitHubServiceForStatus(null);
|
||||
github.getCurrentPullRequestStatus = async (options) => {
|
||||
requested.push({
|
||||
...(options.force ? { force: options.force } : {}),
|
||||
...(options.reason ? { reason: options.reason } : {}),
|
||||
});
|
||||
return createPullRequestStatus();
|
||||
};
|
||||
|
||||
await getPullRequestStatus(repoDir, github, {
|
||||
force: true,
|
||||
reason: "merge-pr-validation",
|
||||
});
|
||||
|
||||
expect(requested).toEqual([{ force: true, reason: "merge-pr-validation" }]);
|
||||
});
|
||||
|
||||
it("expires cached PR status after the TTL", async () => {
|
||||
execFileSync("git", ["checkout", "-b", "feature"], { cwd: repoDir });
|
||||
execFileSync("git", ["remote", "add", "origin", "https://github.com/getpaseo/paseo.git"], {
|
||||
@@ -1777,6 +1801,39 @@ const x = 1;
|
||||
}
|
||||
});
|
||||
|
||||
it("does not use stale PR status fallback for forced GitHub errors", async () => {
|
||||
execFileSync("git", ["checkout", "-b", "feature"], { cwd: repoDir });
|
||||
execFileSync("git", ["remote", "add", "origin", "https://github.com/getpaseo/paseo.git"], {
|
||||
cwd: repoDir,
|
||||
});
|
||||
|
||||
const github = createGitHubServiceForStatus(null);
|
||||
github.getCurrentPullRequestStatus = async () =>
|
||||
createPullRequestStatus({
|
||||
url: "https://github.com/getpaseo/paseo/pull/123",
|
||||
});
|
||||
|
||||
const fresh = await getPullRequestStatus(repoDir, github);
|
||||
expect(fresh.status?.url).toContain("/pull/123");
|
||||
|
||||
const error = new GitHubCommandError({
|
||||
args: ["pr", "view"],
|
||||
cwd: repoDir,
|
||||
exitCode: 1,
|
||||
stderr: "could not resolve host: github.com",
|
||||
});
|
||||
github.getCurrentPullRequestStatus = async () => {
|
||||
throw error;
|
||||
};
|
||||
|
||||
await expect(
|
||||
getPullRequestStatus(repoDir, github, {
|
||||
force: true,
|
||||
reason: "merge-pr-validation",
|
||||
}),
|
||||
).rejects.toBe(error);
|
||||
});
|
||||
|
||||
it("clears stale PR status after a successful no-PR refresh", async () => {
|
||||
execFileSync("git", ["checkout", "-b", "feature"], { cwd: repoDir });
|
||||
execFileSync("git", ["remote", "add", "origin", "https://github.com/getpaseo/paseo.git"], {
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
GitHubCommandError,
|
||||
createGitHubService,
|
||||
resolveGitHubRepo,
|
||||
type GitHubCurrentPullRequestStatus,
|
||||
type GitHubPullRequestStatusFacts,
|
||||
type GitHubService,
|
||||
type PullRequestMergeable,
|
||||
} from "../services/github-service.js";
|
||||
@@ -2318,6 +2320,7 @@ export interface PullRequestStatus {
|
||||
checks?: PullRequestCheck[];
|
||||
checksStatus?: ChecksStatus;
|
||||
reviewDecision?: ReviewDecision;
|
||||
github?: GitHubPullRequestStatusFacts;
|
||||
}
|
||||
|
||||
export interface PullRequestStatusResult {
|
||||
@@ -2402,7 +2405,7 @@ export async function getPullRequestStatus(
|
||||
return status;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof GitHubCommandError) {
|
||||
if (!options?.force && error instanceof GitHubCommandError) {
|
||||
const stale = lastSuccessfulPullRequestStatus.get(cacheKey);
|
||||
if (stale) {
|
||||
return stale;
|
||||
@@ -2433,11 +2436,25 @@ async function getPullRequestStatusUncached(
|
||||
}
|
||||
try {
|
||||
const lookupTarget = await resolvePullRequestStatusLookupTarget(cwd, head);
|
||||
const status = await github.getCurrentPullRequestStatus({
|
||||
cwd,
|
||||
...lookupTarget,
|
||||
reason: options?.reason,
|
||||
});
|
||||
let status: GitHubCurrentPullRequestStatus | null;
|
||||
if (options?.force) {
|
||||
const reason = options.reason;
|
||||
if (!reason) {
|
||||
throw new Error("Forced PR status read requires a reason");
|
||||
}
|
||||
status = await github.getCurrentPullRequestStatus({
|
||||
cwd,
|
||||
...lookupTarget,
|
||||
force: true,
|
||||
reason,
|
||||
});
|
||||
} else {
|
||||
status = await github.getCurrentPullRequestStatus({
|
||||
cwd,
|
||||
...lookupTarget,
|
||||
reason: options?.reason,
|
||||
});
|
||||
}
|
||||
return {
|
||||
status,
|
||||
githubFeaturesEnabled: true,
|
||||
|
||||
Reference in New Issue
Block a user