Browse Source

feat(github-growth): replace delete repo with hide repo on config page (#53024)

Cathy Teng 1 year ago
parent
commit
770dfb4316

+ 23 - 0
static/app/actionCreators/integrations.tsx

@@ -109,6 +109,29 @@ export function cancelDeleteRepository(
   return promise;
 }
 
+/**
+ * Delete a repository by setting its status to hidden.
+ *
+ * @param client ApiClient
+ * @param orgId Organization Slug
+ * @param repositoryId Repository ID
+ */
+export function hideRepository(client: Client, orgId: string, repositoryId: string) {
+  addLoadingMessage();
+  const promise = client.requestPromise(
+    `/organizations/${orgId}/repos/${repositoryId}/`,
+    {
+      method: 'PUT',
+      data: {status: 'hidden'},
+    }
+  );
+  promise.then(
+    () => clearIndicators(),
+    () => addErrorMessage(t('Unable to delete repository.'))
+  );
+  return promise;
+}
+
 function applyRepositoryAddComplete(promise: Promise<Repository>) {
   promise.then(
     (repo: Repository) => {

+ 3 - 3
static/app/components/repositoryRow.spec.tsx

@@ -115,12 +115,12 @@ describe('RepositoryRow', function () {
       access: ['org:integrations'],
     });
 
-    it('sends api request on delete', async function () {
+    it('sends api request to hide upon clicking delete', async function () {
       const deleteRepo = MockApiClient.addMockResponse({
         url: `/organizations/${organization.slug}/repos/${repository.id}/`,
-        method: 'DELETE',
+        method: 'PUT',
         statusCode: 204,
-        body: {},
+        body: {status: 'hidden'},
       });
 
       render(

+ 2 - 5
static/app/components/repositoryRow.tsx

@@ -1,10 +1,7 @@
 import {Fragment} from 'react';
 import styled from '@emotion/styled';
 
-import {
-  cancelDeleteRepository,
-  deleteRepository,
-} from 'sentry/actionCreators/integrations';
+import {cancelDeleteRepository, hideRepository} from 'sentry/actionCreators/integrations';
 import {openModal} from 'sentry/actionCreators/modal';
 import {Client} from 'sentry/api';
 import Access from 'sentry/components/acl/access';
@@ -69,7 +66,7 @@ function RepositoryRow({
     );
 
   const deleteRepo = () =>
-    deleteRepository(api, orgId, repository.id).then(
+    hideRepository(api, orgId, repository.id).then(
       data => {
         if (onRepositoryChange) {
           onRepositoryChange(data);