Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Last active February 7, 2017 09:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apaleslimghost/9d750124a0fde9c712834e09118b5818 to your computer and use it in GitHub Desktop.
Save apaleslimghost/9d750124a0fde9c712834e09118b5818 to your computer and use it in GitHub Desktop.

package-version-jira-release

Create a release on JIRA using the version number from package.json

usage

Create env variables JIRA_HOST (the hostname of your JIRA installation, which needs the REST API enabled), JIRA_PROJECT (the id of the project you want to create releases in, which should be a short alphabetic string), and JIRA_USERNAME & JIRA_PASSWORD (these should be for a user that has at least Project Admin permissions on the project). Run:

package-version-jira-release

If SOURCE_VERSION is set (i.e. it's running on Heroku), it'll be mentioned in the release description.

It's handy to run this with npm lifecycle scripts. You might consider postinstall, postpublish or heroku-postbuild.

licence

MIT

#!/usr/bin/env node
import logPromise from '@quarterto/log-promise';
import assertEnv from '@quarterto/assert-env';
import jiraCreateVersion from '@quarterto/jira-create-version';
import path from 'path';
const commit = process.env.SOURCE_VERSION;
const packagePath = path.resolve('package.json');
const {version, name} = require(packagePath);
if(process.env.JIRA_HOST) {
assertEnv(['JIRA_PROJECT', 'JIRA_USERNAME', 'JIRA_PASSWORD']);
logPromise(
`created version ${version} on JIRA`,
e => e.stack
)(jiraCreateVersion(`${name}-${version}`, {
description: `Release ${commit} to Heroku`,
hostname: process.env.JIRA_HOST,
project: process.env.JIRA_PROJECT,
user: process.env.JIRA_USERNAME,
pass: process.env.JIRA_PASSWORD,
})).catch(() => process.exit(1));
} else {
console.log(`⤼ No JIRA host, not creating release ${version}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment