From 931399dd6eb675e06d59ac57ecfefc1b82467271 Mon Sep 17 00:00:00 2001 From: Asheer Rizvi Date: Wed, 15 Nov 2023 19:35:04 +0530 Subject: [PATCH] fix: used merge-upstream to sync fork & upstream (#6504) * fix: used merge-upstream to sync fork & upstream * fix: merge-upstream api call * fix: use fork repo name when calling merge-upstream * refactor: make it compatible with existing unit tests * style: lint some unrelated code --------- Co-authored-by: Martin Jagodic Co-authored-by: Anze Demsar --- .../src/implementation.tsx | 37 +++++++++++++------ website/gatsby-config.js | 4 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/packages/decap-cms-backend-github/src/implementation.tsx b/packages/decap-cms-backend-github/src/implementation.tsx index 2d350d2aab2d..5a448e746f82 100644 --- a/packages/decap-cms-backend-github/src/implementation.tsx +++ b/packages/decap-cms-backend-github/src/implementation.tsx @@ -283,19 +283,34 @@ export default class GitHub implements Implementation { return Promise.resolve(); } - if (!(await this.forkExists({ token }))) { + // If a fork exists merge it with upstream + // otherwise create a new fork. + const currentUser = await this.currentUser({ token }); + const repoName = this.originRepo.split('/')[1]; + this.repo = `${currentUser.login}/${repoName}`; + this.useOpenAuthoring = true; + + if (await this.forkExists({ token })) { + return fetch(`${this.apiRoot}/repos/${this.repo}/merge-upstream`, { + method: 'POST', + headers: { + Authorization: `token ${token}`, + }, + body: JSON.stringify({ + branch: this.branch, + }), + }); + } else { await getPermissionToFork(); - } - const fork = await fetch(`${this.apiRoot}/repos/${this.originRepo}/forks`, { - method: 'POST', - headers: { - Authorization: `token ${token}`, - }, - }).then(res => res.json()); - this.useOpenAuthoring = true; - this.repo = fork.full_name; - return this.pollUntilForkExists({ repo: fork.full_name, token }); + const fork = await fetch(`${this.apiRoot}/repos/${this.originRepo}/forks`, { + method: 'POST', + headers: { + Authorization: `token ${token}`, + }, + }).then(res => res.json()); + return this.pollUntilForkExists({ repo: fork.full_name, token }); + } } async authenticate(state: Credentials) { diff --git a/website/gatsby-config.js b/website/gatsby-config.js index 34286797e4bf..cf71086471d6 100644 --- a/website/gatsby-config.js +++ b/website/gatsby-config.js @@ -14,9 +14,9 @@ module.exports = { }, plugins: [ { - resolve: "gatsby-plugin-google-tagmanager", + resolve: 'gatsby-plugin-google-tagmanager', options: { - id: "GTM-WQFP7W4H", + id: 'GTM-WQFP7W4H', }, }, {