-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Set correct branch when it's not specified in the config #5844
Changes from 5 commits
47ebd16
61904c8
c3f1fc0
90c9f9c
43fbe2d
8436443
3edc3ce
7ccbac6
e5407c3
3f0e711
a506b5d
cc5f53a
cec8fbb
69d124a
c726ee0
bbafe77
11e187c
67904b1
37531e1
b118aea
fa8e03c
a2add4a
eb9ce4b
8319d4b
87350d9
7b0fda0
542a1d9
3694c75
346ac8b
714a57e
f77dba5
9c14584
acd47a8
98541a3
7dc9dae
1ecd946
efa741f
7bf6724
2dfa3f6
ef664f6
89a2806
54f4314
183a0c3
02ef43c
5d1855c
b03d6a8
13f0863
1aba0da
1f76df9
394dc9b
0fc96ab
6eb2ac3
6bfcf09
53f143a
38f73a4
af9cd9b
a5da48a
14ddaa7
02311f4
1789e6f
34375f4
7f6de72
ec0ff89
48e7175
676631f
614a5b0
20caf5f
8db27d6
ad161df
d4e4fe3
c6b05f8
5827471
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -116,7 +116,7 @@ export default class GitHub implements Implementation { | |||||
this.repo = this.originRepo = config.backend.repo || ''; | ||||||
} | ||||||
this.alwaysForkEnabled = config.backend.always_fork || false; | ||||||
this.branch = config.backend.branch?.trim() || 'master'; | ||||||
this.branch = config.backend.branch?.trim() || ''; | ||||||
this.apiRoot = config.backend.api_root || 'https://api.github.com'; | ||||||
this.token = ''; | ||||||
this.squashMerges = config.backend.squash_merges || false; | ||||||
|
@@ -180,6 +180,20 @@ export default class GitHub implements Implementation { | |||||
: this.authenticate(user); | ||||||
} | ||||||
|
||||||
async setDefaultBranch() { | ||||||
try { | ||||||
const masterBranch = await this.api!.getBranch('master'); | ||||||
if (!masterBranch) { | ||||||
// Get default branch of the repo | ||||||
const defaultBranch = await this.api!.newGetDefaultBranch(); | ||||||
this.branch = defaultBranch || ''; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Should we default to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two things:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sounds good! How about adding the helpers to https://github.com/netlify/netlify-cms/blob/master/packages/netlify-cms-lib-util/src/backendUtil.ts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be backendUtils or API.ts is the place? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either
I definitely don't need it soon, and in any case no need to change your work schedule for us. We are the ones who should adjust our schedule to contributors. |
||||||
} else { | ||||||
this.branch = 'master'; | ||||||
} | ||||||
} catch (e) { | ||||||
console.warn(e); | ||||||
bytrangle marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
} | ||||||
async pollUntilForkExists({ repo, token }: { repo: string; token: string }) { | ||||||
const pollDelay = 250; // milliseconds | ||||||
let repoExists = false; | ||||||
|
@@ -331,6 +345,13 @@ export default class GitHub implements Implementation { | |||||
if (!isCollab) { | ||||||
throw new Error('Your GitHub user account does not have access to this repo.'); | ||||||
} | ||||||
// In the constructor, `this.branch` is set by reading the config file | ||||||
// If it is an empty string at this point, | ||||||
// it means there is no `branch` property set in the config | ||||||
|
||||||
if (this.branch === '') { | ||||||
await this.setDefaultBranch(); | ||||||
} | ||||||
|
||||||
// Authorized user | ||||||
return { ...user, token: state.token as string, useOpenAuthoring: this.useOpenAuthoring }; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we drop the
try/catch
and let the calling function handle any errors (it already has atry/catch
)?