@scm-manager/ui-api 2.20.1-20210616-114029 → 2.20.1
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.
- package/package.json +2 -2
- package/src/base.ts +6 -21
- package/src/branches.test.ts +19 -19
- package/src/branches.ts +1 -1
- package/src/changesets.ts +1 -1
- package/src/diff.ts +8 -14
- package/src/import.ts +5 -87
- package/src/index.ts +0 -7
- package/src/links.test.ts +0 -36
- package/src/links.ts +2 -20
- package/src/permissions.ts +16 -62
- package/src/plugins.test.ts +31 -34
- package/src/repositories.ts +34 -63
- package/src/users.ts +21 -63
- package/src/annotations.ts +0 -40
- package/src/apiKeys.ts +0 -82
- package/src/contentType.ts +0 -49
- package/src/fileContent.ts +0 -33
- package/src/history.ts +0 -62
- package/src/publicKeys.ts +0 -83
- package/src/search.ts +0 -56
package/src/plugins.test.ts
CHANGED
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
useInstallPlugin,
|
|
35
35
|
usePendingPlugins,
|
|
36
36
|
useUninstallPlugin,
|
|
37
|
-
useUpdatePlugins
|
|
37
|
+
useUpdatePlugins
|
|
38
38
|
} from "./plugins";
|
|
39
39
|
import { act } from "react-test-renderer";
|
|
40
40
|
|
|
@@ -48,13 +48,12 @@ describe("Test plugin hooks", () => {
|
|
|
48
48
|
pending: false,
|
|
49
49
|
dependencies: [],
|
|
50
50
|
optionalDependencies: [],
|
|
51
|
-
type: "SCM",
|
|
52
51
|
_links: {
|
|
53
52
|
install: { href: "/plugins/available/heart-of-gold-plugin/install" },
|
|
54
53
|
installWithRestart: {
|
|
55
|
-
href: "/plugins/available/heart-of-gold-plugin/install?restart=true"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
54
|
+
href: "/plugins/available/heart-of-gold-plugin/install?restart=true"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
58
57
|
};
|
|
59
58
|
|
|
60
59
|
const installedPlugin: Plugin = {
|
|
@@ -67,24 +66,23 @@ describe("Test plugin hooks", () => {
|
|
|
67
66
|
markedForUninstall: false,
|
|
68
67
|
dependencies: [],
|
|
69
68
|
optionalDependencies: [],
|
|
70
|
-
type: "SCM",
|
|
71
69
|
_links: {
|
|
72
70
|
self: {
|
|
73
|
-
href: "/plugins/installed/heart-of-gold-plugin"
|
|
71
|
+
href: "/plugins/installed/heart-of-gold-plugin"
|
|
74
72
|
},
|
|
75
73
|
update: {
|
|
76
|
-
href: "/plugins/available/heart-of-gold-plugin/install"
|
|
74
|
+
href: "/plugins/available/heart-of-gold-plugin/install"
|
|
77
75
|
},
|
|
78
76
|
updateWithRestart: {
|
|
79
|
-
href: "/plugins/available/heart-of-gold-plugin/install?restart=true"
|
|
77
|
+
href: "/plugins/available/heart-of-gold-plugin/install?restart=true"
|
|
80
78
|
},
|
|
81
79
|
uninstall: {
|
|
82
|
-
href: "/plugins/installed/heart-of-gold-plugin/uninstall"
|
|
80
|
+
href: "/plugins/installed/heart-of-gold-plugin/uninstall"
|
|
83
81
|
},
|
|
84
82
|
uninstallWithRestart: {
|
|
85
|
-
href: "/plugins/installed/heart-of-gold-plugin/uninstall?restart=true"
|
|
86
|
-
}
|
|
87
|
-
}
|
|
83
|
+
href: "/plugins/installed/heart-of-gold-plugin/uninstall?restart=true"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
88
86
|
};
|
|
89
87
|
|
|
90
88
|
const installedCorePlugin: Plugin = {
|
|
@@ -95,25 +93,24 @@ describe("Test plugin hooks", () => {
|
|
|
95
93
|
name: "heart-of-gold-core-plugin",
|
|
96
94
|
pending: false,
|
|
97
95
|
markedForUninstall: false,
|
|
98
|
-
type: "SCM",
|
|
99
96
|
dependencies: [],
|
|
100
97
|
optionalDependencies: [],
|
|
101
98
|
_links: {
|
|
102
99
|
self: {
|
|
103
|
-
href: "/plugins/installed/heart-of-gold-core-plugin"
|
|
104
|
-
}
|
|
105
|
-
}
|
|
100
|
+
href: "/plugins/installed/heart-of-gold-core-plugin"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
106
103
|
};
|
|
107
104
|
|
|
108
105
|
const createPluginCollection = (plugins: Plugin[]): PluginCollection => ({
|
|
109
106
|
_links: {
|
|
110
107
|
update: {
|
|
111
|
-
href: "/plugins/update"
|
|
112
|
-
}
|
|
108
|
+
href: "/plugins/update"
|
|
109
|
+
}
|
|
113
110
|
},
|
|
114
111
|
_embedded: {
|
|
115
|
-
plugins
|
|
116
|
-
}
|
|
112
|
+
plugins
|
|
113
|
+
}
|
|
117
114
|
});
|
|
118
115
|
|
|
119
116
|
const createPendingPlugins = (
|
|
@@ -125,8 +122,8 @@ describe("Test plugin hooks", () => {
|
|
|
125
122
|
_embedded: {
|
|
126
123
|
new: newPlugins,
|
|
127
124
|
update: updatePlugins,
|
|
128
|
-
uninstall: uninstallPlugins
|
|
129
|
-
}
|
|
125
|
+
uninstall: uninstallPlugins
|
|
126
|
+
}
|
|
130
127
|
});
|
|
131
128
|
|
|
132
129
|
afterEach(() => fetchMock.reset());
|
|
@@ -138,7 +135,7 @@ describe("Test plugin hooks", () => {
|
|
|
138
135
|
setIndexLink(queryClient, "availablePlugins", "/availablePlugins");
|
|
139
136
|
fetchMock.get("/api/v2/availablePlugins", availablePlugins);
|
|
140
137
|
const { result, waitFor } = renderHook(() => useAvailablePlugins(), {
|
|
141
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
138
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
142
139
|
});
|
|
143
140
|
await waitFor(() => !!result.current.data);
|
|
144
141
|
expect(result.current.data).toEqual(availablePlugins);
|
|
@@ -152,7 +149,7 @@ describe("Test plugin hooks", () => {
|
|
|
152
149
|
setIndexLink(queryClient, "installedPlugins", "/installedPlugins");
|
|
153
150
|
fetchMock.get("/api/v2/installedPlugins", installedPlugins);
|
|
154
151
|
const { result, waitFor } = renderHook(() => useInstalledPlugins(), {
|
|
155
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
152
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
156
153
|
});
|
|
157
154
|
await waitFor(() => !!result.current.data);
|
|
158
155
|
expect(result.current.data).toEqual(installedPlugins);
|
|
@@ -166,7 +163,7 @@ describe("Test plugin hooks", () => {
|
|
|
166
163
|
setIndexLink(queryClient, "pendingPlugins", "/pendingPlugins");
|
|
167
164
|
fetchMock.get("/api/v2/pendingPlugins", pendingPlugins);
|
|
168
165
|
const { result, waitFor } = renderHook(() => usePendingPlugins(), {
|
|
169
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
166
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
170
167
|
});
|
|
171
168
|
await waitFor(() => !!result.current.data);
|
|
172
169
|
expect(result.current.data).toEqual(pendingPlugins);
|
|
@@ -182,7 +179,7 @@ describe("Test plugin hooks", () => {
|
|
|
182
179
|
fetchMock.post("/api/v2/plugins/available/heart-of-gold-plugin/install?restart=true", installedPlugin);
|
|
183
180
|
fetchMock.get("/api/v2/", "Restarted");
|
|
184
181
|
const { result, waitFor, waitForNextUpdate } = renderHook(() => useInstallPlugin(), {
|
|
185
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
182
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
186
183
|
});
|
|
187
184
|
await act(() => {
|
|
188
185
|
const { install } = result.current;
|
|
@@ -202,7 +199,7 @@ describe("Test plugin hooks", () => {
|
|
|
202
199
|
queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
|
|
203
200
|
fetchMock.post("/api/v2/plugins/available/heart-of-gold-plugin/install", installedPlugin);
|
|
204
201
|
const { result, waitForNextUpdate } = renderHook(() => useInstallPlugin(), {
|
|
205
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
202
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
206
203
|
});
|
|
207
204
|
await act(() => {
|
|
208
205
|
const { install } = result.current;
|
|
@@ -224,7 +221,7 @@ describe("Test plugin hooks", () => {
|
|
|
224
221
|
fetchMock.post("/api/v2/plugins/installed/heart-of-gold-plugin/uninstall?restart=true", availablePlugin);
|
|
225
222
|
fetchMock.get("/api/v2/", "Restarted");
|
|
226
223
|
const { result, waitForNextUpdate, waitFor } = renderHook(() => useUninstallPlugin(), {
|
|
227
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
224
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
228
225
|
});
|
|
229
226
|
await act(() => {
|
|
230
227
|
const { uninstall } = result.current;
|
|
@@ -244,7 +241,7 @@ describe("Test plugin hooks", () => {
|
|
|
244
241
|
queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
|
|
245
242
|
fetchMock.post("/api/v2/plugins/installed/heart-of-gold-plugin/uninstall", availablePlugin);
|
|
246
243
|
const { result, waitForNextUpdate } = renderHook(() => useUninstallPlugin(), {
|
|
247
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
244
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
248
245
|
});
|
|
249
246
|
await act(() => {
|
|
250
247
|
const { uninstall } = result.current;
|
|
@@ -266,7 +263,7 @@ describe("Test plugin hooks", () => {
|
|
|
266
263
|
fetchMock.post("/api/v2/plugins/available/heart-of-gold-plugin/install?restart=true", installedPlugin);
|
|
267
264
|
fetchMock.get("/api/v2/", "Restarted");
|
|
268
265
|
const { result, waitForNextUpdate, waitFor } = renderHook(() => useUpdatePlugins(), {
|
|
269
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
266
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
270
267
|
});
|
|
271
268
|
await act(() => {
|
|
272
269
|
const { update } = result.current;
|
|
@@ -285,7 +282,7 @@ describe("Test plugin hooks", () => {
|
|
|
285
282
|
queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
|
|
286
283
|
fetchMock.post("/api/v2/plugins/update", installedPlugin);
|
|
287
284
|
const { result, waitForNextUpdate } = renderHook(() => useUpdatePlugins(), {
|
|
288
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
285
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
289
286
|
});
|
|
290
287
|
await act(() => {
|
|
291
288
|
const { update } = result.current;
|
|
@@ -303,7 +300,7 @@ describe("Test plugin hooks", () => {
|
|
|
303
300
|
queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
|
|
304
301
|
fetchMock.post("/api/v2/plugins/update", installedPlugin);
|
|
305
302
|
const { result, waitForNextUpdate } = renderHook(() => useUpdatePlugins(), {
|
|
306
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
303
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
307
304
|
});
|
|
308
305
|
await act(() => {
|
|
309
306
|
const { update } = result.current;
|
|
@@ -321,7 +318,7 @@ describe("Test plugin hooks", () => {
|
|
|
321
318
|
queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
|
|
322
319
|
fetchMock.post("/api/v2/plugins/available/heart-of-gold-plugin/install", installedPlugin);
|
|
323
320
|
const { result, waitForNextUpdate } = renderHook(() => useUpdatePlugins(), {
|
|
324
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
321
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
325
322
|
});
|
|
326
323
|
await act(() => {
|
|
327
324
|
const { update } = result.current;
|
package/src/repositories.ts
CHANGED
|
@@ -30,17 +30,17 @@ import {
|
|
|
30
30
|
Repository,
|
|
31
31
|
RepositoryCollection,
|
|
32
32
|
RepositoryCreation,
|
|
33
|
-
RepositoryTypeCollection
|
|
33
|
+
RepositoryTypeCollection
|
|
34
34
|
} from "@scm-manager/ui-types";
|
|
35
35
|
import { useMutation, useQuery, useQueryClient } from "react-query";
|
|
36
36
|
import { apiClient } from "./apiclient";
|
|
37
37
|
import { ApiResult, useIndexJsonResource, useRequiredIndexLink } from "./base";
|
|
38
38
|
import { createQueryString } from "./utils";
|
|
39
|
-
import {
|
|
39
|
+
import { requiredLink } from "./links";
|
|
40
40
|
import { repoQueryKey } from "./keys";
|
|
41
41
|
import { concat } from "./urls";
|
|
42
42
|
import { useEffect, useState } from "react";
|
|
43
|
-
import {
|
|
43
|
+
import { NotFoundError } from "./errors";
|
|
44
44
|
|
|
45
45
|
export type UseRepositoriesRequest = {
|
|
46
46
|
namespace?: Namespace;
|
|
@@ -56,7 +56,7 @@ export const useRepositories = (request?: UseRepositoriesRequest): ApiResult<Rep
|
|
|
56
56
|
const link = namespaceLink || indexLink;
|
|
57
57
|
|
|
58
58
|
const queryParams: Record<string, string> = {
|
|
59
|
-
sortBy: "namespaceAndName"
|
|
59
|
+
sortBy: "namespaceAndName"
|
|
60
60
|
};
|
|
61
61
|
if (request?.search) {
|
|
62
62
|
queryParams.q = request.search;
|
|
@@ -66,7 +66,7 @@ export const useRepositories = (request?: UseRepositoriesRequest): ApiResult<Rep
|
|
|
66
66
|
}
|
|
67
67
|
return useQuery<RepositoryCollection, Error>(
|
|
68
68
|
["repositories", request?.namespace?.namespace, request?.search || "", request?.page || 0],
|
|
69
|
-
() => apiClient.get(`${link}?${createQueryString(queryParams)}`).then(
|
|
69
|
+
() => apiClient.get(`${link}?${createQueryString(queryParams)}`).then(response => response.json()),
|
|
70
70
|
{
|
|
71
71
|
enabled: !request?.disabled,
|
|
72
72
|
onSuccess: (repositories: RepositoryCollection) => {
|
|
@@ -74,7 +74,7 @@ export const useRepositories = (request?: UseRepositoriesRequest): ApiResult<Rep
|
|
|
74
74
|
repositories._embedded.repositories.forEach((repository: Repository) => {
|
|
75
75
|
queryClient.setQueryData(["repository", repository.namespace, repository.name], repository);
|
|
76
76
|
});
|
|
77
|
-
}
|
|
77
|
+
}
|
|
78
78
|
}
|
|
79
79
|
);
|
|
80
80
|
};
|
|
@@ -92,14 +92,14 @@ const createRepository = (link: string) => {
|
|
|
92
92
|
}
|
|
93
93
|
return apiClient
|
|
94
94
|
.post(createLink, request.repository, "application/vnd.scmm-repository+json;v=2")
|
|
95
|
-
.then(
|
|
95
|
+
.then(response => {
|
|
96
96
|
const location = response.headers.get("Location");
|
|
97
97
|
if (!location) {
|
|
98
98
|
throw new Error("Server does not return required Location header");
|
|
99
99
|
}
|
|
100
100
|
return apiClient.get(location);
|
|
101
101
|
})
|
|
102
|
-
.then(
|
|
102
|
+
.then(response => response.json());
|
|
103
103
|
};
|
|
104
104
|
};
|
|
105
105
|
|
|
@@ -111,10 +111,10 @@ export const useCreateRepository = () => {
|
|
|
111
111
|
const { mutate, data, isLoading, error } = useMutation<Repository, Error, CreateRepositoryRequest>(
|
|
112
112
|
createRepository(link),
|
|
113
113
|
{
|
|
114
|
-
onSuccess:
|
|
114
|
+
onSuccess: repository => {
|
|
115
115
|
queryClient.setQueryData(["repository", repository.namespace, repository.name], repository);
|
|
116
116
|
return queryClient.invalidateQueries(["repositories"]);
|
|
117
|
-
}
|
|
117
|
+
}
|
|
118
118
|
}
|
|
119
119
|
);
|
|
120
120
|
return {
|
|
@@ -123,7 +123,7 @@ export const useCreateRepository = () => {
|
|
|
123
123
|
},
|
|
124
124
|
isLoading,
|
|
125
125
|
error,
|
|
126
|
-
repository: data
|
|
126
|
+
repository: data
|
|
127
127
|
};
|
|
128
128
|
};
|
|
129
129
|
|
|
@@ -133,7 +133,7 @@ export const useRepositoryTypes = () => useIndexJsonResource<RepositoryTypeColle
|
|
|
133
133
|
export const useRepository = (namespace: string, name: string): ApiResult<Repository> => {
|
|
134
134
|
const link = useRequiredIndexLink("repositories");
|
|
135
135
|
return useQuery<Repository, Error>(["repository", namespace, name], () =>
|
|
136
|
-
apiClient.get(concat(link, namespace, name)).then(
|
|
136
|
+
apiClient.get(concat(link, namespace, name)).then(response => response.json())
|
|
137
137
|
);
|
|
138
138
|
};
|
|
139
139
|
|
|
@@ -144,7 +144,7 @@ export type UseDeleteRepositoryOptions = {
|
|
|
144
144
|
export const useDeleteRepository = (options?: UseDeleteRepositoryOptions) => {
|
|
145
145
|
const queryClient = useQueryClient();
|
|
146
146
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
147
|
-
|
|
147
|
+
repository => {
|
|
148
148
|
const link = requiredLink(repository, "delete");
|
|
149
149
|
return apiClient.delete(link);
|
|
150
150
|
},
|
|
@@ -155,21 +155,21 @@ export const useDeleteRepository = (options?: UseDeleteRepositoryOptions) => {
|
|
|
155
155
|
}
|
|
156
156
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
157
157
|
await queryClient.invalidateQueries(["repositories"]);
|
|
158
|
-
}
|
|
158
|
+
}
|
|
159
159
|
}
|
|
160
160
|
);
|
|
161
161
|
return {
|
|
162
162
|
remove: (repository: Repository) => mutate(repository),
|
|
163
163
|
isLoading,
|
|
164
164
|
error,
|
|
165
|
-
isDeleted: !!data
|
|
165
|
+
isDeleted: !!data
|
|
166
166
|
};
|
|
167
167
|
};
|
|
168
168
|
|
|
169
169
|
export const useUpdateRepository = () => {
|
|
170
170
|
const queryClient = useQueryClient();
|
|
171
171
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
172
|
-
|
|
172
|
+
repository => {
|
|
173
173
|
const link = requiredLink(repository, "update");
|
|
174
174
|
return apiClient.put(link, repository, "application/vnd.scmm-repository+json;v=2");
|
|
175
175
|
},
|
|
@@ -177,21 +177,21 @@ export const useUpdateRepository = () => {
|
|
|
177
177
|
onSuccess: async (_, repository) => {
|
|
178
178
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
179
179
|
await queryClient.invalidateQueries(["repositories"]);
|
|
180
|
-
}
|
|
180
|
+
}
|
|
181
181
|
}
|
|
182
182
|
);
|
|
183
183
|
return {
|
|
184
184
|
update: (repository: Repository) => mutate(repository),
|
|
185
185
|
isLoading,
|
|
186
186
|
error,
|
|
187
|
-
isUpdated: !!data
|
|
187
|
+
isUpdated: !!data
|
|
188
188
|
};
|
|
189
189
|
};
|
|
190
190
|
|
|
191
191
|
export const useArchiveRepository = () => {
|
|
192
192
|
const queryClient = useQueryClient();
|
|
193
193
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
194
|
-
|
|
194
|
+
repository => {
|
|
195
195
|
const link = requiredLink(repository, "archive");
|
|
196
196
|
return apiClient.post(link);
|
|
197
197
|
},
|
|
@@ -199,21 +199,21 @@ export const useArchiveRepository = () => {
|
|
|
199
199
|
onSuccess: async (_, repository) => {
|
|
200
200
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
201
201
|
await queryClient.invalidateQueries(["repositories"]);
|
|
202
|
-
}
|
|
202
|
+
}
|
|
203
203
|
}
|
|
204
204
|
);
|
|
205
205
|
return {
|
|
206
206
|
archive: (repository: Repository) => mutate(repository),
|
|
207
207
|
isLoading,
|
|
208
208
|
error,
|
|
209
|
-
isArchived: !!data
|
|
209
|
+
isArchived: !!data
|
|
210
210
|
};
|
|
211
211
|
};
|
|
212
212
|
|
|
213
213
|
export const useUnarchiveRepository = () => {
|
|
214
214
|
const queryClient = useQueryClient();
|
|
215
215
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
216
|
-
|
|
216
|
+
repository => {
|
|
217
217
|
const link = requiredLink(repository, "unarchive");
|
|
218
218
|
return apiClient.post(link);
|
|
219
219
|
},
|
|
@@ -221,35 +221,35 @@ export const useUnarchiveRepository = () => {
|
|
|
221
221
|
onSuccess: async (_, repository) => {
|
|
222
222
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
223
223
|
await queryClient.invalidateQueries(["repositories"]);
|
|
224
|
-
}
|
|
224
|
+
}
|
|
225
225
|
}
|
|
226
226
|
);
|
|
227
227
|
return {
|
|
228
228
|
unarchive: (repository: Repository) => mutate(repository),
|
|
229
229
|
isLoading,
|
|
230
230
|
error,
|
|
231
|
-
isUnarchived: !!data
|
|
231
|
+
isUnarchived: !!data
|
|
232
232
|
};
|
|
233
233
|
};
|
|
234
234
|
|
|
235
235
|
export const useRunHealthCheck = () => {
|
|
236
236
|
const queryClient = useQueryClient();
|
|
237
237
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
|
|
238
|
-
|
|
238
|
+
repository => {
|
|
239
239
|
const link = requiredLink(repository, "runHealthCheck");
|
|
240
240
|
return apiClient.post(link);
|
|
241
241
|
},
|
|
242
242
|
{
|
|
243
243
|
onSuccess: async (_, repository) => {
|
|
244
244
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
245
|
-
}
|
|
245
|
+
}
|
|
246
246
|
}
|
|
247
247
|
);
|
|
248
248
|
return {
|
|
249
249
|
runHealthCheck: (repository: Repository) => mutate(repository),
|
|
250
250
|
isLoading,
|
|
251
251
|
error,
|
|
252
|
-
isRunning: !!data
|
|
252
|
+
isRunning: !!data
|
|
253
253
|
};
|
|
254
254
|
};
|
|
255
255
|
|
|
@@ -258,14 +258,14 @@ export const useExportInfo = (repository: Repository): ApiResult<ExportInfo> =>
|
|
|
258
258
|
//TODO Refetch while exporting to update the page
|
|
259
259
|
const { isLoading, error, data } = useQuery<ExportInfo, Error>(
|
|
260
260
|
["repository", repository.namespace, repository.name, "exportInfo"],
|
|
261
|
-
() => apiClient.get(link).then(
|
|
261
|
+
() => apiClient.get(link).then(response => response.json()),
|
|
262
262
|
{}
|
|
263
263
|
);
|
|
264
264
|
|
|
265
265
|
return {
|
|
266
266
|
isLoading,
|
|
267
267
|
error: error instanceof NotFoundError ? null : error,
|
|
268
|
-
data
|
|
268
|
+
data
|
|
269
269
|
};
|
|
270
270
|
};
|
|
271
271
|
|
|
@@ -308,14 +308,14 @@ export const useExportRepository = () => {
|
|
|
308
308
|
const id = setInterval(() => {
|
|
309
309
|
apiClient
|
|
310
310
|
.get(infolink)
|
|
311
|
-
.then(
|
|
311
|
+
.then(r => r.json())
|
|
312
312
|
.then((info: ExportInfo) => {
|
|
313
313
|
if (info._links.download) {
|
|
314
314
|
clearInterval(id);
|
|
315
315
|
resolve(info);
|
|
316
316
|
}
|
|
317
317
|
})
|
|
318
|
-
.catch(
|
|
318
|
+
.catch(e => {
|
|
319
319
|
clearInterval(id);
|
|
320
320
|
reject(e);
|
|
321
321
|
});
|
|
@@ -328,49 +328,20 @@ export const useExportRepository = () => {
|
|
|
328
328
|
onSuccess: async (_, { repository }) => {
|
|
329
329
|
await queryClient.invalidateQueries(repoQueryKey(repository));
|
|
330
330
|
await queryClient.invalidateQueries(["repositories"]);
|
|
331
|
-
}
|
|
331
|
+
}
|
|
332
332
|
}
|
|
333
333
|
);
|
|
334
334
|
return {
|
|
335
335
|
exportRepository: (repository: Repository, options: ExportOptions) => mutate({ repository, options }),
|
|
336
336
|
isLoading,
|
|
337
337
|
error,
|
|
338
|
-
data
|
|
338
|
+
data
|
|
339
339
|
};
|
|
340
340
|
};
|
|
341
341
|
|
|
342
342
|
export const usePaths = (repository: Repository, revision: string): ApiResult<Paths> => {
|
|
343
343
|
const link = requiredLink(repository, "paths").replace("{revision}", revision);
|
|
344
344
|
return useQuery<Paths, Error>(repoQueryKey(repository, "paths", revision), () =>
|
|
345
|
-
apiClient.get(link).then(
|
|
345
|
+
apiClient.get(link).then(response => response.json())
|
|
346
346
|
);
|
|
347
347
|
};
|
|
348
|
-
|
|
349
|
-
type RenameRepositoryRequest = {
|
|
350
|
-
name: string;
|
|
351
|
-
namespace: string;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
export const useRenameRepository = (repository: Repository) => {
|
|
355
|
-
const queryClient = useQueryClient();
|
|
356
|
-
|
|
357
|
-
const url = objectLink(repository, "renameWithNamespace") || objectLink(repository, "rename");
|
|
358
|
-
|
|
359
|
-
if (!url) {
|
|
360
|
-
throw new MissingLinkError(`could not find rename link on repository ${repository.namespace}/${repository.name}`);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, RenameRepositoryRequest>(
|
|
364
|
-
({ name, namespace }) => apiClient.post(url, { namespace, name }, "application/vnd.scmm-repository+json;v=2"),
|
|
365
|
-
{
|
|
366
|
-
onSuccess: () => queryClient.removeQueries(repoQueryKey(repository))
|
|
367
|
-
}
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
return {
|
|
371
|
-
renameRepository: (namespace: string, name: string) => mutate({ namespace, name }),
|
|
372
|
-
isLoading,
|
|
373
|
-
error,
|
|
374
|
-
isRenamed: !!data,
|
|
375
|
-
};
|
|
376
|
-
};
|