Skip to content

Commit

Permalink
Merge pull request #2 from dowjones/feature/lint
Browse files Browse the repository at this point in the history
Feature/lint
  • Loading branch information
adamgruber authored Jun 15, 2016
2 parents 5122b67 + 45c9ff6 commit 35d6b05
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 44 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
"extends": "airbnb/legacy",
"rules": {
"func-names": 0,
"max-len": 0
}
};
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js

node_js:
- "4"
- "5"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#slack-slash-jira
[![npm](https://img.shields.io/npm/v/slack-slash-jira.svg?style=flat-square)](http://www.npmjs.com/package/slack-slash-jira) [![Build Status](https://travis-ci.org/dowjones/slack-slash-jira.svg?branch=master)](https://travis-ci.org/dowjones/slack-slash-jira)

Command handler for [slack-slash][ss] that makes it easy to get quick info on a Jira ticket right from Slack.

Expand Down
16 changes: 12 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
istanbul = require('gulp-istanbul');
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var eslint = require('gulp-eslint');

var mochaOpts = {
reporter: 'mochawesome'
Expand All @@ -12,6 +13,13 @@ var istanbulThresholdOpts = {
}
};

gulp.task('lint', function () {
return gulp.src(['./*.js', 'lib/**/*.js', 'test/**/*.js', '!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('test', function (cb) {
gulp.src(['lib/**/*.js', 'index.js'])
.pipe(istanbul())
Expand All @@ -25,4 +33,4 @@ gulp.task('test', function (cb) {
});
});

gulp.task('default', ['test']);
gulp.task('default', ['lint', 'test']);
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/slash-jira');
module.exports = require('./lib/slash-jira');
31 changes: 15 additions & 16 deletions lib/slash-jira.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
var _ = require('lodash'),
util = require('util'),
JiraApi = require('jira').JiraApi;
var util = require('util');
var JiraApi = require('jira').JiraApi;

var ERRORS = {
NO_ISSUE_SPECIFIED: 'Whoops, you didn\'t specify an issue number.',
INVALID_ISSUE: 'Uh oh, *%s* doesn\'t seem to be a valid issue number.'
};

module.exports = slashJira;

function _getRegExpFromString(inputstring) {
var flags = inputstring.replace(/.*\/([gimy]*)$/, '$1');
var pattern = inputstring.replace(new RegExp('^/(.*?)/'+flags+'$'), '$1');
var pattern = inputstring.replace(new RegExp('^/(.*?)/' + flags + '$'), '$1');
return new RegExp(pattern, flags);
}

function slashJira (token, options) {
function slashJira(token, options) {
this.token = token;
this.jiraOpts = options.jira;
this.jira = new JiraApi(
Expand All @@ -33,9 +30,9 @@ function slashJira (token, options) {
}

slashJira.prototype.handle = function (req, cb) {
var bodyText = req.body.text,
issueMatch = bodyText ? bodyText.match(this.jiraIssueRegEx) : undefined,
id;
var bodyText = req.body.text;
var issueMatch = bodyText ? bodyText.match(this.jiraIssueRegEx) : undefined;
var id;

if (!bodyText) {
return cb(ERRORS.NO_ISSUE_SPECIFIED);
Expand All @@ -44,9 +41,9 @@ slashJira.prototype.handle = function (req, cb) {
if (!issueMatch) {
return cb(util.format(ERRORS.INVALID_ISSUE, bodyText));
}

id = issueMatch[1] + '-' + issueMatch[3];
this._getJiraIssue(id, cb);
return this._getJiraIssue(id, cb);
};

slashJira.prototype._getJiraIssue = function (issueId, cb) {
Expand All @@ -55,7 +52,7 @@ slashJira.prototype._getJiraIssue = function (issueId, cb) {
if (err) {
return cb(err);
}
cb(null, self._createSlackMessage(jiraRes));
return cb(null, self._createSlackMessage(jiraRes));
});
};

Expand All @@ -68,13 +65,15 @@ slashJira.prototype._swapDisplayName = function (name) {
};

slashJira.prototype._createSlackMessage = function (jiraRes) {
var issueUrl = this.jiraIssueBaseUrl + jiraRes.key,
msg = '';
var issueUrl = this.jiraIssueBaseUrl + jiraRes.key;
var msg = '';

msg += util.format('<%s|*%s*: %s>\n', issueUrl, jiraRes.key, jiraRes.fields.summary);
msg += util.format('*Type:* %s\n', jiraRes.fields.issuetype.name);
msg += util.format('*Assigned to:* %s\n', this._swapDisplayName(jiraRes.fields.assignee.displayName));
msg += util.format('*Status:* %s', jiraRes.fields.status.name);

return msg;
};
};

module.exports = slashJira;
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slack-slash-jira",
"version": "1.0.0",
"version": "1.0.1",
"description": "Slack slash command handler for Jira. Get quick info on a Jira ticket right from Slack.",
"keywords": [
"slack",
Expand All @@ -10,11 +10,13 @@
],
"main": "index",
"dependencies": {
"jira": "git+https://github.com/adamgruber/node-jira.git",
"lodash": "^3.8.0"
"jira": "git+https://github.com/adamgruber/node-jira.git"
},
"devDependencies": {
"eslint": "^2.7.0",
"eslint-config-airbnb": "^6.2.0",
"gulp": "^3.8.11",
"gulp-eslint": "^2.0.0",
"gulp-istanbul": "^0.9.0",
"gulp-mocha": "^2.0.1",
"istanbul": "^0.3.14",
Expand All @@ -23,7 +25,7 @@
"sinon": "^1.14.1"
},
"scripts": {
"test": "gulp test"
"test": "gulp"
},
"author": "Adam Gruber",
"repository": {
Expand Down
39 changes: 20 additions & 19 deletions test/slash-jira-test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
var should = require('should'),
sinon = require('sinon'),
SlashJira = require('../lib/slash-jira');
/* global describe, beforeEach, it */
var should = require('should');
var sinon = require('sinon');
var SlashJira = require('../lib/slash-jira');
// var cb = function (){};

describe('slack-slash-jira', function () {
var token = '',
req = { body: {text: 'ABC-1234'} },
cb = function (){},
opts = {
jira: {},
jiraIssueRegEx: '/(^[a-z]+)(-?)(\\d+$)/i',
jiraIssueBaseUrl: ''
},
slashJira;
var token = '';
var req = { body: { text: 'ABC-1234' } };
var opts = {
jira: {},
jiraIssueRegEx: '/(^[a-z]+)(-?)(\\d+$)/i',
jiraIssueBaseUrl: ''
};
var slashJira;

beforeEach(function () {
slashJira = new SlashJira(token, opts);
Expand All @@ -25,9 +26,9 @@ describe('slack-slash-jira', function () {
key: 'ABC-1234',
fields: {
summary: 'Summary',
issuetype: {name: 'Task'},
assignee: {displayName: 'Gruber, Adam'},
status: {name: 'Resolved'}
issuetype: { name: 'Task' },
assignee: { displayName: 'Gruber, Adam' },
status: { name: 'Resolved' }
}
});
});
Expand All @@ -47,7 +48,7 @@ describe('slack-slash-jira', function () {
var stub = sinon.stub(slashJira.jira, 'findIssue', function (issue, cb) {
cb(expectedErrMsg);
});
slashJira.handle(req, function (err, msg) {
slashJira.handle(req, function (err) {
getIssueSpy.calledOnce.should.equal(true);
should.exist(err);
expectedErrMsg.should.equal(err);
Expand All @@ -70,14 +71,14 @@ describe('slack-slash-jira', function () {

it('returns an error if the issue number is invalid', function (done) {
var invalidReq = {
body: {text: 'ABC'}
body: { text: 'ABC' }
};
slashJira.handle(invalidReq, function (err) {
should.exist(err);
err.should.equal('Uh oh, *ABC* doesn\'t seem to be a valid issue number.');
done();
});
});
});
});

describe('_swapDisplayName', function () {
Expand All @@ -87,4 +88,4 @@ describe('slack-slash-jira', function () {
done();
});
});
});
});

0 comments on commit 35d6b05

Please sign in to comment.