decap-cms-backend-github 3.2.2 → 3.3.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 +67 -67
- package/dist/decap-cms-backend-github.js.map +1 -1
- package/dist/esm/API.js +172 -209
- package/dist/esm/AuthenticationPage.js +85 -98
- package/dist/esm/GraphQLAPI.js +125 -121
- package/dist/esm/fragmentTypes.js +0 -2
- package/dist/esm/fragments.js +8 -14
- package/dist/esm/implementation.js +85 -122
- package/dist/esm/index.js +9 -33
- package/dist/esm/mutations.js +10 -17
- package/dist/esm/queries.js +18 -28
- package/dist/esm/types/semaphore.d.js +0 -1
- package/package.json +3 -3
- package/src/API.ts +6 -1
- package/src/AuthenticationPage.js +10 -0
- package/src/GraphQLAPI.ts +2 -1
package/dist/esm/GraphQLAPI.js
CHANGED
|
@@ -1,35 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _apolloLinkContext = require("apollo-link-context");
|
|
13
|
-
var _decapCmsLibUtil = require("decap-cms-lib-util");
|
|
14
|
-
var _fragmentTypes = _interopRequireDefault(require("./fragmentTypes"));
|
|
15
|
-
var _API = _interopRequireWildcard(require("./API"));
|
|
16
|
-
var queries = _interopRequireWildcard(require("./queries"));
|
|
17
|
-
var mutations = _interopRequireWildcard(require("./mutations"));
|
|
18
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
-
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
|
-
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(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); }
|
|
1
|
+
import { ApolloClient } from 'apollo-client';
|
|
2
|
+
import { InMemoryCache, defaultDataIdFromObject, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
|
|
3
|
+
import { createHttpLink } from 'apollo-link-http';
|
|
4
|
+
import { setContext } from 'apollo-link-context';
|
|
5
|
+
import { APIError, readFile, localForage, DEFAULT_PR_BODY, branchFromContentKey, CMS_BRANCH_PREFIX, throwOnConflictingBranches } from 'decap-cms-lib-util';
|
|
6
|
+
import trim from 'lodash/trim';
|
|
7
|
+
import trimStart from 'lodash/trimStart';
|
|
8
|
+
import introspectionQueryResultData from './fragmentTypes';
|
|
9
|
+
import API, { API_NAME, PullRequestState, MOCK_PULL_REQUEST } from './API';
|
|
10
|
+
import * as queries from './queries';
|
|
11
|
+
import * as mutations from './mutations';
|
|
26
12
|
const NO_CACHE = 'no-cache';
|
|
27
13
|
const CACHE_FIRST = 'cache-first';
|
|
28
|
-
const fragmentMatcher = new
|
|
29
|
-
introspectionQueryResultData
|
|
14
|
+
const fragmentMatcher = new IntrospectionFragmentMatcher({
|
|
15
|
+
introspectionQueryResultData
|
|
30
16
|
});
|
|
31
17
|
function transformPullRequest(pr) {
|
|
32
|
-
return
|
|
18
|
+
return {
|
|
19
|
+
...pr,
|
|
33
20
|
labels: pr.labels.nodes,
|
|
34
21
|
head: {
|
|
35
22
|
ref: pr.headRefName,
|
|
@@ -42,32 +29,31 @@ function transformPullRequest(pr) {
|
|
|
42
29
|
ref: pr.baseRefName,
|
|
43
30
|
sha: pr.baseRefOid
|
|
44
31
|
}
|
|
45
|
-
}
|
|
32
|
+
};
|
|
46
33
|
}
|
|
47
|
-
class GraphQLAPI extends
|
|
34
|
+
export default class GraphQLAPI extends API {
|
|
48
35
|
constructor(config) {
|
|
49
36
|
super(config);
|
|
50
|
-
_defineProperty(this, "client", void 0);
|
|
51
37
|
this.client = this.getApolloClient();
|
|
52
38
|
}
|
|
53
39
|
getApolloClient() {
|
|
54
|
-
const authLink =
|
|
40
|
+
const authLink = setContext((_, {
|
|
55
41
|
headers
|
|
56
42
|
}) => {
|
|
57
43
|
return {
|
|
58
|
-
headers:
|
|
59
|
-
'Content-Type': 'application/json; charset=utf-8'
|
|
60
|
-
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
46
|
+
...headers,
|
|
61
47
|
authorization: this.token ? `${this.tokenKeyword} ${this.token}` : ''
|
|
62
|
-
}
|
|
48
|
+
}
|
|
63
49
|
};
|
|
64
50
|
});
|
|
65
|
-
const httpLink =
|
|
51
|
+
const httpLink = createHttpLink({
|
|
66
52
|
uri: `${this.apiRoot}/graphql`
|
|
67
53
|
});
|
|
68
|
-
return new
|
|
54
|
+
return new ApolloClient({
|
|
69
55
|
link: authLink.concat(httpLink),
|
|
70
|
-
cache: new
|
|
56
|
+
cache: new InMemoryCache({
|
|
71
57
|
fragmentMatcher
|
|
72
58
|
}),
|
|
73
59
|
defaultOptions: {
|
|
@@ -100,7 +86,7 @@ class GraphQLAPI extends _API.default {
|
|
|
100
86
|
}
|
|
101
87
|
query(options) {
|
|
102
88
|
return this.client.query(options).catch(error => {
|
|
103
|
-
throw new
|
|
89
|
+
throw new APIError(error.message, 500, 'GitHub');
|
|
104
90
|
});
|
|
105
91
|
}
|
|
106
92
|
async mutate(options) {
|
|
@@ -110,18 +96,16 @@ class GraphQLAPI extends _API.default {
|
|
|
110
96
|
} catch (error) {
|
|
111
97
|
const errors = error.graphQLErrors;
|
|
112
98
|
if (Array.isArray(errors) && errors.some(e => e.message === 'Ref cannot be created.')) {
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
const branchName = (0, _trimStart2.default)(refName, 'refs/heads/');
|
|
99
|
+
const refName = options?.variables?.createRefInput?.name || '';
|
|
100
|
+
const branchName = trimStart(refName, 'refs/heads/');
|
|
116
101
|
if (branchName) {
|
|
117
|
-
await
|
|
102
|
+
await throwOnConflictingBranches(branchName, name => this.getBranch(name), API_NAME);
|
|
118
103
|
}
|
|
119
|
-
} else if (Array.isArray(errors) && errors.some(e => new RegExp(`A ref named "refs/heads/${
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
if (branchName && branchName.startsWith(`${_decapCmsLibUtil.CMS_BRANCH_PREFIX}/`) && sha) {
|
|
104
|
+
} else if (Array.isArray(errors) && errors.some(e => new RegExp(`A ref named "refs/heads/${CMS_BRANCH_PREFIX}/.+?" already exists in the repository.`).test(e.message))) {
|
|
105
|
+
const refName = options?.variables?.createRefInput?.name || '';
|
|
106
|
+
const sha = options?.variables?.createRefInput?.oid || '';
|
|
107
|
+
const branchName = trimStart(refName, 'refs/heads/');
|
|
108
|
+
if (branchName && branchName.startsWith(`${CMS_BRANCH_PREFIX}/`) && sha) {
|
|
125
109
|
try {
|
|
126
110
|
// this can happen if the branch wasn't deleted when the PR was merged
|
|
127
111
|
// we backup the existing branch just in case an re-run the mutation
|
|
@@ -134,7 +118,7 @@ class GraphQLAPI extends _API.default {
|
|
|
134
118
|
}
|
|
135
119
|
}
|
|
136
120
|
}
|
|
137
|
-
throw new
|
|
121
|
+
throw new APIError(error.message, 500, 'GitHub');
|
|
138
122
|
}
|
|
139
123
|
}
|
|
140
124
|
async hasWriteAccess() {
|
|
@@ -175,14 +159,15 @@ class GraphQLAPI extends _API.default {
|
|
|
175
159
|
async retrieveBlobObject(owner, name, expression, options = {}) {
|
|
176
160
|
const {
|
|
177
161
|
data
|
|
178
|
-
} = await this.query(
|
|
162
|
+
} = await this.query({
|
|
179
163
|
query: queries.blob,
|
|
180
164
|
variables: {
|
|
181
165
|
owner,
|
|
182
166
|
name,
|
|
183
167
|
expression
|
|
184
|
-
}
|
|
185
|
-
|
|
168
|
+
},
|
|
169
|
+
...options
|
|
170
|
+
});
|
|
186
171
|
// https://developer.github.com/v4/object/blob/
|
|
187
172
|
if (data.repository.object) {
|
|
188
173
|
const {
|
|
@@ -232,7 +217,7 @@ class GraphQLAPI extends _API.default {
|
|
|
232
217
|
repoURL,
|
|
233
218
|
parseText
|
|
234
219
|
});
|
|
235
|
-
const content = await
|
|
220
|
+
const content = await readFile(sha, fetchContent, localForage, parseText);
|
|
236
221
|
return content;
|
|
237
222
|
}
|
|
238
223
|
async fetchBlobContent({
|
|
@@ -260,7 +245,7 @@ class GraphQLAPI extends _API.default {
|
|
|
260
245
|
} // blob sha is derived from file content
|
|
261
246
|
);
|
|
262
247
|
if (isNull) {
|
|
263
|
-
throw new
|
|
248
|
+
throw new APIError('Not Found', 404, 'GitHub');
|
|
264
249
|
} else if (!isBinary) {
|
|
265
250
|
return text;
|
|
266
251
|
} else {
|
|
@@ -273,7 +258,7 @@ class GraphQLAPI extends _API.default {
|
|
|
273
258
|
}
|
|
274
259
|
async getPullRequestAuthor(pullRequest) {
|
|
275
260
|
const user = pullRequest.user;
|
|
276
|
-
return
|
|
261
|
+
return user?.name || user?.login;
|
|
277
262
|
}
|
|
278
263
|
async getPullRequests(head, state, predicate) {
|
|
279
264
|
const {
|
|
@@ -281,9 +266,9 @@ class GraphQLAPI extends _API.default {
|
|
|
281
266
|
originRepoName: name
|
|
282
267
|
} = this;
|
|
283
268
|
let states;
|
|
284
|
-
if (state ===
|
|
269
|
+
if (state === PullRequestState.Open) {
|
|
285
270
|
states = ['OPEN'];
|
|
286
|
-
} else if (state ===
|
|
271
|
+
} else if (state === PullRequestState.Closed) {
|
|
287
272
|
states = ['CLOSED', 'MERGED'];
|
|
288
273
|
} else {
|
|
289
274
|
states = ['OPEN', 'CLOSED', 'MERGED'];
|
|
@@ -292,20 +277,20 @@ class GraphQLAPI extends _API.default {
|
|
|
292
277
|
data
|
|
293
278
|
} = await this.query({
|
|
294
279
|
query: queries.pullRequests,
|
|
295
|
-
variables:
|
|
280
|
+
variables: {
|
|
296
281
|
owner,
|
|
297
|
-
name
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
282
|
+
name,
|
|
283
|
+
...(head ? {
|
|
284
|
+
head
|
|
285
|
+
} : {}),
|
|
301
286
|
states
|
|
302
|
-
}
|
|
287
|
+
}
|
|
303
288
|
});
|
|
304
289
|
const {
|
|
305
290
|
pullRequests
|
|
306
291
|
} = data.repository;
|
|
307
292
|
const mapped = pullRequests.nodes.map(transformPullRequest);
|
|
308
|
-
return mapped.filter(pr => pr.head.ref.startsWith(`${
|
|
293
|
+
return mapped.filter(pr => pr.head.ref.startsWith(`${CMS_BRANCH_PREFIX}/`) && predicate(pr));
|
|
309
294
|
}
|
|
310
295
|
async getOpenAuthoringBranches() {
|
|
311
296
|
const {
|
|
@@ -331,7 +316,7 @@ class GraphQLAPI extends _API.default {
|
|
|
331
316
|
}
|
|
332
317
|
async getStatuses(collectionName, slug) {
|
|
333
318
|
const contentKey = this.generateContentKey(collectionName, slug);
|
|
334
|
-
const branch =
|
|
319
|
+
const branch = branchFromContentKey(contentKey);
|
|
335
320
|
const pullRequest = await this.getBranchPullRequest(branch);
|
|
336
321
|
const sha = pullRequest.head.sha;
|
|
337
322
|
const {
|
|
@@ -365,8 +350,7 @@ class GraphQLAPI extends _API.default {
|
|
|
365
350
|
getAllFiles(entries, path) {
|
|
366
351
|
const allFiles = entries.reduce((acc, item) => {
|
|
367
352
|
if (item.type === 'tree') {
|
|
368
|
-
|
|
369
|
-
const entries = ((_item$object = item.object) === null || _item$object === void 0 ? void 0 : _item$object.entries) || [];
|
|
353
|
+
const entries = item.object?.entries || [];
|
|
370
354
|
return [...acc, ...this.getAllFiles(entries, `${path}/${item.name}`)];
|
|
371
355
|
} else if (item.type === 'blob') {
|
|
372
356
|
return [...acc, {
|
|
@@ -390,7 +374,7 @@ class GraphQLAPI extends _API.default {
|
|
|
390
374
|
owner,
|
|
391
375
|
name
|
|
392
376
|
} = this.getOwnerAndNameFromRepoUrl(repoURL);
|
|
393
|
-
const folder = (
|
|
377
|
+
const folder = trim(path, '/');
|
|
394
378
|
const {
|
|
395
379
|
data
|
|
396
380
|
} = await this.query({
|
|
@@ -424,17 +408,20 @@ class GraphQLAPI extends _API.default {
|
|
|
424
408
|
async getDefaultBranch() {
|
|
425
409
|
const {
|
|
426
410
|
data
|
|
427
|
-
} = await this.query(
|
|
411
|
+
} = await this.query({
|
|
412
|
+
...this.getBranchQuery(this.branch, this.originRepoOwner, this.originRepoName)
|
|
413
|
+
});
|
|
428
414
|
return data.repository.branch;
|
|
429
415
|
}
|
|
430
416
|
async getBranch(branch) {
|
|
431
417
|
const {
|
|
432
418
|
data
|
|
433
|
-
} = await this.query(
|
|
419
|
+
} = await this.query({
|
|
420
|
+
...this.getBranchQuery(branch, this.repoOwner, this.repoName),
|
|
434
421
|
fetchPolicy: CACHE_FIRST
|
|
435
|
-
})
|
|
422
|
+
});
|
|
436
423
|
if (!data.repository.branch) {
|
|
437
|
-
throw new
|
|
424
|
+
throw new APIError('Branch not found', 404, API_NAME);
|
|
438
425
|
}
|
|
439
426
|
return data.repository.branch;
|
|
440
427
|
}
|
|
@@ -470,7 +457,7 @@ class GraphQLAPI extends _API.default {
|
|
|
470
457
|
}
|
|
471
458
|
},
|
|
472
459
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
473
|
-
update: store => store.data.delete(
|
|
460
|
+
update: store => store.data.delete(defaultDataIdFromObject(branch))
|
|
474
461
|
});
|
|
475
462
|
return data.deleteRef;
|
|
476
463
|
}
|
|
@@ -491,17 +478,19 @@ class GraphQLAPI extends _API.default {
|
|
|
491
478
|
async getPullRequest(number) {
|
|
492
479
|
const {
|
|
493
480
|
data
|
|
494
|
-
} = await this.query(
|
|
481
|
+
} = await this.query({
|
|
482
|
+
...this.getPullRequestQuery(number),
|
|
495
483
|
fetchPolicy: CACHE_FIRST
|
|
496
|
-
})
|
|
484
|
+
});
|
|
497
485
|
|
|
498
486
|
// https://developer.github.com/v4/enum/pullrequeststate/
|
|
499
487
|
// GraphQL state: [CLOSED, MERGED, OPEN]
|
|
500
488
|
// REST API state: [closed, open]
|
|
501
|
-
const state = data.repository.pullRequest.state === 'OPEN' ?
|
|
502
|
-
return
|
|
489
|
+
const state = data.repository.pullRequest.state === 'OPEN' ? PullRequestState.Open : PullRequestState.Closed;
|
|
490
|
+
return {
|
|
491
|
+
...data.repository.pullRequest,
|
|
503
492
|
state
|
|
504
|
-
}
|
|
493
|
+
};
|
|
505
494
|
}
|
|
506
495
|
getPullRequestAndBranchQuery(branch, number) {
|
|
507
496
|
const {
|
|
@@ -527,9 +516,10 @@ class GraphQLAPI extends _API.default {
|
|
|
527
516
|
async getPullRequestAndBranch(branch, number) {
|
|
528
517
|
const {
|
|
529
518
|
data
|
|
530
|
-
} = await this.query(
|
|
519
|
+
} = await this.query({
|
|
520
|
+
...this.getPullRequestAndBranchQuery(branch, number),
|
|
531
521
|
fetchPolicy: CACHE_FIRST
|
|
532
|
-
})
|
|
522
|
+
});
|
|
533
523
|
const {
|
|
534
524
|
repository,
|
|
535
525
|
origin
|
|
@@ -557,13 +547,15 @@ class GraphQLAPI extends _API.default {
|
|
|
557
547
|
pullRequest
|
|
558
548
|
} = mutationResult.reopenPullRequest;
|
|
559
549
|
const pullRequestData = {
|
|
560
|
-
repository:
|
|
550
|
+
repository: {
|
|
551
|
+
...pullRequest.repository,
|
|
561
552
|
pullRequest
|
|
562
|
-
}
|
|
553
|
+
}
|
|
563
554
|
};
|
|
564
|
-
store.writeQuery(
|
|
555
|
+
store.writeQuery({
|
|
556
|
+
...this.getPullRequestQuery(pullRequest.number),
|
|
565
557
|
data: pullRequestData
|
|
566
|
-
})
|
|
558
|
+
});
|
|
567
559
|
}
|
|
568
560
|
});
|
|
569
561
|
return data.reopenPullRequest;
|
|
@@ -586,13 +578,15 @@ class GraphQLAPI extends _API.default {
|
|
|
586
578
|
pullRequest
|
|
587
579
|
} = mutationResult.closePullRequest;
|
|
588
580
|
const pullRequestData = {
|
|
589
|
-
repository:
|
|
581
|
+
repository: {
|
|
582
|
+
...pullRequest.repository,
|
|
590
583
|
pullRequest
|
|
591
|
-
}
|
|
584
|
+
}
|
|
592
585
|
};
|
|
593
|
-
store.writeQuery(
|
|
586
|
+
store.writeQuery({
|
|
587
|
+
...this.getPullRequestQuery(pullRequest.number),
|
|
594
588
|
data: pullRequestData
|
|
595
|
-
})
|
|
589
|
+
});
|
|
596
590
|
}
|
|
597
591
|
});
|
|
598
592
|
return data.closePullRequest;
|
|
@@ -600,9 +594,9 @@ class GraphQLAPI extends _API.default {
|
|
|
600
594
|
async deleteUnpublishedEntry(collectionName, slug) {
|
|
601
595
|
try {
|
|
602
596
|
const contentKey = this.generateContentKey(collectionName, slug);
|
|
603
|
-
const branchName =
|
|
597
|
+
const branchName = branchFromContentKey(contentKey);
|
|
604
598
|
const pr = await this.getBranchPullRequest(branchName);
|
|
605
|
-
if (pr.number !==
|
|
599
|
+
if (pr.number !== MOCK_PULL_REQUEST) {
|
|
606
600
|
const {
|
|
607
601
|
branch,
|
|
608
602
|
pullRequest
|
|
@@ -621,8 +615,8 @@ class GraphQLAPI extends _API.default {
|
|
|
621
615
|
},
|
|
622
616
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
623
617
|
update: store => {
|
|
624
|
-
store.data.delete(
|
|
625
|
-
store.data.delete(
|
|
618
|
+
store.data.delete(defaultDataIdFromObject(branch));
|
|
619
|
+
store.data.delete(defaultDataIdFromObject(pullRequest));
|
|
626
620
|
}
|
|
627
621
|
});
|
|
628
622
|
return data.closePullRequest;
|
|
@@ -651,7 +645,7 @@ class GraphQLAPI extends _API.default {
|
|
|
651
645
|
variables: {
|
|
652
646
|
createPullRequestInput: {
|
|
653
647
|
baseRefName: this.branch,
|
|
654
|
-
body:
|
|
648
|
+
body: DEFAULT_PR_BODY,
|
|
655
649
|
title,
|
|
656
650
|
headRefName: headReference,
|
|
657
651
|
repositoryId: repository.id
|
|
@@ -664,23 +658,26 @@ class GraphQLAPI extends _API.default {
|
|
|
664
658
|
pullRequest
|
|
665
659
|
} = mutationResult.createPullRequest;
|
|
666
660
|
const pullRequestData = {
|
|
667
|
-
repository:
|
|
661
|
+
repository: {
|
|
662
|
+
...pullRequest.repository,
|
|
668
663
|
pullRequest
|
|
669
|
-
}
|
|
664
|
+
}
|
|
670
665
|
};
|
|
671
|
-
store.writeQuery(
|
|
666
|
+
store.writeQuery({
|
|
667
|
+
...this.getPullRequestQuery(pullRequest.number),
|
|
672
668
|
data: pullRequestData
|
|
673
|
-
})
|
|
669
|
+
});
|
|
674
670
|
}
|
|
675
671
|
});
|
|
676
672
|
const {
|
|
677
673
|
pullRequest
|
|
678
674
|
} = data.createPullRequest;
|
|
679
|
-
return
|
|
675
|
+
return {
|
|
676
|
+
...pullRequest,
|
|
680
677
|
head: {
|
|
681
678
|
sha: pullRequest.headRefOid
|
|
682
679
|
}
|
|
683
|
-
}
|
|
680
|
+
};
|
|
684
681
|
}
|
|
685
682
|
async createBranch(branchName, sha) {
|
|
686
683
|
const owner = this.repoOwner;
|
|
@@ -704,21 +701,24 @@ class GraphQLAPI extends _API.default {
|
|
|
704
701
|
branch
|
|
705
702
|
} = mutationResult.createRef;
|
|
706
703
|
const branchData = {
|
|
707
|
-
repository:
|
|
704
|
+
repository: {
|
|
705
|
+
...branch.repository,
|
|
708
706
|
branch
|
|
709
|
-
}
|
|
707
|
+
}
|
|
710
708
|
};
|
|
711
|
-
store.writeQuery(
|
|
709
|
+
store.writeQuery({
|
|
710
|
+
...this.getBranchQuery(branchName, owner, name),
|
|
712
711
|
data: branchData
|
|
713
|
-
})
|
|
712
|
+
});
|
|
714
713
|
}
|
|
715
714
|
});
|
|
716
715
|
const {
|
|
717
716
|
branch
|
|
718
717
|
} = data.createRef;
|
|
719
|
-
return
|
|
718
|
+
return {
|
|
719
|
+
...branch,
|
|
720
720
|
ref: `${branch.prefix}${branch.name}`
|
|
721
|
-
}
|
|
721
|
+
};
|
|
722
722
|
}
|
|
723
723
|
async createBranchAndPullRequest(branchName, sha, title) {
|
|
724
724
|
const owner = this.originRepoOwner;
|
|
@@ -736,7 +736,7 @@ class GraphQLAPI extends _API.default {
|
|
|
736
736
|
},
|
|
737
737
|
createPullRequestInput: {
|
|
738
738
|
baseRefName: this.branch,
|
|
739
|
-
body:
|
|
739
|
+
body: DEFAULT_PR_BODY,
|
|
740
740
|
title,
|
|
741
741
|
headRefName: branchName,
|
|
742
742
|
repositoryId: repository.id
|
|
@@ -752,24 +752,29 @@ class GraphQLAPI extends _API.default {
|
|
|
752
752
|
pullRequest
|
|
753
753
|
} = mutationResult.createPullRequest;
|
|
754
754
|
const branchData = {
|
|
755
|
-
repository:
|
|
755
|
+
repository: {
|
|
756
|
+
...branch.repository,
|
|
756
757
|
branch
|
|
757
|
-
}
|
|
758
|
+
}
|
|
758
759
|
};
|
|
759
760
|
const pullRequestData = {
|
|
760
|
-
repository:
|
|
761
|
+
repository: {
|
|
762
|
+
...pullRequest.repository,
|
|
761
763
|
branch
|
|
762
|
-
}
|
|
763
|
-
origin:
|
|
764
|
+
},
|
|
765
|
+
origin: {
|
|
766
|
+
...pullRequest.repository,
|
|
764
767
|
pullRequest
|
|
765
|
-
}
|
|
768
|
+
}
|
|
766
769
|
};
|
|
767
|
-
store.writeQuery(
|
|
770
|
+
store.writeQuery({
|
|
771
|
+
...this.getBranchQuery(branchName, owner, name),
|
|
768
772
|
data: branchData
|
|
769
|
-
})
|
|
770
|
-
store.writeQuery(
|
|
773
|
+
});
|
|
774
|
+
store.writeQuery({
|
|
775
|
+
...this.getPullRequestAndBranchQuery(branchName, pullRequest.number),
|
|
771
776
|
data: pullRequestData
|
|
772
|
-
})
|
|
777
|
+
});
|
|
773
778
|
}
|
|
774
779
|
});
|
|
775
780
|
const {
|
|
@@ -798,7 +803,6 @@ class GraphQLAPI extends _API.default {
|
|
|
798
803
|
if (data.repository.file) {
|
|
799
804
|
return data.repository.file.sha;
|
|
800
805
|
}
|
|
801
|
-
throw new
|
|
806
|
+
throw new APIError('Not Found', 404, API_NAME);
|
|
802
807
|
}
|
|
803
|
-
}
|
|
804
|
-
exports.default = GraphQLAPI;
|
|
808
|
+
}
|
package/dist/esm/fragments.js
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.treeEntry = exports.repository = exports.pullRequest = exports.object = exports.fileEntry = exports.branch = exports.blobWithText = void 0;
|
|
7
|
-
var _graphqlTag = require("graphql-tag");
|
|
8
|
-
const repository = exports.repository = (0, _graphqlTag.gql)`
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
export const repository = gql`
|
|
9
3
|
fragment RepositoryParts on Repository {
|
|
10
4
|
id
|
|
11
5
|
isFork
|
|
12
6
|
}
|
|
13
7
|
`;
|
|
14
|
-
const blobWithText =
|
|
8
|
+
export const blobWithText = gql`
|
|
15
9
|
fragment BlobWithTextParts on Blob {
|
|
16
10
|
id
|
|
17
11
|
text
|
|
18
12
|
is_binary: isBinary
|
|
19
13
|
}
|
|
20
14
|
`;
|
|
21
|
-
const object =
|
|
15
|
+
export const object = gql`
|
|
22
16
|
fragment ObjectParts on GitObject {
|
|
23
17
|
id
|
|
24
18
|
sha: oid
|
|
25
19
|
}
|
|
26
20
|
`;
|
|
27
|
-
const branch =
|
|
21
|
+
export const branch = gql`
|
|
28
22
|
fragment BranchParts on Ref {
|
|
29
23
|
commit: target {
|
|
30
24
|
...ObjectParts
|
|
@@ -39,7 +33,7 @@ const branch = exports.branch = (0, _graphqlTag.gql)`
|
|
|
39
33
|
${object}
|
|
40
34
|
${repository}
|
|
41
35
|
`;
|
|
42
|
-
const pullRequest =
|
|
36
|
+
export const pullRequest = gql`
|
|
43
37
|
fragment PullRequestParts on PullRequest {
|
|
44
38
|
id
|
|
45
39
|
baseRefName
|
|
@@ -69,7 +63,7 @@ const pullRequest = exports.pullRequest = (0, _graphqlTag.gql)`
|
|
|
69
63
|
}
|
|
70
64
|
${repository}
|
|
71
65
|
`;
|
|
72
|
-
const treeEntry =
|
|
66
|
+
export const treeEntry = gql`
|
|
73
67
|
fragment TreeEntryParts on TreeEntry {
|
|
74
68
|
path: name
|
|
75
69
|
sha: oid
|
|
@@ -77,7 +71,7 @@ const treeEntry = exports.treeEntry = (0, _graphqlTag.gql)`
|
|
|
77
71
|
mode
|
|
78
72
|
}
|
|
79
73
|
`;
|
|
80
|
-
const fileEntry =
|
|
74
|
+
export const fileEntry = gql`
|
|
81
75
|
fragment FileEntryParts on TreeEntry {
|
|
82
76
|
name
|
|
83
77
|
sha: oid
|