hubot 11.1.5 → 11.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,4 +47,6 @@ See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT).
47
47
 
48
48
  [Hubot by Hubotics](https://www.theoldrobots.com/hubot.html)
49
49
 
50
- [Automating Inefficiencies](https://zachholman.com/2011/01/automating-inefficiencies/)
50
+ [Automating Inefficiencies](https://zachholman.com/2011/01/automating-inefficiencies/)
51
+
52
+ [Getting Started with Hubot](https://www.youtube.com/watch?v=A7fh6RIzGrw)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hubot",
3
- "version": "11.1.5",
3
+ "version": "11.1.7",
4
4
  "author": "hubot",
5
5
  "keywords": [
6
6
  "github",
package/src/GenHubot.mjs CHANGED
@@ -49,7 +49,7 @@ function runCommands (hubotDirectory, options) {
49
49
  // This is a test script.
50
50
  //
51
51
 
52
- export default (robot) => {
52
+ export default async (robot) => {
53
53
  robot.respond(/helo$/, async res => {
54
54
  await res.reply("HELO World! I'm Dumbotheelephant.")
55
55
  })
@@ -92,7 +92,7 @@ export default (robot) => {
92
92
  this.robot.emit('play', envelope, ...strings)
93
93
  }
94
94
 
95
- run () {
95
+ async run () {
96
96
  // This is required to get the scripts loaded
97
97
  this.emit('connected')
98
98
  }
@@ -108,7 +108,7 @@ export default (robot) => {
108
108
  }
109
109
  }
110
110
  export default {
111
- use (robot) {
111
+ async use (robot) {
112
112
  return new DummyAdapter(robot)
113
113
  }
114
114
  }
@@ -128,12 +128,14 @@ export default (robot) => {
128
128
  describe('Xample testing Hubot scripts', () => {
129
129
  let robot = null
130
130
  beforeEach(async () => {
131
+ process.env.EXPRESS_PORT = 0
131
132
  robot = new Robot(dummyRobot, true, 'Dumbotheelephant')
132
133
  await robot.loadAdapter()
133
134
  await robot.run()
134
135
  await robot.loadFile('./scripts', 'Xample.mjs')
135
136
  })
136
137
  afterEach(() => {
138
+ delete process.env.EXPRESS_PORT
137
139
  robot.shutdown()
138
140
  })
139
141
  it('should handle /helo request', async () => {
package/src/Robot.mjs CHANGED
@@ -332,21 +332,25 @@ class Robot {
332
332
  async loadmjs (filePath) {
333
333
  const forImport = this.prepareForImport(filePath)
334
334
  const script = await import(forImport)
335
+ let result = null
335
336
  if (typeof script?.default === 'function') {
336
- script.default(this)
337
+ result = await script.default(this)
337
338
  } else {
338
339
  this.logger.warning(`Expected ${filePath} (after preparing for import ${forImport}) to assign a function to export default, got ${typeof script}`)
339
340
  }
341
+ return result
340
342
  }
341
343
 
342
344
  async loadjs (filePath) {
343
345
  const forImport = this.prepareForImport(filePath)
344
346
  const script = (await import(forImport)).default
347
+ let result = null
345
348
  if (typeof script === 'function') {
346
- script(this)
349
+ result = await script(this)
347
350
  } else {
348
351
  this.logger.warning(`Expected ${filePath} (after preparing for import ${forImport}) to assign a function to module.exports, got ${typeof script}`)
349
352
  }
353
+ return result
350
354
  }
351
355
 
352
356
  // Public: Loads a file in path.
@@ -362,16 +366,17 @@ class Robot {
362
366
  // see https://github.com/hubotio/hubot/issues/1355
363
367
  if (['js', 'mjs'].indexOf(ext) === -1) {
364
368
  this.logger.debug(`Skipping unsupported file type ${full}`)
365
- return
369
+ return null
366
370
  }
367
-
371
+ let result = null
368
372
  try {
369
- await this[`load${ext}`](full)
373
+ result = await this[`load${ext}`](full)
370
374
  this.parseHelp(full)
371
375
  } catch (error) {
372
376
  this.logger.error(`Unable to load ${full}: ${error.stack}`)
373
377
  throw error
374
378
  }
379
+ return result
375
380
  }
376
381
 
377
382
  // Public: Loads every script in the given path.
@@ -381,12 +386,14 @@ class Robot {
381
386
  // Returns nothing.
382
387
  async load (path) {
383
388
  this.logger.debug(`Loading scripts from ${path}`)
389
+ const results = []
384
390
  try {
385
391
  const folder = await File.readdir(path, { withFileTypes: true })
386
392
  for await (const file of folder) {
387
393
  if (file.isDirectory()) continue
388
394
  try {
389
- await this.loadFile(path, file.name)
395
+ const result = await this.loadFile(path, file.name)
396
+ results.push(result)
390
397
  } catch (e) {
391
398
  this.logger.error(`Error loading file ${file.name} - ${e.stack}`)
392
399
  }
@@ -394,6 +401,7 @@ class Robot {
394
401
  } catch (e) {
395
402
  this.logger.error(`Path ${path} does not exist`)
396
403
  }
404
+ return results
397
405
  }
398
406
 
399
407
  // Public: Load scripts from packages specified in the
@@ -460,7 +468,7 @@ class Robot {
460
468
  if (stat) {
461
469
  app.use(express.static(stat))
462
470
  }
463
- const p = new Promise((resolve, reject) => {
471
+ return new Promise((resolve, reject) => {
464
472
  try {
465
473
  this.server = app.listen(port, address, () => {
466
474
  this.router = app
@@ -471,7 +479,6 @@ class Robot {
471
479
  reject(err)
472
480
  }
473
481
  })
474
- return p
475
482
  }
476
483
 
477
484
  // Setup an empty router object
@@ -75,20 +75,15 @@ class Shell extends Adapter {
75
75
  this.#rl.prompt()
76
76
  break
77
77
  }
78
+ if (input.length > 0) {
79
+ fs.appendFileSync(historyPath, `${input}\n`)
80
+ }
78
81
  const history = fs.readFileSync(historyPath, 'utf-8').split('\n').reverse()
79
82
  this.#rl.history = history
80
- this.#rl.on('line', line => {
81
- const input = line.trim()
82
- if (input.length === 0) return
83
- fs.appendFile(historyPath, `${input}\n`, err => {
84
- if (err) console.error(err)
85
- })
86
- })
87
83
  let userId = process.env.HUBOT_SHELL_USER_ID || '1'
88
84
  if (userId.match(/A\d+z/)) {
89
85
  userId = parseInt(userId)
90
86
  }
91
-
92
87
  const userName = process.env.HUBOT_SHELL_USER_NAME || 'Shell'
93
88
  const user = this.robot.brain.userForId(userId, { name: userName, room: 'Shell' })
94
89
  await this.receive(new TextMessage(user, input, 'messageId'))