@scm-manager/ui-api 2.36.1 → 2.36.2-20220522-120507

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/build/index.d.ts +735 -0
  2. package/build/index.js +3200 -0
  3. package/build/index.mjs +3031 -0
  4. package/package.json +15 -10
  5. package/LICENSE.txt +0 -21
  6. package/src/ApiProvider.test.tsx +0 -60
  7. package/src/ApiProvider.tsx +0 -80
  8. package/src/LegacyContext.test.tsx +0 -52
  9. package/src/LegacyContext.tsx +0 -75
  10. package/src/admin.test.ts +0 -55
  11. package/src/admin.ts +0 -42
  12. package/src/alerts.ts +0 -107
  13. package/src/annotations.ts +0 -45
  14. package/src/apiKeys.ts +0 -82
  15. package/src/apiclient.test.ts +0 -126
  16. package/src/apiclient.ts +0 -336
  17. package/src/base.test.ts +0 -238
  18. package/src/base.ts +0 -120
  19. package/src/branches.test.ts +0 -234
  20. package/src/branches.ts +0 -201
  21. package/src/changesets.test.ts +0 -178
  22. package/src/changesets.ts +0 -82
  23. package/src/compare.ts +0 -90
  24. package/src/config.test.ts +0 -118
  25. package/src/config.ts +0 -60
  26. package/src/configLink.test.ts +0 -169
  27. package/src/configLink.ts +0 -89
  28. package/src/contentType.ts +0 -58
  29. package/src/diff.test.ts +0 -234
  30. package/src/diff.ts +0 -93
  31. package/src/errors.test.ts +0 -59
  32. package/src/errors.ts +0 -133
  33. package/src/fileContent.ts +0 -33
  34. package/src/groupSuggestions.ts +0 -32
  35. package/src/groups.test.ts +0 -241
  36. package/src/groups.ts +0 -141
  37. package/src/help/search/modal.de.ts +0 -33
  38. package/src/help/search/modal.en.ts +0 -33
  39. package/src/help/search/syntax.de.ts +0 -148
  40. package/src/help/search/syntax.en.ts +0 -145
  41. package/src/history.ts +0 -62
  42. package/src/import.ts +0 -114
  43. package/src/index.ts +0 -72
  44. package/src/keys.ts +0 -48
  45. package/src/links.test.ts +0 -99
  46. package/src/links.ts +0 -54
  47. package/src/login.test.ts +0 -240
  48. package/src/login.ts +0 -128
  49. package/src/loginInfo.ts +0 -43
  50. package/src/namespaceSuggestions.ts +0 -32
  51. package/src/namespaces.test.ts +0 -95
  52. package/src/namespaces.ts +0 -43
  53. package/src/notifications.ts +0 -183
  54. package/src/permissions.test.ts +0 -345
  55. package/src/permissions.ts +0 -202
  56. package/src/plugins.test.ts +0 -336
  57. package/src/plugins.ts +0 -259
  58. package/src/publicKeys.ts +0 -83
  59. package/src/repositories.test.ts +0 -508
  60. package/src/repositories.ts +0 -375
  61. package/src/repository-roles.test.ts +0 -229
  62. package/src/repository-roles.ts +0 -142
  63. package/src/reset.ts +0 -36
  64. package/src/search.ts +0 -153
  65. package/src/sources.test.ts +0 -233
  66. package/src/sources.ts +0 -136
  67. package/src/suggestions.ts +0 -47
  68. package/src/tags.test.ts +0 -272
  69. package/src/tags.ts +0 -118
  70. package/src/tests/createInfiniteCachingClient.ts +0 -37
  71. package/src/tests/createWrapper.tsx +0 -37
  72. package/src/tests/indexLinks.ts +0 -43
  73. package/src/urls.test.ts +0 -104
  74. package/src/urls.ts +0 -118
  75. package/src/usePluginCenterAuthInfo.ts +0 -91
  76. package/src/userSuggestions.ts +0 -32
  77. package/src/users.test.ts +0 -310
  78. package/src/users.ts +0 -240
  79. package/src/utils.ts +0 -29
package/src/base.ts DELETED
@@ -1,120 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { HalRepresentation, IndexResources, Link } from "@scm-manager/ui-types";
26
- import { useQuery } from "react-query";
27
- import { apiClient } from "./apiclient";
28
- import { useLegacyContext } from "./LegacyContext";
29
- import { MissingLinkError, UnauthorizedError } from "./errors";
30
- import { requiredLink } from "./links";
31
-
32
- export type ApiResult<T> = {
33
- isLoading: boolean;
34
- error: Error | null;
35
- data?: T;
36
- };
37
-
38
- export type ApiResultWithFetching<T> = ApiResult<T> & {
39
- isFetching: boolean;
40
- };
41
-
42
- export type DeleteFunction<T> = (entity: T) => void;
43
-
44
- export const useIndex = (): ApiResult<IndexResources> => {
45
- const legacy = useLegacyContext();
46
- return useQuery<IndexResources, Error>("index", () => apiClient.get("/").then((response) => response.json()), {
47
- onSuccess: (index) => {
48
- // ensure legacy code is notified
49
- if (legacy.onIndexFetched) {
50
- legacy.onIndexFetched(index);
51
- }
52
- },
53
- refetchOnMount: false,
54
- retry: (failureCount, error) => {
55
- // The index resource returns a 401 if the access token expired.
56
- // This only happens once because the error response automatically invalidates the cookie.
57
- // In this event, we have to try the request once again.
58
- return error instanceof UnauthorizedError && failureCount === 0;
59
- },
60
- });
61
- };
62
-
63
- export const useIndexLink = (name: string): string | undefined => {
64
- const { data } = useIndex();
65
- if (!data) {
66
- throw new Error("could not find index data");
67
- }
68
- const linkObject = data._links[name] as Link;
69
- if (linkObject && linkObject.href) {
70
- return linkObject.href;
71
- }
72
- };
73
-
74
- export const useIndexLinks = () => {
75
- const { data } = useIndex();
76
- if (!data) {
77
- throw new Error("could not find index data");
78
- }
79
- return data._links;
80
- };
81
-
82
- export const useRequiredIndexLink = (name: string): string => {
83
- const link = useIndexLink(name);
84
- if (!link) {
85
- throw new MissingLinkError(`Could not find link ${name} in index resource`);
86
- }
87
- return link;
88
- };
89
-
90
- export const useVersion = (): string => {
91
- const { data } = useIndex();
92
- if (!data) {
93
- throw new Error("could not find index data");
94
- }
95
- const { version } = data;
96
- if (!version) {
97
- throw new Error("could not find version in index data");
98
- }
99
- return version;
100
- };
101
-
102
- export const useIndexJsonResource = <T>(name: string): ApiResult<T> => {
103
- const link = useIndexLink(name);
104
- return useQuery<T, Error>(name, () => apiClient.get(link!).then((response) => response.json()), {
105
- enabled: !!link,
106
- });
107
- };
108
-
109
- export const useJsonResource = <T>(entity: HalRepresentation, name: string, key: string[]): ApiResult<T> =>
110
- useQuery<T, Error>(key, () => apiClient.get(requiredLink(entity, name)).then((response) => response.json()));
111
-
112
- export function fetchResourceFromLocationHeader(response: Response) {
113
- const location = response.headers.get("Location");
114
- if (!location) {
115
- throw new Error("Server does not return required Location header");
116
- }
117
- return apiClient.get(location);
118
- }
119
-
120
- export const getResponseJson = (response: Response) => response.json();
@@ -1,234 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import { Branch, BranchCollection, Repository } from "@scm-manager/ui-types";
25
- import fetchMock from "fetch-mock-jest";
26
- import { renderHook } from "@testing-library/react-hooks";
27
- import createWrapper from "./tests/createWrapper";
28
- import createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
29
- import { useBranch, useBranches, useCreateBranch, useDeleteBranch } from "./branches";
30
- import { act } from "react-test-renderer";
31
-
32
- describe("Test branches hooks", () => {
33
- const repository: Repository = {
34
- namespace: "hitchhiker",
35
- name: "heart-of-gold",
36
- type: "hg",
37
- _links: {
38
- branches: {
39
- href: "/hog/branches"
40
- }
41
- }
42
- };
43
-
44
- const develop: Branch = {
45
- name: "develop",
46
- revision: "42",
47
- lastCommitter: { name: "trillian" },
48
- _links: {
49
- delete: {
50
- href: "/hog/branches/develop"
51
- }
52
- }
53
- };
54
-
55
- const feature: Branch = {
56
- name: "feature/something-special",
57
- revision: "42",
58
- lastCommitter: { name: "trillian" },
59
- _links: {
60
- delete: {
61
- href: "/hog/branches/feature%2Fsomething-special"
62
- }
63
- }
64
- };
65
-
66
- const branches: BranchCollection = {
67
- _embedded: {
68
- branches: [develop]
69
- },
70
- _links: {}
71
- };
72
-
73
- const queryClient = createInfiniteCachingClient();
74
-
75
- beforeEach(() => {
76
- queryClient.clear();
77
- });
78
-
79
- afterEach(() => {
80
- fetchMock.reset();
81
- });
82
-
83
- describe("useBranches tests", () => {
84
- const fetchBrances = async () => {
85
- fetchMock.getOnce("/api/v2/hog/branches", branches);
86
-
87
- const { result, waitFor } = renderHook(() => useBranches(repository), {
88
- wrapper: createWrapper(undefined, queryClient)
89
- });
90
- await waitFor(() => {
91
- return !!result.current.data;
92
- });
93
-
94
- return result.current.data;
95
- };
96
-
97
- it("should return branches", async () => {
98
- const branches = await fetchBrances();
99
- expect(branches).toEqual(branches);
100
- });
101
-
102
- it("should add branches to cache", async () => {
103
- await fetchBrances();
104
-
105
- const data = queryClient.getQueryData<BranchCollection>([
106
- "repository",
107
- "hitchhiker",
108
- "heart-of-gold",
109
- "branches"
110
- ]);
111
- expect(data).toEqual(branches);
112
- });
113
- });
114
-
115
- describe("useBranch tests", () => {
116
- const fetchBranch = async (name: string, branch: Branch) => {
117
- fetchMock.getOnce("/api/v2/hog/branches/" + encodeURIComponent(name), branch);
118
-
119
- const { result, waitFor } = renderHook(() => useBranch(repository, name), {
120
- wrapper: createWrapper(undefined, queryClient)
121
- });
122
-
123
- expect(result.error).toBeUndefined();
124
-
125
- await waitFor(() => {
126
- return !!result.current.data;
127
- });
128
-
129
- return result.current.data;
130
- };
131
-
132
- it("should return branch", async () => {
133
- const branch = await fetchBranch("develop", develop);
134
- expect(branch).toEqual(develop);
135
- });
136
-
137
- it("should escape branch name", async () => {
138
- const branch = await fetchBranch("feature/something-special", feature);
139
- expect(branch).toEqual(feature);
140
- });
141
- });
142
-
143
- describe("useCreateBranch tests", () => {
144
- const createBranch = async () => {
145
- fetchMock.postOnce("/api/v2/hog/branches", {
146
- status: 201,
147
- headers: {
148
- Location: "/hog/branches/develop"
149
- }
150
- });
151
-
152
- fetchMock.getOnce("/api/v2/hog/branches/develop", develop);
153
-
154
- const { result, waitForNextUpdate } = renderHook(() => useCreateBranch(repository), {
155
- wrapper: createWrapper(undefined, queryClient)
156
- });
157
-
158
- await act(() => {
159
- const { create } = result.current;
160
- create({ name: "develop", parent: "main" });
161
- return waitForNextUpdate();
162
- });
163
-
164
- return result.current;
165
- };
166
-
167
- it("should create branch", async () => {
168
- const { branch } = await createBranch();
169
- expect(branch).toEqual(develop);
170
- });
171
-
172
- it("should cache created branch", async () => {
173
- await createBranch();
174
-
175
- const branch = queryClient.getQueryData<Branch>([
176
- "repository",
177
- "hitchhiker",
178
- "heart-of-gold",
179
- "branch",
180
- "develop"
181
- ]);
182
- expect(branch).toEqual(develop);
183
- });
184
-
185
- it("should invalidate cached branches list", async () => {
186
- queryClient.setQueryData(["repository", "hitchhiker", "heart-of-gold", "branches"], branches);
187
- await createBranch();
188
-
189
- const queryState = queryClient.getQueryState(["repository", "hitchhiker", "heart-of-gold", "branches"]);
190
- expect(queryState!.isInvalidated).toBe(true);
191
- });
192
- });
193
-
194
- describe("useDeleteBranch tests", () => {
195
- const deleteBranch = async () => {
196
- fetchMock.deleteOnce("/api/v2/hog/branches/develop", {
197
- status: 204
198
- });
199
-
200
- const { result, waitForNextUpdate } = renderHook(() => useDeleteBranch(repository), {
201
- wrapper: createWrapper(undefined, queryClient)
202
- });
203
-
204
- await act(() => {
205
- const { remove } = result.current;
206
- remove(develop);
207
- return waitForNextUpdate();
208
- });
209
-
210
- return result.current;
211
- };
212
-
213
- it("should delete branch", async () => {
214
- const { isDeleted } = await deleteBranch();
215
- expect(isDeleted).toBe(true);
216
- });
217
-
218
- it("should delete branch cache", async () => {
219
- queryClient.setQueryData(["repository", "hitchhiker", "heart-of-gold", "branch", "develop"], develop);
220
- await deleteBranch();
221
-
222
- const queryState = queryClient.getQueryState(["repository", "hitchhiker", "heart-of-gold", "branch", "develop"]);
223
- expect(queryState).toBeUndefined();
224
- });
225
-
226
- it("should invalidate cached branches list", async () => {
227
- queryClient.setQueryData(["repository", "hitchhiker", "heart-of-gold", "branches"], branches);
228
- await deleteBranch();
229
-
230
- const queryState = queryClient.getQueryState(["repository", "hitchhiker", "heart-of-gold", "branches"]);
231
- expect(queryState!.isInvalidated).toBe(true);
232
- });
233
- });
234
- });
package/src/branches.ts DELETED
@@ -1,201 +0,0 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import {
25
- Branch,
26
- BranchCollection,
27
- BranchCreation,
28
- BranchDetails,
29
- BranchDetailsCollection,
30
- Link,
31
- NamespaceAndName,
32
- Repository
33
- } from "@scm-manager/ui-types";
34
- import { requiredLink } from "./links";
35
- import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "react-query";
36
- import { ApiResult, ApiResultWithFetching } from "./base";
37
- import { branchQueryKey, repoQueryKey } from "./keys";
38
- import { apiClient } from "./apiclient";
39
- import { concat } from "./urls";
40
- import { useEffect } from "react";
41
-
42
- export const useBranches = (repository: Repository): ApiResult<BranchCollection> => {
43
- const queryClient = useQueryClient();
44
- const link = requiredLink(repository, "branches");
45
- return useQuery<BranchCollection, Error>(
46
- repoQueryKey(repository, "branches"),
47
- () => apiClient.get(link).then(response => response.json()),
48
- {
49
- onSuccess: () => {
50
- return queryClient.invalidateQueries(branchDetailsQueryKey(repository));
51
- }
52
- }
53
- // we do not populate the cache for a single branch,
54
- // because we have no pagination for branches and if we have a lot of them
55
- // the population slows us down
56
- );
57
- };
58
-
59
- export const useBranch = (repository: Repository, name: string): ApiResultWithFetching<Branch> => {
60
- const link = requiredLink(repository, "branches");
61
- return useQuery<Branch, Error>(branchQueryKey(repository, name), () =>
62
- apiClient.get(concat(link, encodeURIComponent(name))).then(response => response.json())
63
- );
64
- };
65
-
66
- function chunkBranches(branches: Branch[]) {
67
- const chunks: Branch[][] = [];
68
- const chunkSize = 5;
69
- let chunkIndex = 0;
70
- for (const branch of branches) {
71
- if (!chunks[chunkIndex]) {
72
- chunks[chunkIndex] = [];
73
- }
74
- chunks[chunkIndex].push(branch);
75
- if (chunks[chunkIndex].length >= chunkSize) {
76
- chunkIndex = chunkIndex + 1;
77
- }
78
- }
79
- return chunks;
80
- }
81
-
82
- const branchDetailsQueryKey = (repository: NamespaceAndName, branch: string | undefined = undefined) => {
83
- let branchName;
84
- if (!branch) {
85
- branchName = "_";
86
- } else {
87
- branchName = branch;
88
- }
89
- return [...repoQueryKey(repository), "branch-details", branchName];
90
- };
91
-
92
- export const useBranchDetailsCollection = (repository: Repository, branches: Branch[]) => {
93
- const link = requiredLink(repository, "branchDetailsCollection");
94
- const chunks = chunkBranches(branches);
95
- const queryClient = useQueryClient();
96
-
97
- const { data, isLoading, error, fetchNextPage } = useInfiniteQuery<
98
- BranchDetailsCollection,
99
- Error,
100
- BranchDetailsCollection
101
- >(
102
- branchDetailsQueryKey(repository),
103
- ({ pageParam = 0 }) => {
104
- const encodedBranches = chunks[pageParam]?.map(b => encodeURIComponent(b.name)).join("&branches=");
105
- return apiClient.get(concat(link, `?branches=${encodedBranches}`)).then(response => response.json());
106
- },
107
- {
108
- getNextPageParam: (lastPage, allPages) => {
109
- if (allPages.length >= chunks.length) {
110
- return undefined;
111
- }
112
- return allPages.length;
113
- },
114
- onSuccess: newData => {
115
- newData.pages
116
- .flatMap(d => d._embedded?.branchDetails)
117
- .filter(d => !!d)
118
- .forEach(d => queryClient.setQueryData(branchDetailsQueryKey(repository, d!.branchName), () => d));
119
- }
120
- }
121
- );
122
-
123
- useEffect(() => {
124
- fetchNextPage();
125
- }, [data, fetchNextPage]);
126
-
127
- return {
128
- data: data?.pages?.map(d => d._embedded?.branchDetails).flat(1),
129
- isLoading,
130
- error
131
- };
132
- };
133
-
134
- export const useBranchDetails = (repository: Repository, branch: Branch) => {
135
- const link = (branch._links.details as Link).href;
136
- const queryKey = branchDetailsQueryKey(repository, branch.name);
137
- return useQuery<BranchDetails, Error>(queryKey, () => apiClient.get(link).then(response => response.json()));
138
- };
139
-
140
- const createBranch = (link: string) => {
141
- return (branch: BranchCreation) => {
142
- return apiClient
143
- .post(link, branch, "application/vnd.scmm-branchRequest+json;v=2")
144
- .then(response => {
145
- const location = response.headers.get("Location");
146
- if (!location) {
147
- throw new Error("Server does not return required Location header");
148
- }
149
- return apiClient.get(location);
150
- })
151
- .then(response => response.json());
152
- };
153
- };
154
-
155
- export const useCreateBranch = (repository: Repository) => {
156
- const queryClient = useQueryClient();
157
- const link = requiredLink(repository, "branches");
158
- const { mutate, isLoading, error, data } = useMutation<Branch, Error, BranchCreation>(createBranch(link), {
159
- onSuccess: async branch => {
160
- queryClient.setQueryData(branchQueryKey(repository, branch), branch);
161
- await queryClient.invalidateQueries(repoQueryKey(repository, "branches"));
162
- }
163
- });
164
- return {
165
- create: (branch: BranchCreation) => mutate(branch),
166
- isLoading,
167
- error,
168
- branch: data
169
- };
170
- };
171
-
172
- export const useDeleteBranch = (repository: Repository) => {
173
- const queryClient = useQueryClient();
174
- const { mutate, isLoading, error, data } = useMutation<unknown, Error, Branch>(
175
- branch => {
176
- const deleteUrl = (branch._links.delete as Link).href;
177
- return apiClient.delete(deleteUrl);
178
- },
179
- {
180
- onSuccess: async (_, branch) => {
181
- queryClient.removeQueries(branchQueryKey(repository, branch));
182
- await queryClient.invalidateQueries(repoQueryKey(repository, "branches"));
183
- }
184
- }
185
- );
186
- return {
187
- remove: (branch: Branch) => mutate(branch),
188
- isLoading,
189
- error,
190
- isDeleted: !!data
191
- };
192
- };
193
-
194
- type DefaultBranch = { defaultBranch: string };
195
-
196
- export const useDefaultBranch = (repository: Repository): ApiResult<DefaultBranch> => {
197
- const link = requiredLink(repository, "defaultBranch");
198
- return useQuery<DefaultBranch, Error>(branchQueryKey(repository, "__default-branch"), () =>
199
- apiClient.get(link).then(response => response.json())
200
- );
201
- };