fix(web): links to issues no longer strand the pull request viewer (#14242)
This commit is contained in:
1 parent
2b8bb0c188
commit
7bc161f869
12 files changed
+73
-6
No files matched your search
@@ -117,6 +117,7 @@ export function azureDevOpsProviderFailure(
|
||||
if (error._tag === "AzureDevOpsCliUnavailableError") return { reason: "missing-tool" };
|
||||
if (error._tag === "AzureDevOpsCliAuthenticationError") return { reason: "unauthenticated" };
|
||||
if (error._tag === "AzureDevOpsCliRateLimitError") return { reason: "rate-limited" };
|
||||
if (error._tag === "AzureDevOpsPullRequestNotFoundError") return { reason: "not-found" };
|
||||
return { reason: "failed" };
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,12 @@ export function bitbucketProviderFailure(
|
||||
...(error.retryAt === undefined ? {} : { retryAt: error.retryAt }),
|
||||
};
|
||||
}
|
||||
if (
|
||||
(error._tag === "BitbucketResponseError" || error._tag === "BitbucketResponseBodyReadError") &&
|
||||
error.status === 404
|
||||
) {
|
||||
return { reason: "not-found" };
|
||||
}
|
||||
return { reason: "failed" };
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,9 @@ export const make = Effect.gen(function* () {
|
||||
? "unauthenticated"
|
||||
: error.reason === "rate-limit"
|
||||
? "rate-limited"
|
||||
: "failed",
|
||||
: error.reason === "not-found"
|
||||
? "not-found"
|
||||
: "failed",
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -115,6 +115,7 @@ export function gitHubProviderFailure(
|
||||
if (error._tag === "SourceControlRateLimitPausedError") {
|
||||
return { reason: "rate-limited", retryAt: error.retryAt };
|
||||
}
|
||||
if (error._tag === "GitHubPullRequestNotFoundError") return { reason: "not-found" };
|
||||
return { reason: "failed" };
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,7 @@ export function gitLabProviderFailure(
|
||||
if (error._tag === "GitLabCliUnavailableError") return { reason: "missing-tool" };
|
||||
if (error._tag === "GitLabCliAuthenticationError") return { reason: "unauthenticated" };
|
||||
if (error._tag === "GitLabCliRateLimitError") return { reason: "rate-limited" };
|
||||
if (error._tag === "GitLabMergeRequestNotFoundError") return { reason: "not-found" };
|
||||
return { reason: "failed" };
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,13 @@ export class PullRequestProviderError extends Schema.TaggedError<PullRequestProv
|
||||
{
|
||||
provider: SourceControlProviderKindSchema,
|
||||
operation: Schema.String,
|
||||
reason: Schema.Literals(["missing-tool", "unauthenticated", "rate-limited", "failed"]),
|
||||
reason: Schema.Literals([
|
||||
"missing-tool",
|
||||
"unauthenticated",
|
||||
"rate-limited",
|
||||
"not-found",
|
||||
"failed",
|
||||
]),
|
||||
detail: Schema.String,
|
||||
retryAt: Schema.optional(Schema.Number),
|
||||
cause: Schema.optional(Schema.Defect()),
|
||||
|
||||
@@ -4815,6 +4815,33 @@ it.effect("does not let a still-cached detail overwrite a fresher linked summary
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("tells the client when the host has no pull request under that number", () =>
|
||||
Effect.gen(function* () {
|
||||
const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 121 };
|
||||
const service = yield* makeService({
|
||||
projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
|
||||
providers: [
|
||||
fakeProvider("github", {
|
||||
getChangeRequest: () =>
|
||||
Effect.fail(
|
||||
new PullRequestProviderError({
|
||||
provider: "github",
|
||||
operation: "getChangeRequest",
|
||||
reason: "not-found",
|
||||
detail: "Pull request not found. Check the PR number or URL and try again.",
|
||||
}),
|
||||
),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const error = yield* Effect.flip(service.detail(reference));
|
||||
|
||||
assert.strictEqual(error._tag, "PullRequestOperationError");
|
||||
assert.strictEqual(error._tag === "PullRequestOperationError" && error.reason, "not-found");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("keeps recent detail on a transient refresh failure but not after invalidation", () =>
|
||||
Effect.gen(function* () {
|
||||
let failing = false;
|
||||
|
||||
@@ -477,7 +477,12 @@ function toPullRequestError(
|
||||
return (error) =>
|
||||
isProviderUnusable(error)
|
||||
? toUnavailableError(error)
|
||||
: new PullRequestOperationError({ operation, detail: error.detail, cause: error });
|
||||
: new PullRequestOperationError({
|
||||
operation,
|
||||
detail: error.detail,
|
||||
...(error.reason === "not-found" ? { reason: "not-found" as const } : {}),
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
|
||||
function withRateLimitBackoff(
|
||||
|
||||
@@ -144,6 +144,7 @@ import {
|
||||
handoffReviewComments,
|
||||
latestPullRequestReviewOutcomes,
|
||||
loadingPullRequestCheckoutCommand,
|
||||
isPullRequestNotFound,
|
||||
isStackedPullRequestBase,
|
||||
pullRequestActionMenuHasGroup,
|
||||
pullRequestActionNeedsHostRefresh,
|
||||
@@ -2719,7 +2720,13 @@ export function PullRequestDetailPanel({
|
||||
>
|
||||
{detailQuery.error && !detail ? (
|
||||
<PullRequestsUnavailableState
|
||||
error={detailQuery.error}
|
||||
{...(isPullRequestNotFound(detailQuery.failure)
|
||||
? {
|
||||
title: `Pull request #${reference.number} not found`,
|
||||
error:
|
||||
"It may be an issue rather than a pull request, or this account can't see it.",
|
||||
}
|
||||
: { error: detailQuery.error })}
|
||||
refreshing={detailQuery.isPending}
|
||||
onRetry={refreshDetail}
|
||||
{...(unavailableGitHubUrl ? { gitHubUrl: unavailableGitHubUrl } : {})}
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as Schema from "effect/Schema";
|
||||
|
||||
import {
|
||||
PullRequestDetail,
|
||||
PullRequestOperationError,
|
||||
pullRequestHostOf,
|
||||
type PullRequestAction,
|
||||
type PullRequestActor,
|
||||
@@ -1161,6 +1162,12 @@ export function buildAddSelectionToAgentHandoff(input: {
|
||||
};
|
||||
}
|
||||
|
||||
const isPullRequestOperationError = Schema.is(PullRequestOperationError);
|
||||
|
||||
export function isPullRequestNotFound(failure: unknown): boolean {
|
||||
return isPullRequestOperationError(failure) && failure.reason === "not-found";
|
||||
}
|
||||
|
||||
/**
|
||||
* The internal wrapper every failed operation arrives in: which operation ran, and which tool
|
||||
* said no. A reader has no use for either.
|
||||
|
||||
@@ -7,10 +7,11 @@ const EMPTY_ASYNC_RESULT_ATOM = Atom.make(AsyncResult.initial<never, never>(fals
|
||||
Atom.withLabel("web-environment-query:empty"),
|
||||
);
|
||||
|
||||
export interface EnvironmentQueryView<A> {
|
||||
export interface EnvironmentQueryView<A, E = unknown> {
|
||||
readonly data: A | null;
|
||||
readonly dataUpdatedAt: number;
|
||||
readonly error: string | null;
|
||||
readonly failure: E | null;
|
||||
readonly isPending: boolean;
|
||||
readonly isSuccess: boolean;
|
||||
readonly refresh: () => void;
|
||||
@@ -25,7 +26,7 @@ export function formatEnvironmentQueryError(cause: Cause.Cause<unknown>): string
|
||||
|
||||
export function useEnvironmentQuery<A, E>(
|
||||
atom: Atom.Atom<AsyncResult.AsyncResult<A, E>> | null,
|
||||
): EnvironmentQueryView<A> {
|
||||
): EnvironmentQueryView<A, E> {
|
||||
const selectedAtom = atom ?? EMPTY_ASYNC_RESULT_ATOM;
|
||||
const result = useAtomValue(selectedAtom);
|
||||
const refresh = useAtomRefresh(selectedAtom);
|
||||
@@ -38,6 +39,8 @@ export function useEnvironmentQuery<A, E>(
|
||||
? (Option.getOrNull(result.previousSuccess)?.timestamp ?? 0)
|
||||
: 0,
|
||||
error: result._tag === "Failure" ? formatEnvironmentQueryError(result.cause) : null,
|
||||
failure:
|
||||
result._tag === "Failure" ? Option.getOrNull(Cause.findErrorOption(result.cause)) : null,
|
||||
isPending: atom !== null && result.waiting,
|
||||
isSuccess: result._tag === "Success",
|
||||
refresh,
|
||||
|
||||
@@ -1407,6 +1407,7 @@ export class PullRequestOperationError extends Schema.TaggedError<PullRequestOpe
|
||||
{
|
||||
operation: Schema.String,
|
||||
detail: TrimmedNonEmptyString,
|
||||
reason: Schema.optional(Schema.Literal("not-found")),
|
||||
cause: Schema.optional(Schema.Defect()),
|
||||
},
|
||||
{ httpApiStatus: 502 },
|
||||
|
||||
Reference in new issue
Block a user