Skip to content

Commit 11aa5c2

Browse files
authored
Merge pull request #191 from StackStorm/redo-adapter-inheritance
Redo adapter inheritance
2 parents a1f8620 + fd61efc commit 11aa5c2

File tree

7 files changed

+91
-56
lines changed

7 files changed

+91
-56
lines changed

CHANGELOG.rst

+17-10
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,29 @@ Changelog
44
in development
55
--------------
66

7-
* Move babel-eslint dependency to devDependencies (bug fix)
8-
* Small refactor and more tests (for ``scripts/stackstorm.js``) (improvement)
9-
* Refactor chat providers into their own modules (improvement)
10-
* Modernize directory structure to be more consistent with other hubot plugins (improvement)
11-
* Split out the functionality of ``src/stackstorm.js`` into ``stackstorm_api.js`` and refactor it be a JS old style class with a wrapper (improvement)
7+
* Move babel-eslint dependency to devDependencies [PR #180] (bug fix)
8+
* Small refactor and more tests (for ``scripts/stackstorm.js``) [PR #185] (improvement)
9+
* Refactor chat providers into their own modules [PR #186] (improvement)
10+
* Modernize directory structure to be more consistent with other hubot plugins [PR #186, PR #191]
11+
(improvement)
12+
* Split out the functionality of ``src/stackstorm.js`` into ``stackstorm_api.js`` and refactor it
13+
to be a JS old style class with a wrapper [PR #187, PR #190] (improvement)
1214

1315
0.9.6
1416
-----
1517
* Don't consider failed alias execution as a critical reason to exit hubot (bug fix)
1618

1719
0.9.5
1820
-----
19-
* Exit hubot on invalid, expired ``ST2_API_KEY`` / ``ST2_AUTH_TOKEN`` or any other Unauthorized response from st2 server (bug fix)
20-
* When st2 username/password is used, re-generate st2 auth token in advance, giving enough time for request to complete, st2client.js (bug fix)
21+
* Exit hubot on invalid, expired ``ST2_API_KEY`` / ``ST2_AUTH_TOKEN`` or any other Unauthorized
22+
response from st2 server (bug fix)
23+
* When st2 username/password is used, re-generate st2 auth token in advance, giving enough time for
24+
request to complete, st2client.js (bug fix)
2125

2226
0.9.4
2327
-----
24-
* Exit hubot on unhandled promise rejections and uncaught exceptions, usually caused by unrecoverable errors (bug fix)
28+
* Exit hubot on unhandled promise rejections and uncaught exceptions, usually caused by
29+
unrecoverable errors (bug fix)
2530
* Add pagination support for action aliases - fixes #158 (bug fix)
2631

2732
0.9.3
@@ -31,7 +36,8 @@ in development
3136

3237
0.9.2
3338
-----
34-
* Rename ENV variable ``ST2_API`` -> ``ST2_API_URL`` for consistency, keep ``ST2_API`` for backwards compatibility (improvement)
39+
* Rename ENV variable ``ST2_API`` -> ``ST2_API_URL`` for consistency, keep ``ST2_API`` for
40+
backwards compatibility (improvement)
3541

3642
0.9.1
3743
-----
@@ -105,7 +111,8 @@ in development
105111
0.2.2
106112
-----
107113

108-
* Log a better error message if we fail to load the commands because of the StackStorm API unavailability.
114+
* Log a better error message if we fail to load the commands because of the StackStorm API
115+
unavailability.
109116

110117
0.2.1
111118
-----

src/lib/adapters/mattermost.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
var env = process.env;
1818
var util = require('util');
1919
var utils = require('./../utils');
20-
var SlackAdapter = require('./slack');
20+
var SlackLikeAdapter = require('./slack-like');
2121

2222

2323
function MattermostAdapter(robot) {
2424
var self = this;
25-
SlackAdapter.call(self, robot);
25+
SlackLikeAdapter.call(self, robot);
2626
}
2727

28-
util.inherits(MattermostAdapter, SlackAdapter);
28+
util.inherits(MattermostAdapter, SlackLikeAdapter);
2929

3030
MattermostAdapter.prototype.postData = function(data) {
3131
var self = this;

src/lib/adapters/msteams.js

-7
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,4 @@ MSTeamsAdapter.prototype.normalizeCommand = function (command) {
8989
return command;
9090
}
9191

92-
MSTeamsAdapter.prototype.normalizeAddressee = function(msg) {
93-
return {
94-
name: msg.message.user.name,
95-
room: msg.message.room
96-
};
97-
};
98-
9992
module.exports = MSTeamsAdapter;

src/lib/adapters/rocketchat.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
var env = process.env;
1818
var util = require('util');
1919
var utils = require('./../utils');
20-
var SlackAdapter = require('./slack');
20+
var SlackLikeAdapter = require('./slack-like');
2121

2222

2323
function RocketChatAdapter(robot) {
2424
var self = this;
25-
SlackAdapter.call(self, robot);
25+
SlackLikeAdapter.call(self, robot);
2626
}
2727

28-
util.inherits(RocketChatAdapter, SlackAdapter);
28+
util.inherits(RocketChatAdapter, SlackLikeAdapter);
2929

3030
RocketChatAdapter.prototype.postData = function(data) {
3131
var self = this;

src/lib/adapters/slack-like.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2019 Extreme Networks, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
"use strict";
16+
17+
var util = require('util');
18+
var utils = require('./../utils');
19+
var DefaultAdapter = require('./default');
20+
21+
22+
// NOTE: Be careful about making changes to this adapter, because the adapters
23+
// for Mattermost, Cisco Spark, and Rocketchat all inherit from this one
24+
function SlackLikeAdapter(robot) {
25+
var self = this;
26+
DefaultAdapter.call(self, robot);
27+
}
28+
29+
util.inherits(SlackLikeAdapter, DefaultAdapter);
30+
31+
SlackLikeAdapter.prototype.postData = function(data) {
32+
throw Error("Children of SlackLikeAdapter must override postData");
33+
};
34+
35+
SlackLikeAdapter.prototype.formatData = function(data) {
36+
if (utils.isNull(data)) {
37+
return "";
38+
}
39+
// For slack we do not truncate or format the result. This is because
40+
// data is posted to slack as a message attachment.
41+
return data;
42+
};
43+
44+
SlackLikeAdapter.prototype.formatRecipient = function(recipient) {
45+
return recipient;
46+
};
47+
48+
SlackLikeAdapter.prototype.normalizeCommand = function(command) {
49+
var self = this;
50+
command = DefaultAdapter.prototype.normalizeCommand.call(self, command);
51+
// replace left double quote with regular quote
52+
command = command.replace(/\u201c/g, '\u0022');
53+
// replace right double quote with regular quote
54+
command = command.replace(/\u201d/g, '\u0022');
55+
// replace left single quote with regular apostrophe
56+
command = command.replace(/\u2018/g, '\u0027');
57+
// replace right single quote with regular apostrophe
58+
command = command.replace(/\u2019/g, '\u0027');
59+
return command;
60+
};
61+
62+
module.exports = SlackLikeAdapter;

src/lib/adapters/slack.js

+3-30
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ var env = process.env;
1818
var util = require('util');
1919
var utils = require('./../utils');
2020
var messages = require('./../slack-messages');
21-
var DefaultAdapter = require('./default');
21+
var SlackLikeAdapter = require('./slack-like');
2222

2323

2424
// NOTE: Be careful about making changes to this adapter, because the adapters
2525
// for Mattermost, Cisco Spark, and Rocketchat all inherit from this one
2626
function SlackAdapter(robot) {
2727
var self = this;
28-
DefaultAdapter.call(self, robot);
28+
SlackLikeAdapter.call(self, robot);
2929

3030
// We monkey patch sendMessage function to send "parse" argument with the message so the text is not
3131
// formatted and parsed on the server side.
@@ -57,7 +57,7 @@ function SlackAdapter(robot) {
5757
}
5858
};
5959

60-
util.inherits(SlackAdapter, DefaultAdapter);
60+
util.inherits(SlackAdapter, SlackLikeAdapter);
6161

6262
SlackAdapter.prototype.postData = function(data) {
6363
var self = this;
@@ -224,31 +224,4 @@ SlackAdapter.prototype.postData = function(data) {
224224
}
225225
};
226226

227-
SlackAdapter.prototype.formatData = function(data) {
228-
if (utils.isNull(data)) {
229-
return "";
230-
}
231-
// For slack we do not truncate or format the result. This is because
232-
// data is posted to slack as a message attachment.
233-
return data;
234-
};
235-
236-
SlackAdapter.prototype.formatRecipient = function(recipient) {
237-
return recipient;
238-
};
239-
240-
SlackAdapter.prototype.normalizeCommand = function(command) {
241-
var self = this;
242-
command = SlackAdapter.super_.prototype.normalizeCommand.call(self, command);
243-
// replace left double quote with regular quote
244-
command = command.replace(/\u201c/g, '\u0022');
245-
// replace right double quote with regular quote
246-
command = command.replace(/\u201d/g, '\u0022');
247-
// replace left single quote with regular apostrophe
248-
command = command.replace(/\u2018/g, '\u0027');
249-
// replace right single quote with regular apostrophe
250-
command = command.replace(/\u2019/g, '\u0027');
251-
return command;
252-
};
253-
254227
module.exports = SlackAdapter;

src/lib/adapters/spark.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ var env = process.env;
1818
var util = require('util');
1919
var utils = require('./../utils');
2020
var DefaultAdapter = require('./default');
21-
var SlackAdapter = require('./slack');
21+
var SlackLikeAdapter = require('./slack-like');
2222

2323

2424
function SparkAdapter(robot) {
2525
var self = this;
26-
SlackAdapter.call(self, robot);
26+
SlackLikeAdapter.call(self, robot);
2727
}
2828

29-
util.inherits(SparkAdapter, SlackAdapter);
29+
util.inherits(SparkAdapter, SlackLikeAdapter);
3030

3131
SparkAdapter.prototype.postData = function(data) {
3232
var self = this;

0 commit comments

Comments
 (0)