Skip to content

Instantly share code, notes, and snippets.

@johnie
Last active May 29, 2018 09:02
Show Gist options
  • Save johnie/332d220c9fb753ee8d46cabd4bf34173 to your computer and use it in GitHub Desktop.
Save johnie/332d220c9fb753ee8d46cabd4bf34173 to your computer and use it in GitHub Desktop.
Using npx to commit messages with JIRA Ticket

MRG Git

Using npx to commit messages with JIRA Ticket

Usage

$ npx https://gist.github.com/johnie/332d220c9fb753ee8d46cabd4bf34173 "This is a commit message"
//=> git commit -am "JIRA-455 This is a commit message"

Tip

alias mrgit='npx https://gist.github.com/johnie/332d220c9fb753ee8d46cabd4bf34173 '

Licence

MIT @ /johnie

#!/usr/bin/env node
'use strict';
const execa = require('execa');
const re = /((?!([A-Z0-9]{1,10})-?$)[A-Z]{1}[A-Z0-9]+-\d+)/g
const COMMANDS = {
branch: 'git rev-parse --abbrev-ref HEAD',
commit: 'git commit -am'
};
const _ = {
ticket: arg => arg.match(re)[0],
formatMsg: (branch, input) => `\"${_.ticket(branch)} ${input}\"`.trim(),
command: async cmd => await execa.shell(cmd),
async mrGit(input) {
if (!input) {
console.log('Supply a message!');
process.exit(1);
}
const { stdout: branch } = await _.command(COMMANDS.branch);
const msg = _.formatMsg(branch, input);
await _.command(`${COMMANDS.commit} ${msg}`);
return msg;
}
};
(async () => {
const [,,input] = process.argv;
console.log(await _.mrGit(input));
})();
{"name": "mrg-git", "version": "0.0.1", "bin": "./mrg-git.js", "dependencies": {"execa": "^0.10.0"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment