Skip to content

Commit

Permalink
feat(autofix): Surface error on pr creation (#86150)
Browse files Browse the repository at this point in the history
Ideally when `status = 'error'` we'd return a 500 status and use the
`onError` but it doesn't have the response body in it to get the passed
down message...
  • Loading branch information
jennmueng authored Mar 1, 2025
1 parent a1d4314 commit 5f10bf7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
24 changes: 18 additions & 6 deletions static/app/components/events/autofix/autofixChanges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
type AutofixChangesStep,
type AutofixCodebaseChange,
AutofixStatus,
type AutofixUpdateEndpointResponse,
} from 'sentry/components/events/autofix/types';
import {
makeAutofixQueryKey,
Expand Down Expand Up @@ -203,11 +204,17 @@ function CreatePRsButton({
},
});
},
onSuccess: () => {
addSuccessMessage(t('Created pull requests.'));
queryClient.invalidateQueries({queryKey: makeAutofixQueryKey(groupId)});
setHasClickedCreatePr(false);
onBusyStateChange(false);
onSuccess: (data: AutofixUpdateEndpointResponse) => {
if (data.status === 'error') {
addErrorMessage(data.message ?? t('Failed to create a pull request'));
setHasClickedCreatePr(false);
onBusyStateChange(false);
} else {
addSuccessMessage(t('Created pull requests.'));
queryClient.invalidateQueries({queryKey: makeAutofixQueryKey(groupId)});
setHasClickedCreatePr(false);
onBusyStateChange(false);
}
},
onError: () => {
setHasClickedCreatePr(false);
Expand Down Expand Up @@ -273,7 +280,12 @@ function CreateBranchButton({
},
});
},
onSuccess: () => {
onSuccess: (data: AutofixUpdateEndpointResponse) => {
if (data.status === 'error') {
addErrorMessage(data.message ?? t('Failed to create a pull request'));
setHasClickedPushToBranch(false);
onBusyStateChange(false);
}
addSuccessMessage(t('Pushed to branches.'));
queryClient.invalidateQueries({queryKey: makeAutofixQueryKey(groupId)});
setHasClickedPushToBranch(false);
Expand Down
6 changes: 6 additions & 0 deletions static/app/components/events/autofix/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export type AutofixOptions = {
iterative_feedback?: boolean;
};

export type AutofixUpdateEndpointResponse = {
run_id: number;
message?: string;
status?: 'success' | 'error';
};

export type AutofixRepository = {
default_branch: string;
external_id: string;
Expand Down

0 comments on commit 5f10bf7

Please sign in to comment.