Created
January 17, 2020 06:44
-
-
Save vvscode/b7bad44be81412243305b8c75aa5bfb4 to your computer and use it in GitHub Desktop.
commit-message.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* It takes commit message and append a branch name below | |
*/ | |
const fs = require('fs'); | |
const childProcess = require('child_process'); | |
const commitMessageFile = process.argv[2]; | |
/** | |
* feature/foobar-RN-52/FOO-123/BAR-456 => BAR-456 | |
* feature/fooBAR-123 => BAR-123 | |
* feature/foobBAR-123-some-test => BAR-123 | |
* BAR-123-some-test => BAR-123 | |
*/ | |
const extractTicketName = str => (str.match(/[A-Z]+-\d+/g) || []).pop(); | |
const commitMessage = fs.readFileSync(commitMessageFile).toString(); | |
const currentGitBranch = childProcess.execSync('git rev-parse --abbrev-ref HEAD').toString(); | |
const jiraTicketFromBranch = extractTicketName(currentGitBranch); | |
if (jiraTicketFromBranch) { | |
const editedCommitMessage = `${commitMessage}\n\n${jiraTicketFromBranch}`; | |
fs.writeFileSync(commitMessageFile, editedCommitMessage); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
package.json
: