@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.
- package/build/index.d.ts +735 -0
- package/build/index.js +3200 -0
- package/build/index.mjs +3031 -0
- package/package.json +15 -10
- package/LICENSE.txt +0 -21
- package/src/ApiProvider.test.tsx +0 -60
- package/src/ApiProvider.tsx +0 -80
- package/src/LegacyContext.test.tsx +0 -52
- package/src/LegacyContext.tsx +0 -75
- package/src/admin.test.ts +0 -55
- package/src/admin.ts +0 -42
- package/src/alerts.ts +0 -107
- package/src/annotations.ts +0 -45
- package/src/apiKeys.ts +0 -82
- package/src/apiclient.test.ts +0 -126
- package/src/apiclient.ts +0 -336
- package/src/base.test.ts +0 -238
- package/src/base.ts +0 -120
- package/src/branches.test.ts +0 -234
- package/src/branches.ts +0 -201
- package/src/changesets.test.ts +0 -178
- package/src/changesets.ts +0 -82
- package/src/compare.ts +0 -90
- package/src/config.test.ts +0 -118
- package/src/config.ts +0 -60
- package/src/configLink.test.ts +0 -169
- package/src/configLink.ts +0 -89
- package/src/contentType.ts +0 -58
- package/src/diff.test.ts +0 -234
- package/src/diff.ts +0 -93
- package/src/errors.test.ts +0 -59
- package/src/errors.ts +0 -133
- package/src/fileContent.ts +0 -33
- package/src/groupSuggestions.ts +0 -32
- package/src/groups.test.ts +0 -241
- package/src/groups.ts +0 -141
- package/src/help/search/modal.de.ts +0 -33
- package/src/help/search/modal.en.ts +0 -33
- package/src/help/search/syntax.de.ts +0 -148
- package/src/help/search/syntax.en.ts +0 -145
- package/src/history.ts +0 -62
- package/src/import.ts +0 -114
- package/src/index.ts +0 -72
- package/src/keys.ts +0 -48
- package/src/links.test.ts +0 -99
- package/src/links.ts +0 -54
- package/src/login.test.ts +0 -240
- package/src/login.ts +0 -128
- package/src/loginInfo.ts +0 -43
- package/src/namespaceSuggestions.ts +0 -32
- package/src/namespaces.test.ts +0 -95
- package/src/namespaces.ts +0 -43
- package/src/notifications.ts +0 -183
- package/src/permissions.test.ts +0 -345
- package/src/permissions.ts +0 -202
- package/src/plugins.test.ts +0 -336
- package/src/plugins.ts +0 -259
- package/src/publicKeys.ts +0 -83
- package/src/repositories.test.ts +0 -508
- package/src/repositories.ts +0 -375
- package/src/repository-roles.test.ts +0 -229
- package/src/repository-roles.ts +0 -142
- package/src/reset.ts +0 -36
- package/src/search.ts +0 -153
- package/src/sources.test.ts +0 -233
- package/src/sources.ts +0 -136
- package/src/suggestions.ts +0 -47
- package/src/tags.test.ts +0 -272
- package/src/tags.ts +0 -118
- package/src/tests/createInfiniteCachingClient.ts +0 -37
- package/src/tests/createWrapper.tsx +0 -37
- package/src/tests/indexLinks.ts +0 -43
- package/src/urls.test.ts +0 -104
- package/src/urls.ts +0 -118
- package/src/usePluginCenterAuthInfo.ts +0 -91
- package/src/userSuggestions.ts +0 -32
- package/src/users.test.ts +0 -310
- package/src/users.ts +0 -240
- package/src/utils.ts +0 -29
package/src/configLink.ts
DELETED
|
@@ -1,89 +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 { useMutation, useQuery, useQueryClient } from "react-query";
|
|
26
|
-
import { apiClient } from "./apiclient";
|
|
27
|
-
import { useCallback } from "react";
|
|
28
|
-
import { HalRepresentation, Link } from "@scm-manager/ui-types";
|
|
29
|
-
|
|
30
|
-
type Result<C extends HalRepresentation> = {
|
|
31
|
-
contentType: string;
|
|
32
|
-
configuration: C;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type MutationVariables<C extends HalRepresentation> = {
|
|
36
|
-
configuration: C;
|
|
37
|
-
contentType: string;
|
|
38
|
-
link: string;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const useConfigLink = <C extends HalRepresentation>(link: string) => {
|
|
42
|
-
const queryClient = useQueryClient();
|
|
43
|
-
const queryKey = ["configLink", link];
|
|
44
|
-
const { isLoading, error, data } = useQuery<Result<C>, Error>(queryKey, () =>
|
|
45
|
-
apiClient.get(link).then((response) => {
|
|
46
|
-
const contentType = response.headers.get("Content-Type") || "application/json";
|
|
47
|
-
return response.json().then((configuration: C) => ({ configuration, contentType }));
|
|
48
|
-
})
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const {
|
|
52
|
-
isLoading: isUpdating,
|
|
53
|
-
error: mutationError,
|
|
54
|
-
mutate,
|
|
55
|
-
data: updateResponse,
|
|
56
|
-
} = useMutation<Response, Error, MutationVariables<C>>(
|
|
57
|
-
(vars: MutationVariables<C>) => apiClient.put(vars.link, vars.configuration, vars.contentType),
|
|
58
|
-
{
|
|
59
|
-
onSuccess: async () => {
|
|
60
|
-
await queryClient.invalidateQueries(queryKey);
|
|
61
|
-
},
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const isReadOnly = !data?.configuration._links.update;
|
|
66
|
-
|
|
67
|
-
const update = useCallback(
|
|
68
|
-
(configuration: C) => {
|
|
69
|
-
if (data && !isReadOnly) {
|
|
70
|
-
mutate({
|
|
71
|
-
configuration,
|
|
72
|
-
contentType: data.contentType,
|
|
73
|
-
link: (data.configuration._links.update as Link).href,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
[mutate, data, isReadOnly]
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
isLoading,
|
|
82
|
-
isUpdating,
|
|
83
|
-
isReadOnly,
|
|
84
|
-
error: error || mutationError,
|
|
85
|
-
initialConfiguration: data?.configuration,
|
|
86
|
-
update,
|
|
87
|
-
isUpdated: !!updateResponse,
|
|
88
|
-
};
|
|
89
|
-
};
|
package/src/contentType.ts
DELETED
|
@@ -1,58 +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 { apiClient } from "./apiclient";
|
|
25
|
-
import { useQuery } from "react-query";
|
|
26
|
-
import { ApiResultWithFetching } from "./base";
|
|
27
|
-
|
|
28
|
-
export type ContentType = {
|
|
29
|
-
type: string;
|
|
30
|
-
language?: string;
|
|
31
|
-
aceMode?: string;
|
|
32
|
-
codemirrorMode?: string;
|
|
33
|
-
prismMode?: string;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function getContentType(url: string): Promise<ContentType> {
|
|
37
|
-
return apiClient.head(url).then((response) => {
|
|
38
|
-
return {
|
|
39
|
-
type: response.headers.get("Content-Type") || "application/octet-stream",
|
|
40
|
-
language: response.headers.get("X-Programming-Language") || undefined,
|
|
41
|
-
aceMode: response.headers.get("X-Syntax-Mode-Ace") || undefined,
|
|
42
|
-
codemirrorMode: response.headers.get("X-Syntax-Mode-Codemirror") || undefined,
|
|
43
|
-
prismMode: response.headers.get("X-Syntax-Mode-Prism") || undefined,
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const useContentType = (url: string): ApiResultWithFetching<ContentType> => {
|
|
49
|
-
const { isLoading, isFetching, error, data } = useQuery<ContentType, Error>(["contentType", url], () =>
|
|
50
|
-
getContentType(url)
|
|
51
|
-
);
|
|
52
|
-
return {
|
|
53
|
-
isLoading,
|
|
54
|
-
isFetching,
|
|
55
|
-
error,
|
|
56
|
-
data,
|
|
57
|
-
};
|
|
58
|
-
};
|
package/src/diff.test.ts
DELETED
|
@@ -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
|
-
|
|
25
|
-
import fetchMock from "fetch-mock-jest";
|
|
26
|
-
import { Diff } from "@scm-manager/ui-types";
|
|
27
|
-
import { act, renderHook } from "@testing-library/react-hooks";
|
|
28
|
-
import { useDiff } from "./diff";
|
|
29
|
-
import createWrapper from "./tests/createWrapper";
|
|
30
|
-
|
|
31
|
-
describe("Test diff", () => {
|
|
32
|
-
const simpleDiff: Diff = {
|
|
33
|
-
files: [
|
|
34
|
-
{
|
|
35
|
-
oldPath: "/dev/null",
|
|
36
|
-
newPath: "0.txt",
|
|
37
|
-
oldEndingNewLine: true,
|
|
38
|
-
newEndingNewLine: true,
|
|
39
|
-
oldRevision: "0000000000000000000000000000000000000000",
|
|
40
|
-
newRevision: "573541ac9702dd3969c9bc859d2b91ec1f7e6e56",
|
|
41
|
-
type: "add",
|
|
42
|
-
language: "text",
|
|
43
|
-
hunks: [
|
|
44
|
-
{
|
|
45
|
-
content: "@@ -0,0 +1 @@",
|
|
46
|
-
newStart: 1,
|
|
47
|
-
newLines: 1,
|
|
48
|
-
changes: [
|
|
49
|
-
{
|
|
50
|
-
content: "0",
|
|
51
|
-
type: "insert",
|
|
52
|
-
lineNumber: 1,
|
|
53
|
-
isInsert: true,
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
_links: {
|
|
59
|
-
lines: {
|
|
60
|
-
href: "/api/v2/repositories/scmadmin/HeartOfGold-git/content/one_to_onehundred/0.txt?start={start}&end={end}",
|
|
61
|
-
templated: true,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
partial: false,
|
|
67
|
-
_links: {
|
|
68
|
-
self: {
|
|
69
|
-
href: "/api/v2/diff",
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const partialDiff1: Diff = {
|
|
75
|
-
files: [
|
|
76
|
-
{
|
|
77
|
-
oldPath: "/dev/null",
|
|
78
|
-
newPath: "0.txt",
|
|
79
|
-
oldEndingNewLine: true,
|
|
80
|
-
newEndingNewLine: true,
|
|
81
|
-
oldRevision: "0000000000000000000000000000000000000000",
|
|
82
|
-
newRevision: "573541ac9702dd3969c9bc859d2b91ec1f7e6e56",
|
|
83
|
-
type: "add",
|
|
84
|
-
language: "text",
|
|
85
|
-
hunks: [
|
|
86
|
-
{
|
|
87
|
-
content: "@@ -0,0 +1 @@",
|
|
88
|
-
newStart: 1,
|
|
89
|
-
newLines: 1,
|
|
90
|
-
changes: [
|
|
91
|
-
{
|
|
92
|
-
content: "0",
|
|
93
|
-
type: "insert",
|
|
94
|
-
lineNumber: 1,
|
|
95
|
-
isInsert: true,
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
_links: {
|
|
101
|
-
lines: {
|
|
102
|
-
href: "/api/v2/repositories/scmadmin/HeartOfGold-git/content/one_to_onehundred/0.txt?start={start}&end={end}",
|
|
103
|
-
templated: true,
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
partial: true,
|
|
109
|
-
_links: {
|
|
110
|
-
self: {
|
|
111
|
-
href: "/diff",
|
|
112
|
-
},
|
|
113
|
-
next: {
|
|
114
|
-
href: "/diff?offset=1&limit=1",
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const partialDiff2: Diff = {
|
|
120
|
-
files: [
|
|
121
|
-
{
|
|
122
|
-
oldPath: "/dev/null",
|
|
123
|
-
newPath: "1.txt",
|
|
124
|
-
oldEndingNewLine: true,
|
|
125
|
-
newEndingNewLine: true,
|
|
126
|
-
oldRevision: "0000000000000000000000000000000000000000",
|
|
127
|
-
newRevision: "573541ac9702dd3969c9bc859d2b91ec1f7e6e56",
|
|
128
|
-
type: "add",
|
|
129
|
-
language: "text",
|
|
130
|
-
hunks: [
|
|
131
|
-
{
|
|
132
|
-
content: "@@ -0,0 +1 @@",
|
|
133
|
-
newStart: 1,
|
|
134
|
-
newLines: 1,
|
|
135
|
-
changes: [
|
|
136
|
-
{
|
|
137
|
-
content: "1",
|
|
138
|
-
type: "insert",
|
|
139
|
-
lineNumber: 1,
|
|
140
|
-
isInsert: true,
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
_links: {
|
|
146
|
-
lines: {
|
|
147
|
-
href: "/api/v2/repositories/scmadmin/HeartOfGold-git/content/one_to_onehundred/1.txt?start={start}&end={end}",
|
|
148
|
-
templated: true,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
|
-
partial: false,
|
|
154
|
-
_links: {
|
|
155
|
-
self: {
|
|
156
|
-
href: "/diff",
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
beforeEach(() => {
|
|
162
|
-
fetchMock.reset();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("should return simple parsed diff", async () => {
|
|
166
|
-
fetchMock.getOnce("/api/v2/diff", {
|
|
167
|
-
body: simpleDiff,
|
|
168
|
-
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" },
|
|
169
|
-
});
|
|
170
|
-
const { result, waitFor } = renderHook(() => useDiff("/diff"), {
|
|
171
|
-
wrapper: createWrapper(),
|
|
172
|
-
});
|
|
173
|
-
await waitFor(() => !!result.current.data);
|
|
174
|
-
expect(result.current.data).toEqual(simpleDiff);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should parse and return textual diff", async () => {
|
|
178
|
-
fetchMock.getOnce("/api/v2/diff", {
|
|
179
|
-
body: `diff --git a/new.txt b/new.txt
|
|
180
|
-
--- a/new.txt
|
|
181
|
-
+++ b/new.txt
|
|
182
|
-
@@ -1,1 +1,1 @@
|
|
183
|
-
-i am old!
|
|
184
|
-
\
|
|
185
|
-
+i am new!
|
|
186
|
-
\
|
|
187
|
-
`,
|
|
188
|
-
headers: { "Content-Type": "text/plain" },
|
|
189
|
-
});
|
|
190
|
-
const { result, waitFor } = renderHook(() => useDiff("/diff"), {
|
|
191
|
-
wrapper: createWrapper(),
|
|
192
|
-
});
|
|
193
|
-
await waitFor(() => !!result.current.data);
|
|
194
|
-
expect(result.current.data?.files).toHaveLength(1);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("should return parsed diff in multiple chunks", async () => {
|
|
198
|
-
fetchMock.getOnce("/api/v2/diff?limit=1", {
|
|
199
|
-
body: partialDiff1,
|
|
200
|
-
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" },
|
|
201
|
-
});
|
|
202
|
-
fetchMock.getOnce("/api/v2/diff?offset=1&limit=1", {
|
|
203
|
-
body: partialDiff2,
|
|
204
|
-
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" },
|
|
205
|
-
});
|
|
206
|
-
const { result, waitFor, waitForNextUpdate } = renderHook(() => useDiff("/diff?limit=1"), {
|
|
207
|
-
wrapper: createWrapper(),
|
|
208
|
-
});
|
|
209
|
-
await waitFor(() => !!result.current.data);
|
|
210
|
-
expect(result.current.data).toEqual(partialDiff1);
|
|
211
|
-
|
|
212
|
-
await act(() => {
|
|
213
|
-
const { fetchNextPage } = result.current;
|
|
214
|
-
fetchNextPage();
|
|
215
|
-
return waitForNextUpdate();
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
await waitFor(() => !result.current.isFetchingNextPage);
|
|
219
|
-
|
|
220
|
-
expect(result.current.data).toEqual({ ...partialDiff2, files: [partialDiff1.files[0], partialDiff2.files[0]] });
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("should append query parameters to url which has already query params", async () => {
|
|
224
|
-
fetchMock.getOnce("/api/v2/diff?format=GIT&limit=25", {
|
|
225
|
-
body: simpleDiff,
|
|
226
|
-
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" },
|
|
227
|
-
});
|
|
228
|
-
const { result, waitFor } = renderHook(() => useDiff("/diff?format=GIT", { limit: 25 }), {
|
|
229
|
-
wrapper: createWrapper(),
|
|
230
|
-
});
|
|
231
|
-
await waitFor(() => !!result.current.data);
|
|
232
|
-
expect(result.current.data).toEqual(simpleDiff);
|
|
233
|
-
});
|
|
234
|
-
});
|
package/src/diff.ts
DELETED
|
@@ -1,93 +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 parser from "gitdiff-parser";
|
|
26
|
-
|
|
27
|
-
import { useInfiniteQuery } from "react-query";
|
|
28
|
-
import { apiClient } from "./apiclient";
|
|
29
|
-
import { Diff, Link } from "@scm-manager/ui-types";
|
|
30
|
-
|
|
31
|
-
type UseDiffOptions = {
|
|
32
|
-
limit?: number;
|
|
33
|
-
refetchOnWindowFocus?: boolean;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const defaultOptions: UseDiffOptions = {
|
|
37
|
-
refetchOnWindowFocus: true,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const useDiff = (link: string, options: UseDiffOptions = defaultOptions) => {
|
|
41
|
-
let initialLink = link;
|
|
42
|
-
if (options.limit) {
|
|
43
|
-
const separator = initialLink.includes("?") ? "&" : "?";
|
|
44
|
-
initialLink = `${initialLink}${separator}limit=${options.limit}`;
|
|
45
|
-
}
|
|
46
|
-
const { isLoading, error, data, isFetchingNextPage, fetchNextPage } = useInfiniteQuery<Diff, Error, Diff>(
|
|
47
|
-
["link", link],
|
|
48
|
-
({ pageParam }) => {
|
|
49
|
-
return apiClient.get(pageParam || initialLink).then((response) => {
|
|
50
|
-
const contentType = response.headers.get("Content-Type");
|
|
51
|
-
if (contentType && contentType.toLowerCase() === "application/vnd.scmm-diffparsed+json;v=2") {
|
|
52
|
-
return response.json();
|
|
53
|
-
} else {
|
|
54
|
-
return response
|
|
55
|
-
.text()
|
|
56
|
-
.then(parser.parse)
|
|
57
|
-
.then((parsedGit) => {
|
|
58
|
-
return {
|
|
59
|
-
files: parsedGit,
|
|
60
|
-
partial: false,
|
|
61
|
-
_links: {},
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
getNextPageParam: (lastPage) => (lastPage._links.next as Link)?.href,
|
|
69
|
-
refetchOnWindowFocus: options.refetchOnWindowFocus,
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
isLoading,
|
|
75
|
-
error,
|
|
76
|
-
isFetchingNextPage,
|
|
77
|
-
fetchNextPage: () => {
|
|
78
|
-
fetchNextPage();
|
|
79
|
-
},
|
|
80
|
-
data: merge(data?.pages),
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const merge = (diffs?: Diff[]): Diff | undefined => {
|
|
85
|
-
if (!diffs || diffs.length === 0) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const joinedFiles = diffs.flatMap((diff) => diff.files);
|
|
89
|
-
return {
|
|
90
|
-
...diffs[diffs.length - 1],
|
|
91
|
-
files: joinedFiles,
|
|
92
|
-
};
|
|
93
|
-
};
|
package/src/errors.test.ts
DELETED
|
@@ -1,59 +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 { BackendError, UnauthorizedError, createBackendError, NotFoundError } from "./errors";
|
|
26
|
-
|
|
27
|
-
describe("test createBackendError", () => {
|
|
28
|
-
const earthNotFoundError = {
|
|
29
|
-
transactionId: "42t",
|
|
30
|
-
errorCode: "42e",
|
|
31
|
-
message: "earth not found",
|
|
32
|
-
context: [
|
|
33
|
-
{
|
|
34
|
-
type: "planet",
|
|
35
|
-
id: "earth",
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
violations: [],
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
it("should return a default backend error", () => {
|
|
42
|
-
const err = createBackendError(earthNotFoundError, 500);
|
|
43
|
-
expect(err).toBeInstanceOf(BackendError);
|
|
44
|
-
expect(err.name).toBe("BackendError");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// 403 is no backend error
|
|
48
|
-
xit("should return an unauthorized error for status code 403", () => {
|
|
49
|
-
const err = createBackendError(earthNotFoundError, 403);
|
|
50
|
-
expect(err).toBeInstanceOf(UnauthorizedError);
|
|
51
|
-
expect(err.name).toBe("UnauthorizedError");
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should return an not found error for status code 404", () => {
|
|
55
|
-
const err = createBackendError(earthNotFoundError, 404);
|
|
56
|
-
expect(err).toBeInstanceOf(NotFoundError);
|
|
57
|
-
expect(err.name).toBe("NotFoundError");
|
|
58
|
-
});
|
|
59
|
-
});
|
package/src/errors.ts
DELETED
|
@@ -1,133 +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
|
-
type Context = {
|
|
26
|
-
type: string;
|
|
27
|
-
id: string;
|
|
28
|
-
}[];
|
|
29
|
-
|
|
30
|
-
export type Violation = {
|
|
31
|
-
path?: string;
|
|
32
|
-
message: string;
|
|
33
|
-
key?: string;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type AdditionalMessage = {
|
|
37
|
-
key?: string;
|
|
38
|
-
message?: string;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type BackendErrorContent = {
|
|
42
|
-
transactionId: string;
|
|
43
|
-
errorCode: string;
|
|
44
|
-
message: string;
|
|
45
|
-
url?: string;
|
|
46
|
-
context: Context;
|
|
47
|
-
violations: Violation[];
|
|
48
|
-
additionalMessages?: AdditionalMessage[];
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export class BackendError extends Error {
|
|
52
|
-
transactionId: string;
|
|
53
|
-
errorCode: string;
|
|
54
|
-
url: string | null | undefined;
|
|
55
|
-
context: Context = [];
|
|
56
|
-
statusCode: number;
|
|
57
|
-
violations: Violation[];
|
|
58
|
-
additionalMessages?: AdditionalMessage[];
|
|
59
|
-
|
|
60
|
-
constructor(content: BackendErrorContent, name: string, statusCode: number) {
|
|
61
|
-
super(content.message);
|
|
62
|
-
this.name = name;
|
|
63
|
-
this.transactionId = content.transactionId;
|
|
64
|
-
this.errorCode = content.errorCode;
|
|
65
|
-
this.url = content.url;
|
|
66
|
-
this.context = content.context;
|
|
67
|
-
this.statusCode = statusCode;
|
|
68
|
-
this.violations = content.violations;
|
|
69
|
-
this.additionalMessages = content.additionalMessages;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export class UnauthorizedError extends Error {
|
|
74
|
-
statusCode: number;
|
|
75
|
-
|
|
76
|
-
constructor(message: string, statusCode: number) {
|
|
77
|
-
super(message);
|
|
78
|
-
this.statusCode = statusCode;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export class BadGatewayError extends Error {
|
|
83
|
-
statusCode: number;
|
|
84
|
-
|
|
85
|
-
constructor(message: string, statusCode: number) {
|
|
86
|
-
super(message);
|
|
87
|
-
this.statusCode = statusCode;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export class TokenExpiredError extends UnauthorizedError {}
|
|
92
|
-
|
|
93
|
-
export class ForbiddenError extends Error {
|
|
94
|
-
statusCode: number;
|
|
95
|
-
|
|
96
|
-
constructor(message: string, statusCode: number) {
|
|
97
|
-
super(message);
|
|
98
|
-
this.statusCode = statusCode;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export class NotFoundError extends BackendError {
|
|
103
|
-
constructor(content: BackendErrorContent, statusCode: number) {
|
|
104
|
-
super(content, "NotFoundError", statusCode);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export class ConflictError extends BackendError {
|
|
109
|
-
constructor(content: BackendErrorContent, statusCode: number) {
|
|
110
|
-
super(content, "ConflictError", statusCode);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export class MissingLinkError extends Error {
|
|
115
|
-
name = "MissingLinkError";
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function createBackendError(content: BackendErrorContent, statusCode: number) {
|
|
119
|
-
switch (statusCode) {
|
|
120
|
-
case 404:
|
|
121
|
-
return new NotFoundError(content, statusCode);
|
|
122
|
-
case 409:
|
|
123
|
-
return new ConflictError(content, statusCode);
|
|
124
|
-
default:
|
|
125
|
-
return new BackendError(content, "BackendError", statusCode);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function isBackendError(response: Response) {
|
|
130
|
-
return response.headers.get("Content-Type") === "application/vnd.scmm-error+json;v=2";
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export const TOKEN_EXPIRED_ERROR_CODE = "DDS8D8unr1";
|
package/src/fileContent.ts
DELETED
|
@@ -1,33 +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 { File } from "@scm-manager/ui-types";
|
|
25
|
-
import { useQuery } from "react-query";
|
|
26
|
-
import { apiClient } from "./apiclient";
|
|
27
|
-
import { requiredLink } from "./links";
|
|
28
|
-
import { ApiResult } from "./base";
|
|
29
|
-
|
|
30
|
-
export const useFileContent = (file: File): ApiResult<string> => {
|
|
31
|
-
const selfLink = requiredLink(file, "self");
|
|
32
|
-
return useQuery(["fileContent", selfLink], () => apiClient.get(selfLink).then((response) => response.text()));
|
|
33
|
-
};
|