Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/lib-node-utilities / bin / open-jira.js
Size: Mime:
const open = require('open');
const currentBranch = require('current-git-branch');
const chalk = require('chalk');
const { JIRA_KEYS } = require('./constants');

module.exports = () => {
	const branch = currentBranch();
	const jiraKeys = Object.keys(JIRA_KEYS);

	if (branch) {
		const branchParts = branch.split('-');
		const branchKey = branchParts[0];
		const ticketNumber = branchParts.length > 1 ? branchParts[1] : null;

		if (jiraKeys.indexOf(branchKey) > -1) {
			// We have found a branch name that begins with a JIRA KEY
			if (ticketNumber && !Number.isNaN(ticketNumber)) {
				const url = `https://doodleag.atlassian.net/browse/${branchKey}-${ticketNumber}`;
				console.log(`${chalk.cyan('Opening url')} ${url}`);
				open(url);
			} else {
				console.log(`${chalk.magenta('Your branch naming does not meet the pattern of')} XXX-000`);
			}
		} else {
			console.log(`${chalk.magenta('Could not find a recognized JIRA pattern with')} XXX-000`);
		}
	} else {
		console.log('No branch was found.');
	}
};