Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converted rocketchat-integrations coffee to js #6502

Merged
merged 3 commits into from
Mar 29, 2017

Conversation

ggazzo
Copy link
Member

@ggazzo ggazzo commented Mar 27, 2017

@RocketChat/core

@@ -0,0 +1,366 @@
/* globals Api Meteor Restivus logger processWebhookMessage*/
// TODO: remove globals
const vm = Npm.require('vm');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use import instead of require

const buildSandbox = function(store) {
if (store == null) {
store = {};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use default values instead of this condition

return compiledScript.script;
}
const script = integration.scriptCompiled;
let vmScript = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change from undefined to null?

try {
script = getIntegrationScript(this.integration);
} catch (error) {
const e = error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why declare a new var?

const result = vm.runInNewContext('script.process_incoming_request({ request: request })', sandbox, {
timeout: 3000
});
if (result && result.console.error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result.console?

if (result && result.console.error) {
return RocketChat.API.v1.failure(result.error);
}
this.bodyParams = result != null ? result.content : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify with this.bodyParams = result && result.content;

logger.incoming.debug('[Process Incoming Request result of Trigger', this.integration.name, ':]');
logger.incoming.debug('result', this.bodyParams);
} catch (error) {
const e = error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this declaration?

}
return RocketChat.API.v1.success();
} catch (error) {
const e = error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this declaration?

}
};

Object.keys(RocketChat.models).filter(function(k) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we turn these into single line arrow functions? Would clean this up quite a bit.

return compiledScript.script;
}
const script = integration.scriptCompiled;
const sandboxItems = buildSandbox();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break this out using the spread operator? const { store, sandbox } = buildSandbox(); And then use it below, as it'd clean this up and make it very similar to how the outgoing webhook script looks as well.


const compiledScripts = {};

const buildSandbox = function(store = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for variables instead of named functions in this entire file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the "way" that I chose wrong. I'll fix it. There are one difference if I tried to overwrite the function.

const buildSandbox = function(store = {}) {}
.
.
.
buildSandbox = anotherFunction(){}<- exception

logger.incoming.info('Add integration', options.name);
logger.incoming.debug(options);
Meteor.runAsUser(user._id, function() {
switch (options['event']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this to options.event so the assessors are like the other ones for options.

avatar: this.integration.avatar,
emoji: this.integration.emoji
};
if (this.integration.scriptEnabled === true && (this.integration.scriptCompiled != null) && this.integration.scriptCompiled.trim() !== '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the extra ()'s around the middle condition?

}
};
try {
const sandboxItems = buildSandbox(compiledScripts[this.integration._id].store);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, use the object spread. 👍

};
};

Api.addRoute(':integrationId/:userId/:token', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the { authRequired: true } be moved into the same line and not several lines, this way it looks like the api definitions for the api v1.

@engelgabriel engelgabriel modified the milestone: 0.55.0 Mar 29, 2017
@rodrigok rodrigok merged commit bc5878a into RocketChat:develop Mar 29, 2017
Syirrus pushed a commit to Syirrus/Rocket.Chat that referenced this pull request Mar 31, 2017
…nto clarapy-v4

Changed over home.coffee & help.coffee to .js

* 'develop' of https://github.com/RocketChat/Rocket.Chat: (162 commits)
  Remove coffeescript package from ui-flextab
  Remove coffeescript package from ui-sidenav
  Update PULL_REQUEST_TEMPLATE.md
  Fix Outgoing Webhooks Retrying Not Respecting Enabled Status (RocketChat#6478)
  Convert Theme Package to JS (RocketChat#6491)
  Fix typo of the safari pinned tab label (RocketChat#6487)
  fix channel merge option of user preferences (RocketChat#6493)
  converted Rocketchat logger coffee to js (RocketChat#6495)
  converted rocketchat-integrations coffee to js (RocketChat#6502)
  'allow reacting' should be a toggle option (RocketChat#6522)
  Add to HISTORY.md
  Fix backup codes remaining not showing
  Fix ESLint
  Fix ESLint
  Fix review
  Fix review
  Fix review
  fix import issue
  fix
  fix
  ...

# Conflicts:
#	packages/rocketchat-lib/server/lib/PushNotification.js
#	packages/rocketchat-ui/client/views/app/home.coffee
#	packages/rocketchat-ui/package.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants