Skip to content

Commit c15304f

Browse files
author
Claire Nord
committed
update: eslint, incorporate decaffeinate recommendations
1 parent 3a98da2 commit c15304f

1 file changed

Lines changed: 31 additions & 39 deletions

File tree

disabled_scripts/update.js

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
/*
2-
* decaffeinate suggestions:
3-
* DS102: Remove unnecessary code created because of implicit returns
4-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
5-
*/
61
// Description:
72
// Allows hubot to update itself using git pull and npm update.
8-
// If updates are downloaded you'll need to restart hubot, for example using "hubot die" (restart using a watcher like forever.js).
3+
// If updates are downloaded you'll need to restart hubot, for example using "hubot
4+
// die" (restart using a watcher like forever.js).
95
//
106
// Shamelessly stolen from: https://github.com/github/hubot-scripts/blob/master/src/scripts/update.coffee
117
// ... with some slight modifications.
@@ -22,66 +18,62 @@
2218
// Author:
2319
// benjamine, Detry322
2420

25-
const child_process = require('child_process');
26-
const downloaded_updates = false;
21+
const childProcess = require('child_process');
2722

28-
const restart = function(res) {
29-
res.send("Restarting...");
30-
return setTimeout(() => process.exit()
31-
, 500); // Give process some time to send message
23+
const restart = (res) => {
24+
res.send('Restarting...');
25+
setTimeout(() => process.exit(),
26+
500); // Give process some time to send message
3227
};
3328

34-
const send = function(res, should_send, message) {
35-
if (should_send) {
36-
return res.send(message);
29+
const send = (res, shouldSend, message) => {
30+
if (shouldSend) {
31+
res.send(message);
3732
}
3833
};
3934

40-
const update = function(res, send_std, send_err) {
35+
const update = (res, sendStd, sendErr) => {
4136
try {
42-
send(res, send_std, "fetching latest source code...");
43-
return child_process.exec('git fetch --all >/dev/null 2>&1 && git log --oneline --graph --stat HEAD..@{u} && git reset --hard @{u}', function(error, stdout, stderr) {
37+
send(res, sendStd, 'fetching latest source code...');
38+
childProcess.exec('git fetch --all >/dev/null 2>&1 && git log --oneline --graph --stat HEAD..@{u} && git reset --hard @{u}', (error, stdout, stderr) => {
4439
if (error) {
45-
send(res, send_err, "git fetch/reset failed: ```" + stderr + "```");
40+
send(res, sendErr, `git fetch/reset failed: \`\`\`${stderr}\`\`\``);
4641
} else {
47-
send(res, send_std, `\`\`\`${stdout}\`\`\``);
42+
send(res, sendStd, `\`\`\`${stdout}\`\`\``);
4843
}
4944
try {
50-
send(res, send_std, "npm update...");
51-
return child_process.exec('npm update', function(error, stdout, stderr) {
52-
if (error) {
53-
send(res, send_err, "npm update failed: ```" + stderr + "```");
45+
send(res, sendStd, 'npm update...');
46+
childProcess.exec('npm update', (error1, stdout1, stderr1) => {
47+
if (error1) {
48+
send(res, sendErr, `npm update failed: \`\`\`${stderr1}\`\`\``);
5449
} else {
55-
const output = stdout+'';
50+
const output = `${stdout1}`;
5651
if (/node_modules/.test(output)) {
57-
send(res, send_std, "some dependencies updated:\n```" + output + "```");
52+
send(res, sendStd, `some dependencies updated:\n\`\`\`${output}\`\`\``);
5853
} else {
59-
send(res, send_std, "all dependencies are up-to-date");
54+
send(res, sendStd, 'all dependencies are up-to-date');
6055
}
6156
}
62-
return restart(res);
57+
restart(res);
6358
});
6459
} catch (error1) {
65-
error = error1;
66-
return send(res, send_err, "npm update failed: " + error);
60+
send(res, sendErr, `npm update failed: ${error1}`);
6761
}
6862
});
6963
} catch (error1) {
70-
const error = error1;
71-
return send(res, send_err, "git pull failed: " + error);
64+
send(res, sendErr, `git pull failed: ${error1}`);
7265
}
7366
};
7467

75-
module.exports = function(robot) {
68+
module.exports = (robot) => {
69+
robot.respond(/restart( yourself)?$/i, (res) => restart(res));
7670

77-
robot.respond(/restart( yourself)?$/i, res => restart(res));
78-
79-
robot.respond(/update silent$/i, function(res) {
80-
res.send("Updating...");
71+
robot.respond(/update silent$/i, (res) => {
72+
res.send('Updating...');
8173
return update(res, false, true);
8274
});
8375

84-
robot.respond(/update super silent$/i, res => update(res, false, false));
76+
robot.respond(/update super silent$/i, (res) => update(res, false, false));
8577

86-
return robot.respond(/update( yourself)?$/i, res => update(res, true, true));
78+
robot.respond(/update( yourself)?$/i, (res) => update(res, true, true));
8779
};

0 commit comments

Comments
 (0)