decap-cms-backend-github 3.1.0-beta.0 → 3.1.0-beta.1

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.
@@ -252,23 +252,40 @@ class GitHub {
252
252
  this.useOpenAuthoring = false;
253
253
  return Promise.resolve();
254
254
  }
255
- if (!(await this.forkExists({
255
+
256
+ // If a fork exists merge it with upstream
257
+ // otherwise create a new fork.
258
+ const currentUser = await this.currentUser({
256
259
  token
257
- }))) {
258
- await getPermissionToFork();
259
- }
260
- const fork = await fetch(`${this.apiRoot}/repos/${this.originRepo}/forks`, {
261
- method: 'POST',
262
- headers: {
263
- Authorization: `token ${token}`
264
- }
265
- }).then(res => res.json());
260
+ });
261
+ const repoName = this.originRepo.split('/')[1];
262
+ this.repo = `${currentUser.login}/${repoName}`;
266
263
  this.useOpenAuthoring = true;
267
- this.repo = fork.full_name;
268
- return this.pollUntilForkExists({
269
- repo: fork.full_name,
264
+ if (await this.forkExists({
270
265
  token
271
- });
266
+ })) {
267
+ return fetch(`${this.apiRoot}/repos/${this.repo}/merge-upstream`, {
268
+ method: 'POST',
269
+ headers: {
270
+ Authorization: `token ${token}`
271
+ },
272
+ body: JSON.stringify({
273
+ branch: this.branch
274
+ })
275
+ });
276
+ } else {
277
+ await getPermissionToFork();
278
+ const fork = await fetch(`${this.apiRoot}/repos/${this.originRepo}/forks`, {
279
+ method: 'POST',
280
+ headers: {
281
+ Authorization: `token ${token}`
282
+ }
283
+ }).then(res => res.json());
284
+ return this.pollUntilForkExists({
285
+ repo: fork.full_name,
286
+ token
287
+ });
288
+ }
272
289
  }
273
290
  async authenticate(state) {
274
291
  this.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.1.0-beta.0",
4
+ "version": "3.1.0-beta.1",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/decaporg/decap-cms/tree/master/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": "26f650bbfd8b20611ad9bb8957ce2d889a1a9085"
43
+ "gitHead": "ab43e911c48666f7615761dac5ba9e4300bf3825"
44
44
  }
@@ -283,19 +283,34 @@ export default class GitHub implements Implementation {
283
283
  return Promise.resolve();
284
284
  }
285
285
 
286
- if (!(await this.forkExists({ token }))) {
286
+ // If a fork exists merge it with upstream
287
+ // otherwise create a new fork.
288
+ const currentUser = await this.currentUser({ token });
289
+ const repoName = this.originRepo.split('/')[1];
290
+ this.repo = `${currentUser.login}/${repoName}`;
291
+ this.useOpenAuthoring = true;
292
+
293
+ if (await this.forkExists({ token })) {
294
+ return fetch(`${this.apiRoot}/repos/${this.repo}/merge-upstream`, {
295
+ method: 'POST',
296
+ headers: {
297
+ Authorization: `token ${token}`,
298
+ },
299
+ body: JSON.stringify({
300
+ branch: this.branch,
301
+ }),
302
+ });
303
+ } else {
287
304
  await getPermissionToFork();
288
- }
289
305
 
290
- const fork = await fetch(`${this.apiRoot}/repos/${this.originRepo}/forks`, {
291
- method: 'POST',
292
- headers: {
293
- Authorization: `token ${token}`,
294
- },
295
- }).then(res => res.json());
296
- this.useOpenAuthoring = true;
297
- this.repo = fork.full_name;
298
- return this.pollUntilForkExists({ repo: fork.full_name, token });
306
+ const fork = await fetch(`${this.apiRoot}/repos/${this.originRepo}/forks`, {
307
+ method: 'POST',
308
+ headers: {
309
+ Authorization: `token ${token}`,
310
+ },
311
+ }).then(res => res.json());
312
+ return this.pollUntilForkExists({ repo: fork.full_name, token });
313
+ }
299
314
  }
300
315
 
301
316
  async authenticate(state: Credentials) {