|
@@ -2,8 +2,10 @@ import {Fragment, useEffect, useState} from 'react';
|
|
|
import styled from '@emotion/styled';
|
|
|
|
|
|
import {addErrorMessage} from 'sentry/actionCreators/indicator';
|
|
|
+import {openModal} from 'sentry/actionCreators/modal';
|
|
|
import {Button, LinkButton} from 'sentry/components/button';
|
|
|
import {AutofixDiff} from 'sentry/components/events/autofix/autofixDiff';
|
|
|
+import {AutofixSetupWriteAccessModal} from 'sentry/components/events/autofix/autofixSetupWriteAccessModal';
|
|
|
import type {
|
|
|
AutofixChangesStep,
|
|
|
AutofixCodebaseChange,
|
|
@@ -13,6 +15,7 @@ import {
|
|
|
makeAutofixQueryKey,
|
|
|
useAutofixData,
|
|
|
} from 'sentry/components/events/autofix/useAutofix';
|
|
|
+import {useAutofixSetup} from 'sentry/components/events/autofix/useAutofixSetup';
|
|
|
import LoadingIndicator from 'sentry/components/loadingIndicator';
|
|
|
import {IconOpen} from 'sentry/icons';
|
|
|
import {t} from 'sentry/locale';
|
|
@@ -26,7 +29,7 @@ type AutofixChangesProps = {
|
|
|
step: AutofixChangesStep;
|
|
|
};
|
|
|
|
|
|
-function AutofixRepoChange({
|
|
|
+function CreatePullRequestButton({
|
|
|
change,
|
|
|
groupId,
|
|
|
}: {
|
|
@@ -36,7 +39,6 @@ function AutofixRepoChange({
|
|
|
const autofixData = useAutofixData({groupId});
|
|
|
const api = useApi();
|
|
|
const queryClient = useQueryClient();
|
|
|
-
|
|
|
const [hasClickedCreatePr, setHasClickedCreatePr] = useState(false);
|
|
|
|
|
|
const {mutate: createPr} = useMutation({
|
|
@@ -82,6 +84,90 @@ function AutofixRepoChange({
|
|
|
}
|
|
|
}, [hasClickedCreatePr, change.pull_request]);
|
|
|
|
|
|
+ return (
|
|
|
+ <Button
|
|
|
+ size="xs"
|
|
|
+ onClick={() => {
|
|
|
+ createPr();
|
|
|
+ setHasClickedCreatePr(true);
|
|
|
+ }}
|
|
|
+ icon={
|
|
|
+ hasClickedCreatePr && <ProcessingStatusIndicator size={14} mini hideMessage />
|
|
|
+ }
|
|
|
+ busy={hasClickedCreatePr}
|
|
|
+ analyticsEventName="Autofix: Create PR Clicked"
|
|
|
+ analyticsEventKey="autofix.create_pr_clicked"
|
|
|
+ analyticsParams={{group_id: groupId}}
|
|
|
+ >
|
|
|
+ {t('Create a Pull Request')}
|
|
|
+ </Button>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+function PullRequestLinkOrCreateButton({
|
|
|
+ change,
|
|
|
+ groupId,
|
|
|
+}: {
|
|
|
+ change: AutofixCodebaseChange;
|
|
|
+ groupId: string;
|
|
|
+}) {
|
|
|
+ const {data} = useAutofixSetup({groupId});
|
|
|
+
|
|
|
+ if (change.pull_request) {
|
|
|
+ return (
|
|
|
+ <LinkButton
|
|
|
+ size="xs"
|
|
|
+ icon={<IconOpen size="xs" />}
|
|
|
+ href={change.pull_request.pr_url}
|
|
|
+ external
|
|
|
+ analyticsEventName="Autofix: View PR Clicked"
|
|
|
+ analyticsEventKey="autofix.view_pr_clicked"
|
|
|
+ analyticsParams={{group_id: groupId}}
|
|
|
+ >
|
|
|
+ {t('View Pull Request')}
|
|
|
+ </LinkButton>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ if (
|
|
|
+ !data?.githubWriteIntegration?.repos?.find(
|
|
|
+ repo => `${repo.owner}/${repo.name}` === change.repo_name
|
|
|
+ )?.ok
|
|
|
+ ) {
|
|
|
+ return (
|
|
|
+ <Actions>
|
|
|
+ <Button
|
|
|
+ size="xs"
|
|
|
+ onClick={() => {
|
|
|
+ openModal(deps => (
|
|
|
+ <AutofixSetupWriteAccessModal {...deps} groupId={groupId} />
|
|
|
+ ));
|
|
|
+ }}
|
|
|
+ analyticsEventName="Autofix: Create PR Setup Clicked"
|
|
|
+ analyticsEventKey="autofix.create_pr_setup_clicked"
|
|
|
+ analyticsParams={{group_id: groupId}}
|
|
|
+ title={t('Enable write access to create pull requests')}
|
|
|
+ >
|
|
|
+ {t('Create a Pull Request')}
|
|
|
+ </Button>
|
|
|
+ </Actions>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Actions>
|
|
|
+ <CreatePullRequestButton change={change} groupId={groupId} />
|
|
|
+ </Actions>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+function AutofixRepoChange({
|
|
|
+ change,
|
|
|
+ groupId,
|
|
|
+}: {
|
|
|
+ change: AutofixCodebaseChange;
|
|
|
+ groupId: string;
|
|
|
+}) {
|
|
|
return (
|
|
|
<Content>
|
|
|
<RepoChangesHeader>
|
|
@@ -89,40 +175,7 @@ function AutofixRepoChange({
|
|
|
<Title>{change.repo_name}</Title>
|
|
|
<PullRequestTitle>{change.title}</PullRequestTitle>
|
|
|
</div>
|
|
|
- {!change.pull_request ? (
|
|
|
- <Actions>
|
|
|
- <Button
|
|
|
- size="xs"
|
|
|
- onClick={() => {
|
|
|
- createPr();
|
|
|
- setHasClickedCreatePr(true);
|
|
|
- }}
|
|
|
- icon={
|
|
|
- hasClickedCreatePr && (
|
|
|
- <ProcessingStatusIndicator size={14} mini hideMessage />
|
|
|
- )
|
|
|
- }
|
|
|
- busy={hasClickedCreatePr}
|
|
|
- analyticsEventName="Autofix: Create PR Clicked"
|
|
|
- analyticsEventKey="autofix.create_pr_clicked"
|
|
|
- analyticsParams={{group_id: groupId}}
|
|
|
- >
|
|
|
- {t('Create a Pull Request')}
|
|
|
- </Button>
|
|
|
- </Actions>
|
|
|
- ) : (
|
|
|
- <LinkButton
|
|
|
- size="xs"
|
|
|
- icon={<IconOpen size="xs" />}
|
|
|
- href={change.pull_request.pr_url}
|
|
|
- external
|
|
|
- analyticsEventName="Autofix: View PR Clicked"
|
|
|
- analyticsEventKey="autofix.view_pr_clicked"
|
|
|
- analyticsParams={{group_id: groupId}}
|
|
|
- >
|
|
|
- {t('View Pull Request')}
|
|
|
- </LinkButton>
|
|
|
- )}
|
|
|
+ <PullRequestLinkOrCreateButton change={change} groupId={groupId} />
|
|
|
</RepoChangesHeader>
|
|
|
<AutofixDiff diff={change.diff} />
|
|
|
</Content>
|