From 885a15f55b13bca694765f47107450b6400f88fc Mon Sep 17 00:00:00 2001 From: Shaun Burdick Date: Wed, 3 Feb 2016 11:33:49 -0500 Subject: [PATCH] Changed the regex to be a string that we convert to regexp. Removed default values from Dockerfile --- Dockerfile | 22 +++++++++++----------- README.md | 1 + config.default.js | 6 ++++-- lib/bot.js | 5 ++++- lib/config.js | 2 +- package.json | 4 ++-- test/config.test.js | 2 +- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6870963..e260a73 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,19 +3,19 @@ FROM node:latest MAINTAINER Shaun Burdick ENV NODE_ENV=production \ - JIRA_PROTOCOL=https \ - JIRA_HOST=jira.yourdomain.com \ - JIRA_PORT=443 \ + JIRA_PROTOCOL= \ + JIRA_HOST= \ + JIRA_PORT= \ JIRA_BASE= \ - JIRA_USER=username \ - JIRA_PASS=password \ - JIRA_API_VERSION=latest \ - JIRA_VERBOSE=false \ - JIRA_STRICT_SSL=false \ - JIRA_REGEX=([A-Z]{1}[A-Z0-9]+\-[0-9]+) \ + JIRA_USER= \ + JIRA_PASS= \ + JIRA_API_VERSION= \ + JIRA_VERBOSE= \ + JIRA_STRICT_SSL= \ + JIRA_REGEX= \ JIRA_SPRINT_FIELD= \ - SLACK_TOKEN=xoxb-foo \ - SLACK_AUTO_RECONNECT=true + SLACK_TOKEN= \ + SLACK_AUTO_RECONNECT= ADD . /usr/src/myapp diff --git a/README.md b/README.md index cba8733..aadbf71 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ The config file should be filled out as follows: - apiVersion: string, API version slug, usually latest - verbose: boolean, Verbose logging - strictSSL: boolean, set false for self-signed certificates + - regex: string, a string that will be used as a RegExp to match tickets, defaults to '([A-Z][A-Z0-9]+\-[0-9]+)' - sprintField: string, If using greenhopper, set the custom field that holds sprint information (customfield_1xxxx) - customFields: - Add any custom fields you would like to display diff --git a/config.default.js b/config.default.js index a490764..8b6e0e8 100644 --- a/config.default.js +++ b/config.default.js @@ -11,9 +11,11 @@ const config = { apiVersion: 'latest', verbose: false, strictSSL: false, - regex: /([A-Z]{1}[A-Z0-9]+\-[0-9]+)/g, + regex: '([A-Z][A-Z0-9]+\-[0-9]+)', sprintField: '', - customFields: {}, + customFields: { + + }, }, slack: { token: 'xoxb-Your-Token', diff --git a/lib/bot.js b/lib/bot.js index eb173fc..9053af8 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -25,6 +25,9 @@ class Bot { this.controller = Botkit.slackbot(); + this.ticketRegExp = new RegExp(config.jira.regex, 'g'); + logger.info(`Ticket Matching Regexp: ${this.ticketRegExp}`); + this.jira = new JiraApi( config.jira.protocol, config.jira.host, @@ -210,7 +213,7 @@ class Bot { return retVal; } const uniques = {}; - const found = message.match(this.config.jira.regex); + const found = message.match(this.ticketRegExp); const now = Date.now(); let ticketHash; if (found && found.length) { diff --git a/lib/config.js b/lib/config.js index 5c4949f..f17e007 100644 --- a/lib/config.js +++ b/lib/config.js @@ -38,7 +38,7 @@ function parse(config) { config.jira.apiVersion = process.env.JIRA_API_VERSION || config.jira.apiVersion; config.jira.verbose = parseBool(process.env.JIRA_VERBOSE) || config.jira.verbose; config.jira.strictSSL = parseBool(process.env.JIRA_STRICT_SSL) || config.jira.strictSSL; - config.jira.regex = process.env.JIRA_REGEX ? new RegExp(process.env.JIRA_REGEX, 'g') : config.jira.regex; + config.jira.regex = process.env.JIRA_REGEX || config.jira.regex; config.jira.sprintField = process.env.JIRA_SPRINT_FIELD || config.jira.sprintField; config.slack.token = process.env.SLACK_TOKEN || config.slack.token; diff --git a/package.json b/package.json index c156c75..8cbe785 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slack-jirabot", - "version": "2.0.1", + "version": "2.0.3", "description": "Slackbot for interacting with JIRA", "main": "app.js", "private": true, @@ -10,7 +10,7 @@ "unit": "faucet", "lint": "eslint .", "coverage": "istanbul cover --include-all-sources tape test/*.test.js", - "coveralls": "cat ./coverage/lcov.info | coveralls --verbose", + "coveralls": "cat ./coverage/lcov.info | coveralls", "travis": "npm run coverage && npm run coveralls" }, "author": "Shaun Burdick ", diff --git a/test/config.test.js b/test/config.test.js index d09d190..bcf254a 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -37,7 +37,7 @@ test('Config: use env values over file values', (assert) => { process.env.JIRA_REGEX = 'foo'; const conf = Config.parse(rawConfig); - assert.deepEqual(conf.jira.regex, /foo/g); + assert.deepEqual(conf.jira.regex, 'foo'); assert.end(); });