From ed12ffb81c0643c170d19be5270b57fdb5e05bd8 Mon Sep 17 00:00:00 2001 From: Nguyen Hong Phuc Date: Tue, 7 May 2019 01:13:19 +0900 Subject: [PATCH 1/6] add compatibility for Coffeescript 2 --- src/bot.coffee | 9 +++++---- src/message.coffee | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/bot.coffee b/src/bot.coffee index a44ba84a..0fc5103b 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -15,8 +15,9 @@ class SlackBot extends Adapter # @param {Object} options.rtm - RTM configuration options for SlackClient # @param {Object} options.rtmStart - options for `rtm.start` Web API method ### - constructor: (@robot, @options) -> - super + constructor: (robot, @options) -> + super(robot) + @robot = robot @robot.logger.info "hubot-slack adapter v#{pkg.version}" @client = new SlackClient @options, @robot @@ -287,9 +288,9 @@ class SlackBot extends Adapter @robot.logger.debug "Received presence update message for users: #{u.id for u in users} with status: #{event.presence}" @receive new PresenceMessage(users, event.presence) - + else if event.type is "file_shared" - + # Once again Hubot expects all user objects to have a room property that is used in the envelope for the message # after it is received. If the reaction is to a message, then the `event.item.channel` contain a conversation ID. # Otherwise reactions can be on files and file comments, which are "global" and aren't contained in a diff --git a/src/message.coffee b/src/message.coffee index 2dc02890..c277f55f 100644 --- a/src/message.coffee +++ b/src/message.coffee @@ -17,10 +17,11 @@ class ReactionMessage extends Message # custom integration (not part of a Slack app with a bot user), then this value will be undefined. # @param {string} event_ts - A String of the reaction event timestamp. ### - constructor: (@type, @user, @reaction, @item_user, @item, @event_ts) -> - super @user + constructor: (@type, user, @reaction, @item_user, @item, @event_ts) -> + super user + @user = user @type = @type.replace("reaction_", "") - + class FileSharedMessage extends Message ###* @@ -31,8 +32,9 @@ class FileSharedMessage extends Message # @param {string} file_id - A String identifying the file_id of the file that was shared. # @param {string} event_ts - A String of the file_shared event timestamp. ### - constructor: (@user, @file_id, @event_ts) -> - super @user + constructor: (user, @file_id, @event_ts) -> + super user + @user = user class PresenceMessage extends Message @@ -79,7 +81,12 @@ class SlackTextMessage extends TextMessage # @param {string} robot_name - The Slack username for this robot # @param {string} robot_alias - The alias for this robot ### - constructor: (@user, @text, rawText, @rawMessage, channel_id, robot_name, robot_alias) -> + constructor: (user, text, rawText, rawMessage, channel_id, robot_name, robot_alias) -> + super user, text, rawMessage.ts + + @user = user + @text = text + @rawMessage = rawMessage # private instance properties @_channel_id = channel_id @_robot_name = robot_name @@ -90,8 +97,6 @@ class SlackTextMessage extends TextMessage @thread_ts = @rawMessage.thread_ts if @rawMessage.thread_ts? @mentions = [] - super @user, @text, @rawMessage.ts - ###* # Build the text property, a flat string representation of the contents of this message. # @@ -262,4 +267,4 @@ class SlackTextMessage extends TextMessage exports.SlackTextMessage = SlackTextMessage exports.ReactionMessage = ReactionMessage exports.PresenceMessage = PresenceMessage -exports.FileSharedMessage = FileSharedMessage \ No newline at end of file +exports.FileSharedMessage = FileSharedMessage From cabcd37c4cb81ea74f2aac55dd72e5f876b73c5f Mon Sep 17 00:00:00 2001 From: Nguyen Hong Phuc Date: Tue, 7 May 2019 01:15:35 +0900 Subject: [PATCH 2/6] Test compatibility with hubot 3 and coffeescript 2 Add COFFEESCRIPT_VERSION variable to env of .travis.yml --- .travis.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c8fa38a..1ea17366 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,12 +9,16 @@ node_js: - "4" - "4.2" env: - - HUBOT_VERSION=">=2.0 <3" - - HUBOT_VERSION="^3.0" + - HUBOT_VERSION=">=2.0 <3" COFFEESCRIPT_VERSION=">=1.6.3 <2.0" + - HUBOT_VERSION="^3.0" COFFEESCRIPT_VERSION=">=1.6.3 <2.0" + - HUBOT_VERSION="^3.0" COFFEESCRIPT_VERSION="^2.0" after_success: - npm run codecov # The second step here installs the specific hubot version determined # by the `env` specified in the matrix. That lets us test against # multiple Hubot versions. This is a bit messy, but works around # package.json only being able to specify one version. -script: npm install && npm install hubot@"$HUBOT_VERSION" && npm test +script: + - npm install &&\ + npm install hubot@"$HUBOT_VERSION" coffeescript@"$COFFEESCRIPT_VERSION" &&\ + npm test From d8a5e992c403bd9a3a82c227c4334a20b2eb9ab3 Mon Sep 17 00:00:00 2001 From: Nguyen Hong Phuc Date: Tue, 7 May 2019 01:28:07 +0900 Subject: [PATCH 3/6] Fix test script --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1ea17366..3c07a7da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,4 @@ after_success: # by the `env` specified in the matrix. That lets us test against # multiple Hubot versions. This is a bit messy, but works around # package.json only being able to specify one version. -script: - - npm install &&\ - npm install hubot@"$HUBOT_VERSION" coffeescript@"$COFFEESCRIPT_VERSION" &&\ - npm test +script: npm install && npm install hubot@"$HUBOT_VERSION" coffeescript@"$COFFEESCRIPT_VERSION" && npm test From 46407def083a141c3c95a86e54cd3eaa9722fdbf Mon Sep 17 00:00:00 2001 From: Nguyen Hong Phuc Date: Tue, 7 May 2019 16:05:39 +0900 Subject: [PATCH 4/6] Exclude run tests with coffeescript 2, hubot 3 on nodejs <=5 --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3c07a7da..e8cb1324 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,14 @@ env: - HUBOT_VERSION=">=2.0 <3" COFFEESCRIPT_VERSION=">=1.6.3 <2.0" - HUBOT_VERSION="^3.0" COFFEESCRIPT_VERSION=">=1.6.3 <2.0" - HUBOT_VERSION="^3.0" COFFEESCRIPT_VERSION="^2.0" +matrix: + exclude: + - node_js: "4.2" + env: HUBOT_VERSION="^3.0" COFFEESCRIPT_VERSION="^2.0" + - node_js: "4" + env: HUBOT_VERSION="^3.0" COFFEESCRIPT_VERSION="^2.0" + - node_js: "5" + env: HUBOT_VERSION="^3.0" COFFEESCRIPT_VERSION="^2.0" after_success: - npm run codecov # The second step here installs the specific hubot version determined From 95d96a787f6e6f9198e9086b09209a5ef1d6aae5 Mon Sep 17 00:00:00 2001 From: Nguyen Hong Phuc Date: Tue, 7 May 2019 16:31:31 +0900 Subject: [PATCH 5/6] Explain why excluded tests with Coffeescript 2 on nodejs <= 5 --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index e8cb1324..2315184e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,10 @@ env: - HUBOT_VERSION=">=2.0 <3" COFFEESCRIPT_VERSION=">=1.6.3 <2.0" - HUBOT_VERSION="^3.0" COFFEESCRIPT_VERSION=">=1.6.3 <2.0" - HUBOT_VERSION="^3.0" COFFEESCRIPT_VERSION="^2.0" +# Excluding tests with Coffeescript 2 on nodejs version <= 5 +# because the syntax incompatible issue. Coffeescript 2 use +# destructuring assignment syntax at https://git.io/fjcq2 but +# nodejs <= 5 doesn't support. matrix: exclude: - node_js: "4.2" From 31653622f19fa5e925eb1f6ca5b138eea51a090f Mon Sep 17 00:00:00 2001 From: Nguyen Hong Phuc Date: Tue, 7 May 2019 16:32:12 +0900 Subject: [PATCH 6/6] Refactoring: change to 'super robot' --- src/bot.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bot.coffee b/src/bot.coffee index 0fc5103b..e691b032 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -16,7 +16,7 @@ class SlackBot extends Adapter # @param {Object} options.rtmStart - options for `rtm.start` Web API method ### constructor: (robot, @options) -> - super(robot) + super robot @robot = robot @robot.logger.info "hubot-slack adapter v#{pkg.version}" @client = new SlackClient @options, @robot