decap-cms-backend-github 3.1.1 → 3.2.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 +10 -0
- package/dist/decap-cms-backend-github.js +2 -2
- package/dist/decap-cms-backend-github.js.map +1 -1
- package/dist/esm/API.js +3 -3
- package/dist/esm/AuthenticationPage.js +2 -2
- package/dist/esm/GraphQLAPI.js +2 -5
- package/dist/esm/implementation.js +23 -2
- package/package.json +2 -2
- package/src/API.ts +1 -1
- package/src/implementation.tsx +21 -1
package/dist/esm/API.js
CHANGED
|
@@ -19,8 +19,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
19
19
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
20
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
21
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
22
|
-
function _toPropertyKey(
|
|
23
|
-
function _toPrimitive(
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
23
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
24
24
|
const API_NAME = exports.API_NAME = 'GitHub';
|
|
25
25
|
const MOCK_PULL_REQUEST = exports.MOCK_PULL_REQUEST = -1;
|
|
26
26
|
var GitHubCommitStatusState = /*#__PURE__*/function (GitHubCommitStatusState) {
|
|
@@ -449,7 +449,7 @@ class API {
|
|
|
449
449
|
return;
|
|
450
450
|
}
|
|
451
451
|
try {
|
|
452
|
-
const user = await this.user
|
|
452
|
+
const user = await this.request(`/users/${pullRequest.user.login}`);
|
|
453
453
|
return user.name || user.login;
|
|
454
454
|
} catch {
|
|
455
455
|
return;
|
|
@@ -13,8 +13,8 @@ var _react2 = require("@emotion/react");
|
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
15
15
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
-
function _toPropertyKey(
|
|
17
|
-
function _toPrimitive(
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
17
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
18
|
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
|
|
19
19
|
const LoginButtonIcon = /*#__PURE__*/(0, _base.default)(_decapCmsUiDefault.Icon, {
|
|
20
20
|
target: "e1ko648l2",
|
package/dist/esm/GraphQLAPI.js
CHANGED
|
@@ -21,8 +21,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
21
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
22
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
23
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
-
function _toPropertyKey(
|
|
25
|
-
function _toPrimitive(
|
|
24
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
25
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
26
|
const NO_CACHE = 'no-cache';
|
|
27
27
|
const CACHE_FIRST = 'cache-first';
|
|
28
28
|
const fragmentMatcher = new _apolloCacheInmemory.IntrospectionFragmentMatcher({
|
|
@@ -96,7 +96,6 @@ class GraphQLAPI extends _API.default {
|
|
|
96
96
|
},
|
|
97
97
|
fetchPolicy: CACHE_FIRST // repository id doesn't change
|
|
98
98
|
});
|
|
99
|
-
|
|
100
99
|
return data.repository;
|
|
101
100
|
}
|
|
102
101
|
query(options) {
|
|
@@ -171,7 +170,6 @@ class GraphQLAPI extends _API.default {
|
|
|
171
170
|
query: queries.user,
|
|
172
171
|
fetchPolicy: CACHE_FIRST // we can assume user details don't change often
|
|
173
172
|
});
|
|
174
|
-
|
|
175
173
|
return data.viewer;
|
|
176
174
|
}
|
|
177
175
|
async retrieveBlobObject(owner, name, expression, options = {}) {
|
|
@@ -261,7 +259,6 @@ class GraphQLAPI extends _API.default {
|
|
|
261
259
|
fetchPolicy: CACHE_FIRST
|
|
262
260
|
} // blob sha is derived from file content
|
|
263
261
|
);
|
|
264
|
-
|
|
265
262
|
if (isNull) {
|
|
266
263
|
throw new _decapCmsLibUtil.APIError('Not Found', 404, 'GitHub');
|
|
267
264
|
} else if (!isBinary) {
|
|
@@ -20,8 +20,8 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
20
20
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
21
21
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22
22
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
-
function _toPropertyKey(
|
|
24
|
-
function _toPrimitive(
|
|
23
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
24
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
25
25
|
const MAX_CONCURRENT_DOWNLOADS = 10;
|
|
26
26
|
const {
|
|
27
27
|
fetchWithTimeout: fetch
|
|
@@ -36,6 +36,7 @@ class GitHub {
|
|
|
36
36
|
_defineProperty(this, "api", void 0);
|
|
37
37
|
_defineProperty(this, "options", void 0);
|
|
38
38
|
_defineProperty(this, "originRepo", void 0);
|
|
39
|
+
_defineProperty(this, "isBranchConfigured", void 0);
|
|
39
40
|
_defineProperty(this, "repo", void 0);
|
|
40
41
|
_defineProperty(this, "openAuthoringEnabled", void 0);
|
|
41
42
|
_defineProperty(this, "useOpenAuthoring", void 0);
|
|
@@ -94,6 +95,7 @@ class GitHub {
|
|
|
94
95
|
throw new Error('The GitHub backend needs a "repo" in the backend configuration.');
|
|
95
96
|
}
|
|
96
97
|
this.api = this.options.API || null;
|
|
98
|
+
this.isBranchConfigured = config.backend.branch ? true : false;
|
|
97
99
|
this.openAuthoringEnabled = config.backend.open_authoring || false;
|
|
98
100
|
if (this.openAuthoringEnabled) {
|
|
99
101
|
if (!this.options.useWorkflow) {
|
|
@@ -296,6 +298,18 @@ class GitHub {
|
|
|
296
298
|
}
|
|
297
299
|
async authenticate(state) {
|
|
298
300
|
this.token = state.token;
|
|
301
|
+
// Query the default branch name when the `branch` property is missing
|
|
302
|
+
// in the config file
|
|
303
|
+
if (!this.isBranchConfigured) {
|
|
304
|
+
const repoInfo = await fetch(`${this.apiRoot}/repos/${this.originRepo}`, {
|
|
305
|
+
headers: {
|
|
306
|
+
Authorization: `token ${this.token}`
|
|
307
|
+
}
|
|
308
|
+
}).then(res => res.json()).catch(() => null);
|
|
309
|
+
if (repoInfo && repoInfo.default_branch) {
|
|
310
|
+
this.branch = repoInfo.default_branch;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
299
313
|
const apiCtor = this.useGraphql ? _GraphQLAPI.default : _API.default;
|
|
300
314
|
this.api = new apiCtor({
|
|
301
315
|
token: this.token,
|
|
@@ -330,6 +344,13 @@ class GitHub {
|
|
|
330
344
|
throw new Error('Your GitHub user account does not have access to this repo.');
|
|
331
345
|
}
|
|
332
346
|
|
|
347
|
+
// if (!this.isBranchConfigured) {
|
|
348
|
+
// const defaultBranchName = await this.api.getDefaultBranchName()
|
|
349
|
+
// if (defaultBranchName) {
|
|
350
|
+
// this.branch = defaultBranchName;
|
|
351
|
+
// }
|
|
352
|
+
// }
|
|
353
|
+
|
|
333
354
|
// Authorized user
|
|
334
355
|
return _objectSpread(_objectSpread({}, user), {}, {
|
|
335
356
|
token: state.token,
|
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.2.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",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"prop-types": "^15.7.2",
|
|
41
41
|
"react": "^18.2.0"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "86c93a4fae0fd954d043acc176b0618ab715623b"
|
|
44
44
|
}
|
package/src/API.ts
CHANGED
package/src/implementation.tsx
CHANGED
|
@@ -69,6 +69,7 @@ export default class GitHub implements Implementation {
|
|
|
69
69
|
initialWorkflowStatus: string;
|
|
70
70
|
};
|
|
71
71
|
originRepo: string;
|
|
72
|
+
isBranchConfigured: boolean;
|
|
72
73
|
repo?: string;
|
|
73
74
|
openAuthoringEnabled: boolean;
|
|
74
75
|
useOpenAuthoring?: boolean;
|
|
@@ -106,7 +107,7 @@ export default class GitHub implements Implementation {
|
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
this.api = this.options.API || null;
|
|
109
|
-
|
|
110
|
+
this.isBranchConfigured = config.backend.branch ? true : false;
|
|
110
111
|
this.openAuthoringEnabled = config.backend.open_authoring || false;
|
|
111
112
|
if (this.openAuthoringEnabled) {
|
|
112
113
|
if (!this.options.useWorkflow) {
|
|
@@ -320,6 +321,18 @@ export default class GitHub implements Implementation {
|
|
|
320
321
|
|
|
321
322
|
async authenticate(state: Credentials) {
|
|
322
323
|
this.token = state.token as string;
|
|
324
|
+
// Query the default branch name when the `branch` property is missing
|
|
325
|
+
// in the config file
|
|
326
|
+
if (!this.isBranchConfigured) {
|
|
327
|
+
const repoInfo = await fetch(`${this.apiRoot}/repos/${this.originRepo}`, {
|
|
328
|
+
headers: { Authorization: `token ${this.token}` },
|
|
329
|
+
})
|
|
330
|
+
.then(res => res.json())
|
|
331
|
+
.catch(() => null);
|
|
332
|
+
if (repoInfo && repoInfo.default_branch) {
|
|
333
|
+
this.branch = repoInfo.default_branch;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
323
336
|
const apiCtor = this.useGraphql ? GraphQLAPI : API;
|
|
324
337
|
this.api = new apiCtor({
|
|
325
338
|
token: this.token,
|
|
@@ -354,6 +367,13 @@ export default class GitHub implements Implementation {
|
|
|
354
367
|
throw new Error('Your GitHub user account does not have access to this repo.');
|
|
355
368
|
}
|
|
356
369
|
|
|
370
|
+
// if (!this.isBranchConfigured) {
|
|
371
|
+
// const defaultBranchName = await this.api.getDefaultBranchName()
|
|
372
|
+
// if (defaultBranchName) {
|
|
373
|
+
// this.branch = defaultBranchName;
|
|
374
|
+
// }
|
|
375
|
+
// }
|
|
376
|
+
|
|
357
377
|
// Authorized user
|
|
358
378
|
return { ...user, token: state.token as string, useOpenAuthoring: this.useOpenAuthoring };
|
|
359
379
|
}
|