|
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 | | - */ |
6 | 1 | // Description: |
7 | 2 | // 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). |
9 | 5 | // |
10 | 6 | // Shamelessly stolen from: https://github.com/github/hubot-scripts/blob/master/src/scripts/update.coffee |
11 | 7 | // ... with some slight modifications. |
|
22 | 18 | // Author: |
23 | 19 | // benjamine, Detry322 |
24 | 20 |
|
25 | | -const child_process = require('child_process'); |
26 | | -const downloaded_updates = false; |
| 21 | +const childProcess = require('child_process'); |
27 | 22 |
|
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 |
32 | 27 | }; |
33 | 28 |
|
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); |
37 | 32 | } |
38 | 33 | }; |
39 | 34 |
|
40 | | -const update = function(res, send_std, send_err) { |
| 35 | +const update = (res, sendStd, sendErr) => { |
41 | 36 | 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) => { |
44 | 39 | if (error) { |
45 | | - send(res, send_err, "git fetch/reset failed: ```" + stderr + "```"); |
| 40 | + send(res, sendErr, `git fetch/reset failed: \`\`\`${stderr}\`\`\``); |
46 | 41 | } else { |
47 | | - send(res, send_std, `\`\`\`${stdout}\`\`\``); |
| 42 | + send(res, sendStd, `\`\`\`${stdout}\`\`\``); |
48 | 43 | } |
49 | 44 | 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}\`\`\``); |
54 | 49 | } else { |
55 | | - const output = stdout+''; |
| 50 | + const output = `${stdout1}`; |
56 | 51 | if (/node_modules/.test(output)) { |
57 | | - send(res, send_std, "some dependencies updated:\n```" + output + "```"); |
| 52 | + send(res, sendStd, `some dependencies updated:\n\`\`\`${output}\`\`\``); |
58 | 53 | } else { |
59 | | - send(res, send_std, "all dependencies are up-to-date"); |
| 54 | + send(res, sendStd, 'all dependencies are up-to-date'); |
60 | 55 | } |
61 | 56 | } |
62 | | - return restart(res); |
| 57 | + restart(res); |
63 | 58 | }); |
64 | 59 | } catch (error1) { |
65 | | - error = error1; |
66 | | - return send(res, send_err, "npm update failed: " + error); |
| 60 | + send(res, sendErr, `npm update failed: ${error1}`); |
67 | 61 | } |
68 | 62 | }); |
69 | 63 | } catch (error1) { |
70 | | - const error = error1; |
71 | | - return send(res, send_err, "git pull failed: " + error); |
| 64 | + send(res, sendErr, `git pull failed: ${error1}`); |
72 | 65 | } |
73 | 66 | }; |
74 | 67 |
|
75 | | -module.exports = function(robot) { |
| 68 | +module.exports = (robot) => { |
| 69 | + robot.respond(/restart( yourself)?$/i, (res) => restart(res)); |
76 | 70 |
|
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...'); |
81 | 73 | return update(res, false, true); |
82 | 74 | }); |
83 | 75 |
|
84 | | - robot.respond(/update super silent$/i, res => update(res, false, false)); |
| 76 | + robot.respond(/update super silent$/i, (res) => update(res, false, false)); |
85 | 77 |
|
86 | | - return robot.respond(/update( yourself)?$/i, res => update(res, true, true)); |
| 78 | + robot.respond(/update( yourself)?$/i, (res) => update(res, true, true)); |
87 | 79 | }; |
0 commit comments