Skip to content

Commit

Permalink
feat: Use organization scoped adapters like @hubot-friends/hubot-slack (
Browse files Browse the repository at this point in the history
#1655)

BREAKING CHANGE: This change now requires you to include hubot- when specifying hubot adapters.
  • Loading branch information
joeyguerra committed Jul 29, 2023
1 parent 5f21da9 commit ac5dcd2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,16 @@ class Robot {
} else if (['.mjs'].includes(ext)) {
this.adapter = await this.importAdapterFrom(pathToFileURL(path.resolve(adapterPath)).href)
} else {
this.adapter = this.requireAdapterFrom(`hubot-${this.adapterName}`)
const adapterPathInCurrentWorkingDirectory = this.adapterName
try {
this.adapter = this.requireAdapterFrom(adapterPathInCurrentWorkingDirectory)
} catch (err) {
if (err.name === 'SyntaxError' && err.message.includes('Cannot use import statement outside a module')) {
this.adapter = await this.importAdapterFrom(adapterPathInCurrentWorkingDirectory)
} else {
throw err
}
}
}
} catch (err) {
this.logger.error(`Cannot load adapter ${adapterPath ?? '[no path set]'} ${this.adapterName} - ${err}`)
Expand Down
2 changes: 1 addition & 1 deletion test/es2015_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('hubot/es2015', function () {
mockery.registerMock('hubot-mock-adapter', require('./fixtures/mock-adapter.js'))

class MyRobot extends Robot {}
const robot = new MyRobot('mock-adapter', false, 'TestHubot')
const robot = new MyRobot('hubot-mock-adapter', false, 'TestHubot')
await robot.loadAdapter()
expect(robot).to.be.an.instanceof(Robot)
expect(robot.name).to.equal('TestHubot')
Expand Down
2 changes: 1 addition & 1 deletion test/middleware_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ describe('Middleware', function () {
})
mockery.registerMock('hubot-mock-adapter', require('./fixtures/mock-adapter.js'))
process.env.EXPRESS_PORT = 0
this.robot = new Robot('mock-adapter', true, 'TestHubot')
this.robot = new Robot('hubot-mock-adapter', true, 'TestHubot')
await this.robot.loadAdapter()
this.robot.run

Expand Down
2 changes: 1 addition & 1 deletion test/robot_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Robot', function () {
})
mockery.registerMock('hubot-mock-adapter', require('./fixtures/mock-adapter.js'))
process.env.EXPRESS_PORT = 0
this.robot = new Robot('mock-adapter', true, 'TestHubot')
this.robot = new Robot('hubot-mock-adapter', true, 'TestHubot')
this.robot.alias = 'Hubot'
await this.robot.loadAdapter()
this.robot.run()
Expand Down

0 comments on commit ac5dcd2

Please sign in to comment.