@scm-manager/ui-api 2.33.1-20220411-113741 → 2.34.0

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/src/plugins.ts CHANGED
@@ -41,29 +41,27 @@ const waitForRestartAfter = (
41
41
  const endTime = Number(new Date()) + 4 * 60 * 1000;
42
42
  let started = false;
43
43
 
44
- const executor =
45
- <T = any>(data: T) =>
46
- (resolve: (result: T) => void, reject: (error: Error) => void) => {
47
- // we need some initial delay
48
- if (!started) {
49
- started = true;
50
- setTimeout(executor(data), initialDelay, resolve, reject);
51
- } else {
52
- apiClient
53
- .get("")
54
- .then(() => resolve(data))
55
- .catch(() => {
56
- if (Number(new Date()) < endTime) {
57
- setTimeout(executor(data), timeout, resolve, reject);
58
- } else {
59
- reject(new Error("timeout reached"));
60
- }
61
- });
62
- }
63
- };
44
+ const executor = <T = any>(data: T) => (resolve: (result: T) => void, reject: (error: Error) => void) => {
45
+ // we need some initial delay
46
+ if (!started) {
47
+ started = true;
48
+ setTimeout(executor(data), initialDelay, resolve, reject);
49
+ } else {
50
+ apiClient
51
+ .get("")
52
+ .then(() => resolve(data))
53
+ .catch(() => {
54
+ if (Number(new Date()) < endTime) {
55
+ setTimeout(executor(data), timeout, resolve, reject);
56
+ } else {
57
+ reject(new Error("timeout reached"));
58
+ }
59
+ });
60
+ }
61
+ };
64
62
 
65
63
  return promise
66
- .catch((err) => {
64
+ .catch(err => {
67
65
  if (err instanceof BadGatewayError) {
68
66
  // in some rare cases the reverse proxy stops forwarding traffic to scm before the response is returned
69
67
  // in such a case the reverse proxy returns 502 (bad gateway), so we treat 502 not as error
@@ -71,7 +69,7 @@ const waitForRestartAfter = (
71
69
  }
72
70
  throw err;
73
71
  })
74
- .then((data) => new Promise<void>(executor(data)));
72
+ .then(data => new Promise<void>(executor(data)));
75
73
  };
76
74
 
77
75
  export type UseAvailablePluginsOptions = {
@@ -82,10 +80,10 @@ export const useAvailablePlugins = ({ enabled }: UseAvailablePluginsOptions = {}
82
80
  const indexLink = useRequiredIndexLink("availablePlugins");
83
81
  return useQuery<PluginCollection, Error>(
84
82
  ["plugins", "available"],
85
- () => apiClient.get(indexLink).then((response) => response.json()),
83
+ () => apiClient.get(indexLink).then(response => response.json()),
86
84
  {
87
85
  enabled,
88
- retry: 3,
86
+ retry: 3
89
87
  }
90
88
  );
91
89
  };
@@ -98,10 +96,10 @@ export const useInstalledPlugins = ({ enabled }: UseInstalledPluginsOptions = {}
98
96
  const indexLink = useRequiredIndexLink("installedPlugins");
99
97
  return useQuery<PluginCollection, Error>(
100
98
  ["plugins", "installed"],
101
- () => apiClient.get(indexLink).then((response) => response.json()),
99
+ () => apiClient.get(indexLink).then(response => response.json()),
102
100
  {
103
101
  enabled,
104
- retry: 3,
102
+ retry: 3
105
103
  }
106
104
  );
107
105
  };
@@ -110,10 +108,10 @@ export const usePendingPlugins = (): ApiResult<PendingPlugins> => {
110
108
  const indexLink = useIndexLink("pendingPlugins");
111
109
  return useQuery<PendingPlugins, Error>(
112
110
  ["plugins", "pending"],
113
- () => apiClient.get(indexLink!).then((response) => response.json()),
111
+ () => apiClient.get(indexLink!).then(response => response.json()),
114
112
  {
115
113
  enabled: !!indexLink,
116
- retry: 3,
114
+ retry: 3
117
115
  }
118
116
  );
119
117
  };
@@ -145,19 +143,19 @@ export const useInstallPlugin = () => {
145
143
  return promise;
146
144
  },
147
145
  {
148
- onSuccess: () => queryClient.invalidateQueries("plugins"),
146
+ onSuccess: () => queryClient.invalidateQueries("plugins")
149
147
  }
150
148
  );
151
149
  return {
152
150
  install: (plugin: Plugin, restartOptions: RestartOptions = {}) =>
153
151
  mutate({
154
152
  plugin,
155
- restartOptions,
153
+ restartOptions
156
154
  }),
157
155
  isLoading,
158
156
  error,
159
157
  data,
160
- isInstalled: !!data,
158
+ isInstalled: !!data
161
159
  };
162
160
  };
163
161
 
@@ -172,18 +170,18 @@ export const useUninstallPlugin = () => {
172
170
  return promise;
173
171
  },
174
172
  {
175
- onSuccess: () => queryClient.invalidateQueries("plugins"),
173
+ onSuccess: () => queryClient.invalidateQueries("plugins")
176
174
  }
177
175
  );
178
176
  return {
179
177
  uninstall: (plugin: Plugin, restartOptions: RestartOptions = {}) =>
180
178
  mutate({
181
179
  plugin,
182
- restartOptions,
180
+ restartOptions
183
181
  }),
184
182
  isLoading,
185
183
  error,
186
- isUninstalled: !!data,
184
+ isUninstalled: !!data
187
185
  };
188
186
  };
189
187
 
@@ -206,18 +204,18 @@ export const useUpdatePlugins = () => {
206
204
  return promise;
207
205
  },
208
206
  {
209
- onSuccess: () => queryClient.invalidateQueries("plugins"),
207
+ onSuccess: () => queryClient.invalidateQueries("plugins")
210
208
  }
211
209
  );
212
210
  return {
213
211
  update: (plugin: Plugin | PluginCollection, restartOptions: RestartOptions = {}) =>
214
212
  mutate({
215
213
  plugins: plugin,
216
- restartOptions,
214
+ restartOptions
217
215
  }),
218
216
  isLoading,
219
217
  error,
220
- isUpdated: !!data,
218
+ isUpdated: !!data
221
219
  };
222
220
  };
223
221
 
@@ -232,7 +230,7 @@ export const useExecutePendingPlugins = () => {
232
230
  ({ pending, restartOptions }) =>
233
231
  waitForRestartAfter(apiClient.post(requiredLink(pending, "execute")), restartOptions),
234
232
  {
235
- onSuccess: () => queryClient.invalidateQueries("plugins"),
233
+ onSuccess: () => queryClient.invalidateQueries("plugins")
236
234
  }
237
235
  );
238
236
  return {
@@ -240,22 +238,22 @@ export const useExecutePendingPlugins = () => {
240
238
  mutate({ pending, restartOptions }),
241
239
  isLoading,
242
240
  error,
243
- isExecuted: !!data,
241
+ isExecuted: !!data
244
242
  };
245
243
  };
246
244
 
247
245
  export const useCancelPendingPlugins = () => {
248
246
  const queryClient = useQueryClient();
249
247
  const { mutate, isLoading, error, data } = useMutation<unknown, Error, PendingPlugins>(
250
- (pending) => apiClient.post(requiredLink(pending, "cancel")),
248
+ pending => apiClient.post(requiredLink(pending, "cancel")),
251
249
  {
252
- onSuccess: () => queryClient.invalidateQueries("plugins"),
250
+ onSuccess: () => queryClient.invalidateQueries("plugins")
253
251
  }
254
252
  );
255
253
  return {
256
254
  update: (pending: PendingPlugins) => mutate(pending),
257
255
  isLoading,
258
256
  error,
259
- isCancelled: !!data,
257
+ isCancelled: !!data
260
258
  };
261
259
  };
@@ -37,7 +37,7 @@ import {
37
37
  useRepository,
38
38
  useRepositoryTypes,
39
39
  useUnarchiveRepository,
40
- useUpdateRepository,
40
+ useUpdateRepository
41
41
  } from "./repositories";
42
42
  import { Repository } from "@scm-manager/ui-types";
43
43
  import { QueryClient } from "react-query";
@@ -50,25 +50,25 @@ describe("Test repository hooks", () => {
50
50
  type: "git",
51
51
  _links: {
52
52
  delete: {
53
- href: "/r/spaceships/heartOfGold",
53
+ href: "/r/spaceships/heartOfGold"
54
54
  },
55
55
  update: {
56
- href: "/r/spaceships/heartOfGold",
56
+ href: "/r/spaceships/heartOfGold"
57
57
  },
58
58
  archive: {
59
- href: "/r/spaceships/heartOfGold/archive",
59
+ href: "/r/spaceships/heartOfGold/archive"
60
60
  },
61
61
  unarchive: {
62
- href: "/r/spaceships/heartOfGold/unarchive",
63
- },
64
- },
62
+ href: "/r/spaceships/heartOfGold/unarchive"
63
+ }
64
+ }
65
65
  };
66
66
 
67
67
  const repositoryCollection = {
68
68
  _embedded: {
69
- repositories: [heartOfGold],
69
+ repositories: [heartOfGold]
70
70
  },
71
- _links: {},
71
+ _links: {}
72
72
  };
73
73
 
74
74
  afterEach(() => {
@@ -78,7 +78,7 @@ describe("Test repository hooks", () => {
78
78
  describe("useRepositories tests", () => {
79
79
  const expectCollection = async (queryClient: QueryClient, request?: UseRepositoriesRequest) => {
80
80
  const { result, waitFor } = renderHook(() => useRepositories(request), {
81
- wrapper: createWrapper(undefined, queryClient),
81
+ wrapper: createWrapper(undefined, queryClient)
82
82
  });
83
83
  await waitFor(() => {
84
84
  return !!result.current.data;
@@ -99,12 +99,12 @@ describe("Test repository hooks", () => {
99
99
  setIndexLink(queryClient, "repositories", "/repos");
100
100
  fetchMock.get("/api/v2/repos", repositoryCollection, {
101
101
  query: {
102
- page: "42",
103
- },
102
+ page: "42"
103
+ }
104
104
  });
105
105
 
106
106
  await expectCollection(queryClient, {
107
- page: 42,
107
+ page: 42
108
108
  });
109
109
  });
110
110
 
@@ -118,10 +118,10 @@ describe("Test repository hooks", () => {
118
118
  namespace: "spaceships",
119
119
  _links: {
120
120
  repositories: {
121
- href: "/spaceships",
122
- },
123
- },
124
- },
121
+ href: "/spaceships"
122
+ }
123
+ }
124
+ }
125
125
  });
126
126
  });
127
127
 
@@ -130,12 +130,12 @@ describe("Test repository hooks", () => {
130
130
  setIndexLink(queryClient, "repositories", "/repos");
131
131
  fetchMock.get("/api/v2/repos", repositoryCollection, {
132
132
  query: {
133
- q: "heart",
134
- },
133
+ q: "heart"
134
+ }
135
135
  });
136
136
 
137
137
  await expectCollection(queryClient, {
138
- search: "heart",
138
+ search: "heart"
139
139
  });
140
140
  });
141
141
 
@@ -154,7 +154,7 @@ describe("Test repository hooks", () => {
154
154
  const queryClient = createInfiniteCachingClient();
155
155
  setIndexLink(queryClient, "repositories", "/repos");
156
156
  const { result } = renderHook(() => useRepositories({ disabled: true }), {
157
- wrapper: createWrapper(undefined, queryClient),
157
+ wrapper: createWrapper(undefined, queryClient)
158
158
  });
159
159
 
160
160
  expect(result.current.isLoading).toBe(false);
@@ -171,18 +171,18 @@ describe("Test repository hooks", () => {
171
171
  fetchMock.postOnce("/api/v2/r", {
172
172
  status: 201,
173
173
  headers: {
174
- Location: "/r/spaceships/heartOfGold",
175
- },
174
+ Location: "/r/spaceships/heartOfGold"
175
+ }
176
176
  });
177
177
 
178
178
  fetchMock.getOnce("/api/v2/r/spaceships/heartOfGold", heartOfGold);
179
179
 
180
180
  const { result, waitForNextUpdate } = renderHook(() => useCreateRepository(), {
181
- wrapper: createWrapper(undefined, queryClient),
181
+ wrapper: createWrapper(undefined, queryClient)
182
182
  });
183
183
 
184
184
  const repository = {
185
- ...heartOfGold,
185
+ ...heartOfGold
186
186
  };
187
187
 
188
188
  await act(() => {
@@ -201,18 +201,18 @@ describe("Test repository hooks", () => {
201
201
  fetchMock.postOnce("/api/v2/r?initialize=true", {
202
202
  status: 201,
203
203
  headers: {
204
- Location: "/r/spaceships/heartOfGold",
205
- },
204
+ Location: "/r/spaceships/heartOfGold"
205
+ }
206
206
  });
207
207
 
208
208
  fetchMock.getOnce("/api/v2/r/spaceships/heartOfGold", heartOfGold);
209
209
 
210
210
  const { result, waitForNextUpdate } = renderHook(() => useCreateRepository(), {
211
- wrapper: createWrapper(undefined, queryClient),
211
+ wrapper: createWrapper(undefined, queryClient)
212
212
  });
213
213
 
214
214
  const repository = {
215
- ...heartOfGold,
215
+ ...heartOfGold
216
216
  };
217
217
 
218
218
  await act(() => {
@@ -229,15 +229,15 @@ describe("Test repository hooks", () => {
229
229
  setIndexLink(queryClient, "repositories", "/r");
230
230
 
231
231
  fetchMock.postOnce("/api/v2/r", {
232
- status: 201,
232
+ status: 201
233
233
  });
234
234
 
235
235
  const { result, waitForNextUpdate } = renderHook(() => useCreateRepository(), {
236
- wrapper: createWrapper(undefined, queryClient),
236
+ wrapper: createWrapper(undefined, queryClient)
237
237
  });
238
238
 
239
239
  const repository = {
240
- ...heartOfGold,
240
+ ...heartOfGold
241
241
  };
242
242
 
243
243
  await act(() => {
@@ -257,7 +257,7 @@ describe("Test repository hooks", () => {
257
257
  fetchMock.get("/api/v2/r/spaceships/heartOfGold", heartOfGold);
258
258
 
259
259
  const { result, waitFor } = renderHook(() => useRepository("spaceships", "heartOfGold"), {
260
- wrapper: createWrapper(undefined, queryClient),
260
+ wrapper: createWrapper(undefined, queryClient)
261
261
  });
262
262
  await waitFor(() => {
263
263
  return !!result.current.data;
@@ -276,15 +276,15 @@ describe("Test repository hooks", () => {
276
276
  {
277
277
  name: "git",
278
278
  displayName: "Git",
279
- _links: {},
280
- },
281
- ],
279
+ _links: {}
280
+ }
281
+ ]
282
282
  },
283
- _links: {},
283
+ _links: {}
284
284
  });
285
285
 
286
286
  const { result, waitFor } = renderHook(() => useRepositoryTypes(), {
287
- wrapper: createWrapper(undefined, queryClient),
287
+ wrapper: createWrapper(undefined, queryClient)
288
288
  });
289
289
  await waitFor(() => {
290
290
  return !!result.current.data;
@@ -305,11 +305,11 @@ describe("Test repository hooks", () => {
305
305
 
306
306
  const deleteRepository = async (options?: UseDeleteRepositoryOptions) => {
307
307
  fetchMock.deleteOnce("/api/v2/r/spaceships/heartOfGold", {
308
- status: 204,
308
+ status: 204
309
309
  });
310
310
 
311
311
  const { result, waitForNextUpdate } = renderHook(() => useDeleteRepository(options), {
312
- wrapper: createWrapper(undefined, queryClient),
312
+ wrapper: createWrapper(undefined, queryClient)
313
313
  });
314
314
 
315
315
  await act(() => {
@@ -354,9 +354,9 @@ describe("Test repository hooks", () => {
354
354
  it("should call onSuccess callback", async () => {
355
355
  let repo;
356
356
  await deleteRepository({
357
- onSuccess: (repository) => {
357
+ onSuccess: repository => {
358
358
  repo = repository;
359
- },
359
+ }
360
360
  });
361
361
  expect(repo).toEqual(heartOfGold);
362
362
  });
@@ -371,11 +371,11 @@ describe("Test repository hooks", () => {
371
371
 
372
372
  const updateRepository = async () => {
373
373
  fetchMock.putOnce("/api/v2/r/spaceships/heartOfGold", {
374
- status: 204,
374
+ status: 204
375
375
  });
376
376
 
377
377
  const { result, waitForNextUpdate } = renderHook(() => useUpdateRepository(), {
378
- wrapper: createWrapper(undefined, queryClient),
378
+ wrapper: createWrapper(undefined, queryClient)
379
379
  });
380
380
 
381
381
  await act(() => {
@@ -419,11 +419,11 @@ describe("Test repository hooks", () => {
419
419
 
420
420
  const archiveRepository = async () => {
421
421
  fetchMock.postOnce("/api/v2/r/spaceships/heartOfGold/archive", {
422
- status: 204,
422
+ status: 204
423
423
  });
424
424
 
425
425
  const { result, waitForNextUpdate } = renderHook(() => useArchiveRepository(), {
426
- wrapper: createWrapper(undefined, queryClient),
426
+ wrapper: createWrapper(undefined, queryClient)
427
427
  });
428
428
 
429
429
  await act(() => {
@@ -467,11 +467,11 @@ describe("Test repository hooks", () => {
467
467
 
468
468
  const unarchiveRepository = async () => {
469
469
  fetchMock.postOnce("/api/v2/r/spaceships/heartOfGold/unarchive", {
470
- status: 204,
470
+ status: 204
471
471
  });
472
472
 
473
473
  const { result, waitForNextUpdate } = renderHook(() => useUnarchiveRepository(), {
474
- wrapper: createWrapper(undefined, queryClient),
474
+ wrapper: createWrapper(undefined, queryClient)
475
475
  });
476
476
 
477
477
  await act(() => {