decap-cms-backend-github 3.4.0 → 3.5.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/CHANGELOG.md +4 -0
- package/dist/decap-cms-backend-github.js +70 -70
- package/dist/decap-cms-backend-github.js.map +1 -1
- package/dist/esm/API.js +22 -11
- package/dist/esm/implementation.js +13 -6
- package/dist/esm/rateLimitLink.js +24 -0
- package/dist/esm/types/githubPullRequests.js +1 -0
- package/package.json +2 -2
- package/src/API.ts +131 -108
- package/src/GraphQLAPI.ts +8 -5
- package/src/__tests__/API.spec.js +15 -3
- package/src/implementation.tsx +16 -9
package/src/implementation.tsx
CHANGED
|
@@ -26,7 +26,7 @@ import AuthenticationPage from './AuthenticationPage';
|
|
|
26
26
|
import API, { API_NAME } from './API';
|
|
27
27
|
import GraphQLAPI from './GraphQLAPI';
|
|
28
28
|
|
|
29
|
-
import type {
|
|
29
|
+
import type { Endpoints } from '@octokit/types';
|
|
30
30
|
import type {
|
|
31
31
|
AsyncLock,
|
|
32
32
|
Implementation,
|
|
@@ -42,7 +42,7 @@ import type {
|
|
|
42
42
|
} from 'decap-cms-lib-util';
|
|
43
43
|
import type { Semaphore } from 'semaphore';
|
|
44
44
|
|
|
45
|
-
export type GitHubUser =
|
|
45
|
+
export type GitHubUser = Endpoints['GET /user']['response']['data'];
|
|
46
46
|
|
|
47
47
|
const MAX_CONCURRENT_DOWNLOADS = 10;
|
|
48
48
|
|
|
@@ -210,13 +210,20 @@ export default class GitHub implements Implementation {
|
|
|
210
210
|
return Promise.resolve();
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
async currentUser({ token }: { token: string }) {
|
|
213
|
+
async currentUser({ token }: { token: string }): Promise<GitHubUser> {
|
|
214
214
|
if (!this._currentUserPromise) {
|
|
215
|
-
this._currentUserPromise =
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
this._currentUserPromise = (async () => {
|
|
216
|
+
const res = await fetch(`${this.apiRoot}/user`, {
|
|
217
|
+
headers: {
|
|
218
|
+
Authorization: `${this.tokenKeyword} ${token}`,
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
const user = await res.json();
|
|
222
|
+
return {
|
|
223
|
+
...user,
|
|
224
|
+
name: user.name || 'Unknown',
|
|
225
|
+
} as GitHubUser;
|
|
226
|
+
})();
|
|
220
227
|
}
|
|
221
228
|
return this._currentUserPromise;
|
|
222
229
|
}
|
|
@@ -346,7 +353,7 @@ export default class GitHub implements Implementation {
|
|
|
346
353
|
useOpenAuthoring: this.useOpenAuthoring,
|
|
347
354
|
initialWorkflowStatus: this.options.initialWorkflowStatus,
|
|
348
355
|
baseUrl: this.baseUrl,
|
|
349
|
-
getUser: this.currentUser,
|
|
356
|
+
getUser: args => this.currentUser(args),
|
|
350
357
|
});
|
|
351
358
|
const user = await this.api!.user();
|
|
352
359
|
const isCollab = await this.api!.hasWriteAccess().catch(error => {
|