Skip to content

Commit 0a3deaf

Browse files
committed
Update to new API version
1 parent 37ab4f1 commit 0a3deaf

File tree

6 files changed

+59
-229
lines changed

6 files changed

+59
-229
lines changed

__tests__/main.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,7 @@ describe('action', () => {
211211
await main.run()
212212
expect(fetchMock).toHaveBeenNthCalledWith(
213213
1,
214-
'https://example.com/api/v1/admin/extensions?search=ValeLS',
215-
expect.anything()
216-
)
217-
expect(fetchMock).toHaveBeenNthCalledWith(
218-
2,
219-
'https://example.com/api/v1/admin/extensions',
214+
'https://example.com/api/v1/management/plugins',
220215
expect.objectContaining({
221216
body: expect.anything(),
222217
method: 'POST',

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 18 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extensionstore.ts

Lines changed: 38 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ type Platform = 'Windows' | 'Linux' | 'macOS'
44
type Architecture = 'x86_64' | 'arm64'
55

66
export interface PluginMetaData {
7+
Id: string
78
Name: string
89
Version: string
910
CompatVersion: string
1011
Vendor: string
12+
VendorId: string
1113
Copyright: string
1214
License: string
1315
Category: string
@@ -18,141 +20,50 @@ export interface PluginMetaData {
1820

1921
interface PlatformDescriptor {
2022
name: Platform
21-
version: string
2223
architecture: Architecture
2324
}
2425

25-
interface PluginInstance {
26+
interface PluginSource {
2627
url: string
27-
size: number
28-
meta_data: PluginMetaData
29-
dependencies: PluginInstance[]
28+
platform?: PlatformDescriptor
3029
}
3130

32-
interface PluginSet {
33-
status: 'published' | 'draft' | 'hidden'
34-
core_compat_version: string
35-
core_version: string
36-
host_os: Platform
37-
host_os_version: string
38-
host_os_architecture: Architecture
39-
plugins: PluginInstance[]
40-
}
41-
42-
interface ExtensionData {
43-
name: string
44-
vendor?: string
31+
interface PluginRequest {
32+
id: string
33+
display_name: string
4534
tags?: string[]
46-
compatibility: string
47-
platforms: string[]
48-
license: string
49-
copyright?: string
50-
version: string
51-
version_history?: {
52-
version: string
53-
released_at: string
54-
is_latest: boolean
55-
}[]
56-
status: 'published' | 'draft' | 'hidden'
57-
is_pack: boolean
35+
license: 'open-source' | 'commercial'
36+
status: 'published' | 'unpublished' | 'disabled'
5837
icon?: string
5938
small_icon?: string
60-
description_paragraphs?: {
61-
header: string
62-
text: string[]
63-
}[]
64-
description_links?: {
65-
link_text: string
66-
url: string
67-
}[]
68-
description_images?: {
69-
image_label: string
70-
url: string
71-
}[]
72-
download_history?: {
73-
download_count: number
74-
first_download_at?: string
75-
latest_download_at?: string
76-
}[]
77-
plugin_sets: PluginSet[]
78-
}
79-
/*
80-
interface Extension extends ExtensionData {
81-
extension_id: string
82-
}
83-
*/
84-
type ExtensionSaveRequest = ExtensionData
85-
86-
interface Versions {
87-
version: string
88-
compat_version: string
39+
released_at?: string
40+
is_latest?: boolean
41+
plugin: {
42+
metadata: PluginMetaData
43+
sources: PluginSource[]
44+
}
8945
}
9046

91-
function createPluginSets(
92-
downloadUrl: string,
47+
function createPluginRequest(
9348
pluginMetaData: PluginMetaData,
94-
qtcVersion: Versions,
95-
publish: boolean
96-
): PluginSet[] {
97-
const osArr = [
98-
{
99-
name: 'Windows',
100-
version: '10.0.0'
101-
},
102-
{
103-
name: 'Linux',
104-
version: '20.4.0'
105-
},
106-
{
107-
name: 'macOS',
108-
version: '11.0.0'
109-
}
110-
]
111-
const allPlatforms: PlatformDescriptor[] = osArr
112-
.map(os => {
113-
return { ...os, architecture: 'x86_64' } as PlatformDescriptor
114-
})
115-
.concat(
116-
osArr.map(os => {
117-
return { ...os, architecture: 'arm64' } as PlatformDescriptor
118-
})
119-
)
120-
return allPlatforms.map(platform => {
121-
return {
122-
status: publish ? 'published' : 'draft',
123-
core_version: qtcVersion.version,
124-
core_compat_version: qtcVersion.compat_version,
125-
host_os: platform.name,
126-
host_os_version: platform.version, // TODO: pass the real data
127-
host_os_architecture: platform.architecture, // TODO: pass the real data
128-
plugins: [
49+
//pluginSets: PluginSet[],
50+
publish: boolean,
51+
downloadUrl: string
52+
): PluginRequest {
53+
return {
54+
id: pluginMetaData.Id,
55+
display_name: pluginMetaData.Name,
56+
license: 'open-source',
57+
status: publish ? 'published' : 'unpublished',
58+
tags: pluginMetaData.Tags,
59+
plugin: {
60+
metadata: pluginMetaData,
61+
sources: [
12962
{
130-
url: downloadUrl,
131-
size: 5000, // TODO: check if it is needed, pass the real data
132-
meta_data: pluginMetaData,
133-
dependencies: []
63+
url: downloadUrl
13464
}
13565
]
13666
}
137-
})
138-
}
139-
140-
function createSaveRequest(
141-
pluginMetaData: PluginMetaData,
142-
pluginSets: PluginSet[],
143-
publish: boolean
144-
): ExtensionSaveRequest {
145-
return {
146-
name: pluginMetaData.Name,
147-
vendor: pluginMetaData.Vendor,
148-
compatibility: 'Qt 6.0',
149-
platforms: ['Windows', 'macOS', 'Linux'],
150-
license: 'os',
151-
version: pluginMetaData.Version,
152-
status: publish ? 'published' : 'draft',
153-
is_pack: false,
154-
tags: pluginMetaData.Tags,
155-
plugin_sets: pluginSets
15667
}
15768
}
15869

@@ -185,47 +96,20 @@ async function request(
18596
export async function createOrUpdateExtension(
18697
downloadUrl: string,
18798
pluginMetaData: PluginMetaData,
188-
qtcVersion: Versions,
18999
apiUrl: string,
190100
apiToken: string,
191101
publish: boolean
192102
): Promise<void> {
193103
core.debug(`Creating or updating extension ${pluginMetaData.Name}`)
194-
const search = await request(
195-
'GET',
196-
`${apiUrl}api/v1/admin/extensions?search=${pluginMetaData.Name}`,
197-
apiToken
198-
)
199104

200-
if (!search.items || !Array.isArray(search.items)) {
201-
throw new Error('Invalid response from the API')
202-
}
203-
204-
const saveRequest = JSON.stringify(
205-
createSaveRequest(
206-
pluginMetaData,
207-
createPluginSets(downloadUrl, pluginMetaData, qtcVersion, publish),
208-
publish
209-
)
105+
const pluginRequest = JSON.stringify(
106+
createPluginRequest(pluginMetaData, publish, downloadUrl)
210107
)
211108

212-
const extensionId =
213-
search.items.length > 0 && search.items[0].extension_id !== ''
214-
? search.items[0].extension_id
215-
: ''
216-
if (extensionId) {
217-
await request(
218-
'PUT',
219-
`${apiUrl}api/v1/admin/extensions/${extensionId}`,
220-
apiToken,
221-
saveRequest
222-
)
223-
} else {
224-
await request(
225-
'POST',
226-
`${apiUrl}api/v1/admin/extensions`,
227-
apiToken,
228-
saveRequest
229-
)
230-
}
109+
await request(
110+
'POST',
111+
`${apiUrl}api/v1/management/plugins`,
112+
apiToken,
113+
pluginRequest
114+
)
231115
}

src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export async function run(): Promise<void> {
3434
await createOrUpdateExtension(
3535
downloadUrl,
3636
asJson as unknown as PluginMetaData,
37-
{ version: '14.0.0', compat_version: '14.0.0' },
3837
api,
3938
token,
4039
publish

0 commit comments

Comments
 (0)