Skip to content

Instantly share code, notes, and snippets.

@chengjianhua
Created January 5, 2019 11:49
Show Gist options
  • Save chengjianhua/a7ea079c67447c73aa8b96f62b78e773 to your computer and use it in GitHub Desktop.
Save chengjianhua/a7ea079c67447c73aa8b96f62b78e773 to your computer and use it in GitHub Desktop.
format-git-commit-message
const rawMessage = `Merge branch 'fix/bundle' into 'develop'
asdasdasdasdasd
fix(bundle): fix bug in bundle_edit
See merge request frontend/darwin-yy!63`;
const firstLineBreakIndex = rawMessage.indexOf('\n');
let computedMessage;
if (firstLineBreakIndex + 1 >= rawMessage.length) {
computedMessage = rawMessage;
} else {
const nextToFirstLineBreak = rawMessage[firstLineBreakIndex + 1];
if (nextToFirstLineBreak !== '\n') {
computedMessage =
rawMessage.substring(0, firstLineBreakIndex) +
' ' +
rawMessage
.substring(firstLineBreakIndex + 1, rawMessage.length)
.trimLeft();
} else {
return rawMessage;
}
}
return computedMessage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment