bitcrowd / tickety-tick

A browser extension that helps you name branches and write better commit messages
MIT License
57 stars 10 forks source link

new helper to limit string length #233

Closed bitboxer closed 4 years ago

bitboxer commented 4 years ago

I would love to have a helper to limit string lenghts because the branch names are getting waaaay to long sometimes. So long that they break a build system I have to use for a customer right now :trollface: .

bitboxer commented 4 years ago

I will have some time to implement it in 2-3 weeks I think. So if you like it, ping me and I will try to do it.

pmeinhardt commented 4 years ago

Ha, interesting. 😁 Can you share which build system this is?

I am not 100% sure if there'll be time for us to work on this before you get around to it. I suggest whoever starts working on it, just drops a comment here. ✌️

To implement this, I think our template syntax needs to be extended. At the moment, the transforms/filters you can apply to template values do not accept/expect arguments.

My idea would be to update template.js to support the following syntax:

{type}/{title | slugify | limit(32)}

…so filters can have (optional) arguments.

Our helpers, instead of directly taking in the value would receive these "configuration" arguments and then return the filter function itself.

export const limit = (maxLength) => (s) => s.substring(0, maxLength);
export const lowercase = () => (s) => s.toLowerCase();
export const shellquote = () => (s) => typeof s === 'string' ? `'${s.replace(/'/g, "'\\''")}'` : "''";
export const slugify = () => createSlug({ separator: '-' });
export const trim = () => (s) => s.replace(/^\s+|\s+$/g, '');
export const uppercase = () => (s) => s.toUpperCase();
pmeinhardt commented 4 years ago

Thanks for proposing this. 💚

bitboxer commented 4 years ago

Its using aws amplify to generate branch previews and somehow the dns has a length limit and those branch names as subdomain make it explode 🤣 .

Also yes, I will extend the template language like you proposed 😉

bitboxer commented 4 years ago

@pmeinhardt thanks for implementing this 🥳