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', }, }, {