Skip to content
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

Add branch name max length option to GitHub backend (closes #526) #862

Closed
wants to merge 1 commit into from

Conversation

Benaiah
Copy link
Contributor

@Benaiah Benaiah commented Dec 5, 2017

- Summary

Adds branch name max length option to GitHub backend. Closes #526.

- Test plan

Tested manually.

- Description for the changelog

@verythorough
Copy link
Contributor

verythorough commented Dec 5, 2017

Deploy preview ready!

Built with commit 45b1598

https://deploy-preview-862--netlify-cms-www.netlify.com

truncateSlugForBranchName(slug) {
const slugMaxLength = this.branchNameMaxLength - CMS_BRANCH_PREFIX.length;
return slug.length > slugMaxLength
? slug.substring(0, slugMaxLength)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just take out the ternary here? If the string is smaller than it, shouldn't the string just be left as-is? I'm not experienced enough with JS string behavior to know whether that is the case or not, but it seems to be.

@Benaiah
Copy link
Contributor Author

Benaiah commented Dec 5, 2017

@tech4him1 addressed your comment, please re-review.

@@ -15,6 +15,7 @@ export default class API {
this.branch = config.branch || "master";
this.repo = config.repo || "";
this.repoURL = `/repos/${ this.repo }`;
this.branchNameMaxLength = (config.backend && config.backend.branchNameMaxLength) || 40;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you actually test this line? I'm not sure how it works, seeing that config is not the actual config.yml, only the values that are passed in here: https://github.com/netlify/netlify-cms/blob/ca1ecc5fc04afdaad4726c2d0eb71e402f6e19a9/src/backends/github/implementation.js#L33

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we need to start rooting out ambiguous variable names like this, there's a lot of it in our source.

@verythorough
Copy link
Contributor

Deploy preview ready!

Built with commit 45b1598

https://deploy-preview-862--cms-demo.netlify.com

@tech4him1
Copy link
Contributor

tech4him1 commented Mar 27, 2018

@Benaiah Sorry for the delay. I'm seeing two things right now, one needs to be handled and one may not be:

If the branch_name_max_length is less than 5, we need to throw an error at config load point, since it always must be at least 5 chars to account for cms/.

If the branch_name_max_length is reduced after a post draft is created, the post will no longer show up in editorial workflow if it's slug had to be trimmed. I'm not sure if we can fix this, or just have a warning in the documentation.

@erquhart
Copy link
Contributor

I would say we aren't set up for branch names to change, so updating that config should only affect new branches and not existing branches.

@tech4him1
Copy link
Contributor

@erquhart I agree, do you have any suggestions on how that could be implemented?

@erquhart
Copy link
Contributor

Only reference/enforce it when creating branches.

@tech4him1
Copy link
Contributor

@erquhart I don't see how that works. If we save the metadata to a truncated name, how do we know what to get it back with without truncating? For example, if the slug is long-filename, and truncated it is long, how do we know what to get it as when attempting to read metadata for long-filename (assuming that the truncation length is different)?

@erquhart
Copy link
Contributor

I may be under thinking this, but I'd expect we'd set the same name for metadata and branch?

Sent with GitHawk

@tech4him1
Copy link
Contributor

tech4him1 commented Apr 20, 2018

Well, that's not really what I'm trying to point out, but I could be wrong. If we call retrieveMetadata with a slug (from updateUnpublishedEntryStatus for example), isn't that going to be the full path, not the truncated one? We have to truncate it to get the metadata or branch name, but to do that we have to assume the truncation length hasn't changed.

@erquhart
Copy link
Contributor

Hmm we'd need to find a way to avoid truncating for read purposes, maybe through changing the metadata we track so the branch name itself is recorded.

Sent with GitHawk

@tech4him1
Copy link
Contributor

That's the thing -- this PR currently truncates both the metadata filename and the branch name.

@erquhart
Copy link
Contributor

Ah, understood! We shouldn't do that, agreed.

@tech4him1
Copy link
Contributor

tech4him1 commented Apr 20, 2018

Also, do you still think the best way to track the branch name is by saving in the metadata, or do you have other suggestions here?

@erquhart
Copy link
Contributor

Haven't dug into it very deep, but I can't think of a better way at the moment. You?

@erquhart
Copy link
Contributor

Closing as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Long post titles can lead to invalid hostnames in Netlify deploy previews
4 participants