|
1 | | -import { Firebase } from '../../Firebase'; |
2 | 1 | import { GithubGraphQL } from '../../v2/GraphQLInterop'; |
3 | 2 |
|
4 | 3 | const FormatSize = (kilobytes) => { |
@@ -41,9 +40,8 @@ export interface PluginDataTable { |
41 | 40 | metadata: { id: string; commitId: string }[]; |
42 | 41 | } |
43 | 42 |
|
44 | | -const GetPluginData = (pluginList) => { |
45 | | - return new Promise<PluginDataProps[]>(async (resolve, reject) => { |
46 | | - const query = ` |
| 43 | +const GetPluginData = async (pluginList): Promise<PluginDataProps[]> => { |
| 44 | + const query = ` |
47 | 45 | query { |
48 | 46 | ${pluginList |
49 | 47 | .map( |
@@ -88,33 +86,33 @@ const GetPluginData = (pluginList) => { |
88 | 86 | } |
89 | 87 | `; |
90 | 88 |
|
91 | | - const responseJson = await GithubGraphQL.Post(query); |
| 89 | + const responseJson = await GithubGraphQL.Post(query); |
92 | 90 |
|
93 | | - const jsonResponse = Object.values(responseJson.data) |
94 | | - .map((repository) => repository) |
95 | | - .map((repo: any): PluginDataProps | null => { |
96 | | - try { |
97 | | - const pluginJson = JSON.parse(repo.pluginJson.text); |
98 | | - return { |
99 | | - pluginJson: pluginJson, |
100 | | - usesBackend: pluginJson?.useBackend === true || pluginJson?.useBackend === undefined, |
101 | | - readme: repo?.pluginReadme?.text || repo.readme.text, |
102 | | - stargazerCount: repo.stargazerCount, |
103 | | - diskUsage: FormatSize(repo.diskUsage), |
104 | | - commitDate: repo.commit.committedDate, |
105 | | - commitMessage: repo.commit.message, |
106 | | - repoName: repo.repoName, |
107 | | - repoOwner: repo.repoOwner.login, |
108 | | - id: repo.commitId.oid, |
109 | | - }; |
110 | | - } catch { |
111 | | - return null; |
112 | | - } |
113 | | - }) |
114 | | - .filter((item): item is PluginDataProps => item !== null); |
| 91 | + if (!responseJson.data) { |
| 92 | + throw new Error(`GitHub GraphQL error: ${JSON.stringify(responseJson)}`); |
| 93 | + } |
115 | 94 |
|
116 | | - resolve(jsonResponse); |
117 | | - }); |
| 95 | + return Object.values(responseJson.data) |
| 96 | + .map((repo: any): PluginDataProps | null => { |
| 97 | + try { |
| 98 | + const pluginJson = JSON.parse(repo.pluginJson.text); |
| 99 | + return { |
| 100 | + pluginJson: pluginJson, |
| 101 | + usesBackend: pluginJson?.useBackend === true || pluginJson?.useBackend === undefined, |
| 102 | + readme: repo?.pluginReadme?.text || repo.readme.text, |
| 103 | + stargazerCount: repo.stargazerCount, |
| 104 | + diskUsage: FormatSize(repo.diskUsage), |
| 105 | + commitDate: repo.commit.committedDate, |
| 106 | + commitMessage: repo.commit.message, |
| 107 | + repoName: repo.repoName, |
| 108 | + repoOwner: repo.repoOwner.login, |
| 109 | + id: repo.commitId.oid, |
| 110 | + }; |
| 111 | + } catch { |
| 112 | + return null; |
| 113 | + } |
| 114 | + }) |
| 115 | + .filter((item): item is PluginDataProps => item !== null); |
118 | 116 | }; |
119 | 117 |
|
120 | 118 | export { GetPluginData }; |
0 commit comments