Skip to content

Commit

Permalink
Prettier cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Moran committed May 11, 2020
1 parent 418776f commit 5cb133e
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 116 deletions.
25 changes: 12 additions & 13 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module.exports = function(grunt) {
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-release');

grunt.loadNpmTasks("grunt-release");

grunt.initConfig({
release: {
options: {
github: {
repo: "AirVantage/hubot-jira-issue-fetcher",
accessTokenVar: "GITHUB_ACCESS_TOKEN"
}
}
}
});
grunt.initConfig({
release: {
options: {
github: {
repo: 'AirVantage/hubot-jira-issue-fetcher',
accessTokenVar: 'GITHUB_ACCESS_TOKEN',
},
},
},
});
};
30 changes: 15 additions & 15 deletions lib/jira.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const JiraApi = require('jira-client');

module.exports = function(config) {
const jira = new JiraApi({
protocol: 'https',
host: config.jiraHost,
username: config.jiraUser,
password: config.jiraPwd,
apiVersion: '2',
strictSSL: true
});
module.exports = function (config) {
const jira = new JiraApi({
protocol: 'https',
host: config.jiraHost,
username: config.jiraUser,
password: config.jiraPwd,
apiVersion: '2',
strictSSL: true,
});

function getIssuesByKeys(keys) {
return jira.searchJira(`key in (${keys.join(',')})`).then(res => res.issues);
}
function getIssuesByKeys(keys) {
return jira.searchJira(`key in (${keys.join(',')})`).then((res) => res.issues);
}

return {
getIssuesByKeys: keys => getIssuesByKeys(keys)
};
return {
getIssuesByKeys: (keys) => getIssuesByKeys(keys),
};
};
110 changes: 54 additions & 56 deletions lib/messageFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,76 @@ const _ = require('lodash');

let config;

module.exports = configuration => {
config = configuration;
module.exports = (configuration) => {
config = configuration;

return {
buildDetailedMessages: issues => _.map(issues, buildDetailedMessage),
buildMessages: issues => _.map(issues, buildMessage),
buildErrorMessage: error => buildErrorMessage(error)
};
return {
buildDetailedMessages: (issues) => _.map(issues, buildDetailedMessage),
buildMessages: (issues) => _.map(issues, buildMessage),
buildErrorMessage: (error) => buildErrorMessage(error),
};
};

function buildDetailedMessage(issue) {
return {
fallback: issue.fields.summary,
color: getColorForStatus(issue.fields.status.name),
author_name: issue.fields.assignee ? issue.fields.assignee.displayName : 'Unassigned',
author_icon: issue.fields.assignee ? issue.fields.assignee.avatarUrls['16x16'] : null,
title: `${issue.key}: ${issue.fields.summary}`,
title_link: `https://${config.jiraHost}/browse/${issue.key}`,
text: issue.fields.description,
fields: [
{
title: 'Status',
value: issue.fields.status.name
}
]
};
return {
fallback: issue.fields.summary,
color: getColorForStatus(issue.fields.status.name),
author_name: issue.fields.assignee ? issue.fields.assignee.displayName : 'Unassigned',
author_icon: issue.fields.assignee ? issue.fields.assignee.avatarUrls['16x16'] : null,
title: `${issue.key}: ${issue.fields.summary}`,
title_link: `https://${config.jiraHost}/browse/${issue.key}`,
text: issue.fields.description,
fields: [
{
title: 'Status',
value: issue.fields.status.name,
},
],
};
}

function buildMessage(issue) {
return {
fallback: issue.fields.summary,
color: getColorForStatus(issue.fields.status.name),
author_name: issue.fields.assignee ? issue.fields.assignee.displayName : 'Unassigned',
author_icon: issue.fields.assignee ? issue.fields.assignee.avatarUrls['16x16'] : null,
text: `<https://${config.jiraHost}/browse/${issue.key}|${issue.key}> \`${issue.fields.status.name}\` ${
issue.fields.summary
}`,
mrkdwn_in: ['text']
};
return {
fallback: issue.fields.summary,
color: getColorForStatus(issue.fields.status.name),
author_name: issue.fields.assignee ? issue.fields.assignee.displayName : 'Unassigned',
author_icon: issue.fields.assignee ? issue.fields.assignee.avatarUrls['16x16'] : null,
text: `<https://${config.jiraHost}/browse/${issue.key}|${issue.key}> \`${issue.fields.status.name}\` ${issue.fields.summary}`,
mrkdwn_in: ['text'],
};
}

function getColorForStatus(status) {
switch (status) {
case 'In Development':
case 'In Review':
case 'Resolved':
return '#00AEAF';
case 'Incomplete':
return 'warning';
case 'Closed':
case 'Deployed':
case 'Declined':
return 'good';
case 'Error':
return '#E53B30';
default:
return '#A0ACAF';
}
switch (status) {
case 'In Development':
case 'In Review':
case 'Resolved':
return '#00AEAF';
case 'Incomplete':
return 'warning';
case 'Closed':
case 'Deployed':
case 'Declined':
return 'good';
case 'Error':
return '#E53B30';
default:
return '#A0ACAF';
}
}

function isUnknownKeyError(errorMessage) {
return errorMessage && (errorMessage.indexOf('does not exist') !== -1 || errorMessage.indexOf('is invalid') !== -1);
return errorMessage && (errorMessage.indexOf('does not exist') !== -1 || errorMessage.indexOf('is invalid') !== -1);
}

function buildErrorMessage(error) {
let message = 'Hmmm... something went wrong :thinking_face:',
errorMessage = _.get(error, 'errorMessages[0]');
let message = 'Hmmm... something went wrong :thinking_face:',
errorMessage = _.get(error, 'errorMessages[0]');

if (isUnknownKeyError(errorMessage)) {
const chunks = errorMessage.split("'");
message = `:exclamation: \`${chunks[1]}\` cannot be found`;
}
if (isUnknownKeyError(errorMessage)) {
const chunks = errorMessage.split("'");
message = `:exclamation: \`${chunks[1]}\` cannot be found`;
}

return message;
return message;
}
18 changes: 9 additions & 9 deletions lib/messageParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const _ = require('lodash');

const ALL_JIRA_KEY_MATCHER = /[A-Z0-9]*-\d+/g;

module.exports = configuration => {
return {
extractIssueKeys: message => {
let keys = message.text.toUpperCase().match(ALL_JIRA_KEY_MATCHER);
keys = _.filter(keys, issueKey => _.includes(configuration.projectsKeys, issueKey.split('-')[0]));
message.issueKeys = keys;
module.exports = (configuration) => {
return {
extractIssueKeys: (message) => {
let keys = message.text.toUpperCase().match(ALL_JIRA_KEY_MATCHER);
keys = _.filter(keys, (issueKey) => _.includes(configuration.projectsKeys, issueKey.split('-')[0]));
message.issueKeys = keys;

return message;
}
};
return message;
},
};
};
45 changes: 22 additions & 23 deletions test/messageParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@ import test from 'ava';
import messageParser from '../lib/messageParser';

const configuration = {
jiraHost: 'issues.sierrawireless.com',
projectsKeys: 'PLTFRS,PLTBUGS,ALT1250'.split(',')
jiraHost: 'issues.sierrawireless.com',
projectsKeys: 'PLTFRS,PLTBUGS,ALT1250'.split(','),
};

const parser = messageParser(configuration);

test('parse simple key', t => {
const message = parser.extractIssueKeys({
text: 'Working on pltfrs-333. And ALT1250-362, PLTBUGS-3333! '
});
t.is(message.issueKeys.length, 3);
test('parse simple key', (t) => {
const message = parser.extractIssueKeys({
text: 'Working on pltfrs-333. And ALT1250-362, PLTBUGS-3333! ',
});
t.is(message.issueKeys.length, 3);
});


test('parse URLs', t => {
const message = parser.extractIssueKeys({
text: 'Working on https://issues.sierrawireless.com/browse/PLTBUGS-3333! '
});
t.is(message.issueKeys.length, 1);
test('parse URLs', (t) => {
const message = parser.extractIssueKeys({
text: 'Working on https://issues.sierrawireless.com/browse/PLTBUGS-3333! ',
});
t.is(message.issueKeys.length, 1);
});

test('only returns known issues', t => {
const message = parser.extractIssueKeys({
text: 'Working on PLTFRS-3456 and TOTO-25'
});
t.is(message.issueKeys.length, 1);
test('only returns known issues', (t) => {
const message = parser.extractIssueKeys({
text: 'Working on PLTFRS-3456 and TOTO-25',
});
t.is(message.issueKeys.length, 1);
});

test('returns empty array when no issue found', t => {
const message = parser.extractIssueKeys({
text: 'Working TOTO-25'
});
t.is(message.issueKeys.length, 0);
test('returns empty array when no issue found', (t) => {
const message = parser.extractIssueKeys({
text: 'Working TOTO-25',
});
t.is(message.issueKeys.length, 0);
});

0 comments on commit 5cb133e

Please sign in to comment.