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/dist/esm/API.js
CHANGED
|
@@ -91,14 +91,17 @@ export default class API {
|
|
|
91
91
|
token: this.token
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
return this._userPromise
|
|
94
|
+
return this._userPromise.then(user => ({
|
|
95
|
+
name: user.name || 'Unknown',
|
|
96
|
+
login: user.login
|
|
97
|
+
}));
|
|
95
98
|
}
|
|
96
99
|
async hasWriteAccess() {
|
|
97
100
|
try {
|
|
98
101
|
const result = await this.request(this.repoURL);
|
|
99
102
|
// update config repoOwner to avoid case sensitivity issues with GitHub
|
|
100
103
|
this.repoOwner = result.owner.login;
|
|
101
|
-
return result.permissions
|
|
104
|
+
return result.permissions?.push ?? false;
|
|
102
105
|
} catch (error) {
|
|
103
106
|
console.error('Problem fetching repo data from GitHub');
|
|
104
107
|
throw error;
|
|
@@ -402,7 +405,7 @@ export default class API {
|
|
|
402
405
|
const [{
|
|
403
406
|
files
|
|
404
407
|
}, pullRequestAuthor] = await Promise.all([this.getDifferences(this.branch, pullRequest.head.sha), this.getPullRequestAuthor(pullRequest)]);
|
|
405
|
-
const diffs = await Promise.all(files.map(file => this.diffFromFile(file)));
|
|
408
|
+
const diffs = await Promise.all((files || []).map(file => this.diffFromFile(file)));
|
|
406
409
|
const label = pullRequest.labels.find(l => isCMSLabel(l.name, this.cmsLabelPrefix));
|
|
407
410
|
const status = labelToStatus(label.name, this.cmsLabelPrefix);
|
|
408
411
|
const updatedAt = pullRequest.updated_at;
|
|
@@ -450,8 +453,8 @@ export default class API {
|
|
|
450
453
|
commit
|
|
451
454
|
} = result[0];
|
|
452
455
|
return {
|
|
453
|
-
author: commit.author
|
|
454
|
-
updatedOn: commit.author
|
|
456
|
+
author: commit.author?.name || commit.author?.email || '',
|
|
457
|
+
updatedOn: commit.author?.date || ''
|
|
455
458
|
};
|
|
456
459
|
} catch (e) {
|
|
457
460
|
return {
|
|
@@ -502,12 +505,12 @@ export default class API {
|
|
|
502
505
|
});
|
|
503
506
|
return result.tree
|
|
504
507
|
// filter only files and up to the required depth
|
|
505
|
-
.filter(file => file.type === 'blob' && file.path.split('/').length <= depth).map(file => ({
|
|
508
|
+
.filter(file => file.type === 'blob' && file.path && file.path.split('/').length <= depth).map(file => ({
|
|
506
509
|
type: file.type,
|
|
507
510
|
id: file.sha,
|
|
508
511
|
name: basename(file.path),
|
|
509
512
|
path: `${folder}/${file.path}`,
|
|
510
|
-
size: file.size
|
|
513
|
+
size: file.size || 0
|
|
511
514
|
}));
|
|
512
515
|
} catch (err) {
|
|
513
516
|
if (err && err.status === 404) {
|
|
@@ -668,7 +671,7 @@ export default class API {
|
|
|
668
671
|
const resp = await this.request(`${this.originRepoURL}/commits/${sha}/status`);
|
|
669
672
|
return resp.statuses.map(s => ({
|
|
670
673
|
context: s.context,
|
|
671
|
-
target_url: s.target_url,
|
|
674
|
+
target_url: s.target_url || '',
|
|
672
675
|
state: s.state === GitHubCommitStatusState.Success ? PreviewState.Success : PreviewState.Other
|
|
673
676
|
}));
|
|
674
677
|
}
|
|
@@ -744,7 +747,7 @@ export default class API {
|
|
|
744
747
|
return {
|
|
745
748
|
path: diff.filename,
|
|
746
749
|
newFile: diff.status === 'added',
|
|
747
|
-
sha: diff.sha,
|
|
750
|
+
sha: diff.sha || '',
|
|
748
751
|
// media files diffs don't have a patch attribute, except svg files
|
|
749
752
|
// renamed files don't have a patch attribute too
|
|
750
753
|
binary: diff.status !== 'renamed' && !diff.patch || diff.filename.endsWith('.svg')
|
|
@@ -769,7 +772,7 @@ export default class API {
|
|
|
769
772
|
const {
|
|
770
773
|
files: diffFiles
|
|
771
774
|
} = await this.getDifferences(this.branch, await this.getHeadReference(branch));
|
|
772
|
-
const diffs = await Promise.all(diffFiles.map(file => this.diffFromFile(file)));
|
|
775
|
+
const diffs = await Promise.all((diffFiles || []).map(file => this.diffFromFile(file)));
|
|
773
776
|
// mark media files to remove
|
|
774
777
|
const mediaFilesToRemove = [];
|
|
775
778
|
for (const diff of diffs.filter(d => d.binary)) {
|
|
@@ -824,7 +827,15 @@ export default class API {
|
|
|
824
827
|
} = commit.commit;
|
|
825
828
|
|
|
826
829
|
// create a new commit from the updated tree
|
|
827
|
-
const newCommit = await this.createCommit(message, tree.sha, [baseCommit.sha], author
|
|
830
|
+
const newCommit = await this.createCommit(message, tree.sha, [baseCommit.sha], author ? {
|
|
831
|
+
name: author.name || '',
|
|
832
|
+
email: author.email || '',
|
|
833
|
+
date: author.date
|
|
834
|
+
} : undefined, committer ? {
|
|
835
|
+
name: committer.name || '',
|
|
836
|
+
email: committer.email || '',
|
|
837
|
+
date: committer.date
|
|
838
|
+
} : undefined);
|
|
828
839
|
return newCommit;
|
|
829
840
|
} else {
|
|
830
841
|
return commit;
|
|
@@ -124,11 +124,18 @@ export default class GitHub {
|
|
|
124
124
|
token
|
|
125
125
|
}) {
|
|
126
126
|
if (!this._currentUserPromise) {
|
|
127
|
-
this._currentUserPromise =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
this._currentUserPromise = (async () => {
|
|
128
|
+
const res = await fetch(`${this.apiRoot}/user`, {
|
|
129
|
+
headers: {
|
|
130
|
+
Authorization: `${this.tokenKeyword} ${token}`
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const user = await res.json();
|
|
134
|
+
return {
|
|
135
|
+
...user,
|
|
136
|
+
name: user.name || 'Unknown'
|
|
137
|
+
};
|
|
138
|
+
})();
|
|
132
139
|
}
|
|
133
140
|
return this._currentUserPromise;
|
|
134
141
|
}
|
|
@@ -255,7 +262,7 @@ export default class GitHub {
|
|
|
255
262
|
useOpenAuthoring: this.useOpenAuthoring,
|
|
256
263
|
initialWorkflowStatus: this.options.initialWorkflowStatus,
|
|
257
264
|
baseUrl: this.baseUrl,
|
|
258
|
-
getUser: this.currentUser
|
|
265
|
+
getUser: args => this.currentUser(args)
|
|
259
266
|
});
|
|
260
267
|
const user = await this.api.user();
|
|
261
268
|
const isCollab = await this.api.hasWriteAccess().catch(error => {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate limit info type and callback
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Extracts rate limit information from response headers
|
|
7
|
+
*/
|
|
8
|
+
export function extractRateLimitInfo(headers) {
|
|
9
|
+
const used = headers.get('x-ratelimit-used');
|
|
10
|
+
const limit = headers.get('x-ratelimit-limit');
|
|
11
|
+
const remaining = headers.get('x-ratelimit-remaining');
|
|
12
|
+
const reset = headers.get('x-ratelimit-reset');
|
|
13
|
+
const resource = headers.get('x-ratelimit-resource');
|
|
14
|
+
if (!used || !limit || !remaining || !reset || !resource) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
used: parseInt(used, 10),
|
|
19
|
+
limit: parseInt(limit, 10),
|
|
20
|
+
remaining: parseInt(remaining, 10),
|
|
21
|
+
reset: parseInt(reset, 10),
|
|
22
|
+
resource
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decap-cms-backend-github",
|
|
3
3
|
"description": "GitHub backend for Decap CMS",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.5.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-backend-github",
|
|
7
7
|
"bugs": "https://github.com/decaporg/decap-cms/issues",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"browser": {
|
|
45
45
|
"path": "path-browserify"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "0c1b7c7d63ba6ddb3de3692fbb6b16ac6ebb44d5"
|
|
48
48
|
}
|