Skip to content

Commit

Permalink
fix: used merge-upstream to sync fork & upstream (#6504)
Browse files Browse the repository at this point in the history
* 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 <jagodicmartin1@gmail.com>
Co-authored-by: Anze Demsar <anze.demsar@p-m.si>
  • Loading branch information
3 people authored Nov 15, 2023
1 parent 91662c8 commit 931399d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
37 changes: 26 additions & 11 deletions packages/decap-cms-backend-github/src/implementation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions website/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ module.exports = {
},
plugins: [
{
resolve: "gatsby-plugin-google-tagmanager",
resolve: 'gatsby-plugin-google-tagmanager',
options: {
id: "GTM-WQFP7W4H",
id: 'GTM-WQFP7W4H',
},
},
{
Expand Down

0 comments on commit 931399d

Please sign in to comment.