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

feat: Add ability to define PR title #125

Merged
merged 3 commits into from
May 9, 2019
Merged

feat: Add ability to define PR title #125

merged 3 commits into from
May 9, 2019

Conversation

cjskillingstad
Copy link
Contributor

@cjskillingstad cjskillingstad commented May 7, 2019

Resolves issue #126

  • Added the ability to define an optional custom PR title
  • Allows for a template literal string so the consumer can access the base branch name and commit message strings
    Example: "prTitle": "${commitMessages} backport for ${baseBranch}"
  • This is especially helpful for those using standard version who want to have the commit messages first for the prefix notation
  • Defaults to the same pr title as before ("[${baseBranch}] ${commitMessages}")
  • Updated unit tests
  • Updated documentation

.map(commit => commit.message)
.join(' | ')
.slice(0, 200);

return `[${baseBranch}] ${commitMessages}`;
// prTitle could include baseBranch or commitMessages in template literal
return eval('`' + prTitle + '`');
Copy link
Owner

Choose a reason for hiding this comment

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

I think it's better to avoid eval and explicitly replacing certain tokens. Eg.

prTitle
  .replace('${baseBranch}', baseBranch)
  .replace('${commitMessages}', commitMessages)

It's not as powerful but it's explicit and will make it more obvious when breaking the contract with the end user. Plus, I'm afraid of eval 😱

Would this solution still work for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this can definitely still work. I was weary of using eval in the first place. Fixed in fe109c0

Copy link
Owner

Choose a reason for hiding this comment

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

Looks great!

I noticed that $ is treated as a special character and everything after it will be stripped. So the following won't work: --prTitle="Custom title: ${commitMessages}"

This is a limitation with bash. Quick google turned up this and this.

Workarounds

  • Using single quotes : --prTitle='Custom title: ${commitMessages}'
  • Escaping: --prTitle="Custom title: \${commitMessages}"

To bypass the problem altogether it might be better to drop the $ and just use curly brackets - that way users won't have to resort to the workarounds above:

prTitle
  .replace('{baseBranch}', baseBranch)
  .replace('{commitMessages}', commitMessages)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, didn't think about that. Removed the dollar sign notation in
8e9bbe5

@sorenlouv
Copy link
Owner

Hi @cjskillingstad, Thanks for the contribution. Much appreciated!

@sorenlouv sorenlouv merged commit 040156d into sorenlouv:master May 9, 2019
@sorenlouv
Copy link
Owner

This is great. Will make a new release shortly.

@sorenlouv
Copy link
Owner

Released in v4.5.4

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

Successfully merging this pull request may close these issues.

None yet

2 participants