hubot 11.1.4 → 11.1.6
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/package.json +1 -1
- package/src/Brain.mjs +2 -2
- package/src/GenHubot.mjs +5 -3
- package/src/Robot.mjs +27 -11
package/package.json
CHANGED
package/src/Brain.mjs
CHANGED
|
@@ -157,9 +157,9 @@ class Brain extends EventEmitter {
|
|
|
157
157
|
this.emit('loaded', this.data)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
// Public: Get an
|
|
160
|
+
// Public: Get an object of User objects stored in the brain.
|
|
161
161
|
//
|
|
162
|
-
// Returns an
|
|
162
|
+
// Returns an object of User objects.
|
|
163
163
|
users () {
|
|
164
164
|
return this.data.users
|
|
165
165
|
}
|
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
|
@@ -12,6 +12,7 @@ import { Listener, TextListener } from './Listener.mjs'
|
|
|
12
12
|
import Message from './Message.mjs'
|
|
13
13
|
import Middleware from './Middleware.mjs'
|
|
14
14
|
|
|
15
|
+
const File = fs.promises
|
|
15
16
|
const HUBOT_DEFAULT_ADAPTERS = ['Campfire', 'Shell']
|
|
16
17
|
const HUBOT_DOCUMENTATION_SECTIONS = ['description', 'dependencies', 'configuration', 'commands', 'notes', 'author', 'authors', 'examples', 'tags', 'urls']
|
|
17
18
|
|
|
@@ -331,21 +332,25 @@ class Robot {
|
|
|
331
332
|
async loadmjs (filePath) {
|
|
332
333
|
const forImport = this.prepareForImport(filePath)
|
|
333
334
|
const script = await import(forImport)
|
|
335
|
+
let result = null
|
|
334
336
|
if (typeof script?.default === 'function') {
|
|
335
|
-
script.default(this)
|
|
337
|
+
result = await script.default(this)
|
|
336
338
|
} else {
|
|
337
339
|
this.logger.warning(`Expected ${filePath} (after preparing for import ${forImport}) to assign a function to export default, got ${typeof script}`)
|
|
338
340
|
}
|
|
341
|
+
return result
|
|
339
342
|
}
|
|
340
343
|
|
|
341
344
|
async loadjs (filePath) {
|
|
342
345
|
const forImport = this.prepareForImport(filePath)
|
|
343
346
|
const script = (await import(forImport)).default
|
|
347
|
+
let result = null
|
|
344
348
|
if (typeof script === 'function') {
|
|
345
|
-
script(this)
|
|
349
|
+
result = await script(this)
|
|
346
350
|
} else {
|
|
347
351
|
this.logger.warning(`Expected ${filePath} (after preparing for import ${forImport}) to assign a function to module.exports, got ${typeof script}`)
|
|
348
352
|
}
|
|
353
|
+
return result
|
|
349
354
|
}
|
|
350
355
|
|
|
351
356
|
// Public: Loads a file in path.
|
|
@@ -361,16 +366,17 @@ class Robot {
|
|
|
361
366
|
// see https://github.com/hubotio/hubot/issues/1355
|
|
362
367
|
if (['js', 'mjs'].indexOf(ext) === -1) {
|
|
363
368
|
this.logger.debug(`Skipping unsupported file type ${full}`)
|
|
364
|
-
return
|
|
369
|
+
return null
|
|
365
370
|
}
|
|
366
|
-
|
|
371
|
+
let result = null
|
|
367
372
|
try {
|
|
368
|
-
await this[`load${ext}`](full)
|
|
373
|
+
result = await this[`load${ext}`](full)
|
|
369
374
|
this.parseHelp(full)
|
|
370
375
|
} catch (error) {
|
|
371
376
|
this.logger.error(`Unable to load ${full}: ${error.stack}`)
|
|
372
377
|
throw error
|
|
373
378
|
}
|
|
379
|
+
return result
|
|
374
380
|
}
|
|
375
381
|
|
|
376
382
|
// Public: Loads every script in the given path.
|
|
@@ -380,11 +386,22 @@ class Robot {
|
|
|
380
386
|
// Returns nothing.
|
|
381
387
|
async load (path) {
|
|
382
388
|
this.logger.debug(`Loading scripts from ${path}`)
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const
|
|
386
|
-
await
|
|
389
|
+
const results = []
|
|
390
|
+
try {
|
|
391
|
+
const folder = await File.readdir(path, { withFileTypes: true })
|
|
392
|
+
for await (const file of folder) {
|
|
393
|
+
if (file.isDirectory()) continue
|
|
394
|
+
try {
|
|
395
|
+
const result = await this.loadFile(path, file.name)
|
|
396
|
+
results.push(result)
|
|
397
|
+
} catch (e) {
|
|
398
|
+
this.logger.error(`Error loading file ${file.name} - ${e.stack}`)
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
} catch (e) {
|
|
402
|
+
this.logger.error(`Path ${path} does not exist`)
|
|
387
403
|
}
|
|
404
|
+
return results
|
|
388
405
|
}
|
|
389
406
|
|
|
390
407
|
// Public: Load scripts from packages specified in the
|
|
@@ -451,7 +468,7 @@ class Robot {
|
|
|
451
468
|
if (stat) {
|
|
452
469
|
app.use(express.static(stat))
|
|
453
470
|
}
|
|
454
|
-
|
|
471
|
+
return new Promise((resolve, reject) => {
|
|
455
472
|
try {
|
|
456
473
|
this.server = app.listen(port, address, () => {
|
|
457
474
|
this.router = app
|
|
@@ -462,7 +479,6 @@ class Robot {
|
|
|
462
479
|
reject(err)
|
|
463
480
|
}
|
|
464
481
|
})
|
|
465
|
-
return p
|
|
466
482
|
}
|
|
467
483
|
|
|
468
484
|
// Setup an empty router object
|