hubot 9.0.2 → 9.1.1

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/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2017 GitHub Inc.
1
+ Copyright (c) 2011-2023 GitHub Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ![Pipeline Status](https://github.com/hubotio/hubot/actions/workflows/pipeline.yml/badge.svg)
2
+
1
3
  ![Build Status: MacOS](https://github.com/hubotio/hubot/actions/workflows/nodejs-macos.yml/badge.svg)
2
4
  ![Build Status: Ubuntu](https://github.com/hubotio/hubot/actions/workflows/nodejs-ubuntu.yml/badge.svg)
3
5
  ![Build Status: Window](https://github.com/hubotio/hubot/actions/workflows/nodejs-windows.yml/badge.svg)
@@ -5,16 +7,26 @@
5
7
  # Hubot
6
8
 
7
9
  Hubot is a framework to build chat bots, modeled after GitHub's Campfire bot of the same name, hubot.
8
- He's pretty cool. He's [extendable with scripts](http://hubot.github.com/docs/#scripts) and can work
9
- on [many different chat services](https://hubot.github.com/docs/adapters/).
10
+ He's pretty cool. He's [extendable with scripts](https://hubotio.github.io/hubot/docs#scripts) and can work
11
+ on [many different chat services](https://hubotio.github.io/hubot/adapters.html).
10
12
 
11
13
  This repository provides a library that's distributed by `npm` that you
12
- use for building your own bots. See the [documentation](http://hubot.github.com/docs)
14
+ use for building your own bots. See the [documentation](https://hubotio.github.io/hubot/docs.html)
13
15
  for details on getting up and running with your very own robot friend.
14
16
 
15
17
  In most cases, you'll probably never have to hack on this repo directly if you
16
18
  are building your own bot. But if you do, check out [CONTRIBUTING.md](CONTRIBUTING.md)
17
19
 
20
+ # Create your own Hubot instance
21
+
22
+ This will create a directory called `myhubot` in the current working directory.
23
+
24
+ ```sh
25
+ npx hubot --create myhubot --adapter @hubot-friends/hubot-slack
26
+ ```
27
+
28
+ Review `scripts/example.mjs`. Create more scripts in the `scripts` folder.
29
+
18
30
  ## License
19
31
 
20
32
  See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT).
package/bin/hubot.js CHANGED
@@ -6,6 +6,7 @@ const pathResolve = require('path').resolve
6
6
  const OptParse = require('optparse')
7
7
 
8
8
  const Hubot = require('..')
9
+ const create = require('../src/GenHubot.js')
9
10
 
10
11
  const switches = [
11
12
  ['-a', '--adapter HUBOT_ADAPTER', 'The Adapter to use, e.g. "shell" (to load the default hubot shell adapter)'],
@@ -86,14 +87,11 @@ Parser.on((opt, value) => {
86
87
  Parser.parse(process.argv)
87
88
 
88
89
  if (options.create) {
89
- console.error("'hubot --create' is deprecated. Use the yeoman generator instead:")
90
- console.error(' npm install -g yo generator-hubot')
91
- console.error(` mkdir -p ${options.path}`)
92
- console.error(` cd ${options.path}`)
93
- console.error(' yo hubot')
94
- console.error('See https://github.com/github/hubot/blob/main/docs/index.md for more details on getting started.')
95
- process.exit(1)
90
+ options.hubotInstallationPath = process.env.HUBOT_INSTALLATION_PATH ?? 'hubot'
91
+ create(options.path, options)
92
+ process.exit(0)
96
93
  }
94
+
97
95
  if (options.file) {
98
96
  options.adapter = options.file.split('/').pop().split('.')[0]
99
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hubot",
3
- "version": "9.0.2",
3
+ "version": "9.1.1",
4
4
  "author": "hubot",
5
5
  "keywords": [
6
6
  "github",
@@ -24,7 +24,6 @@
24
24
  "pino": "^8.11.0"
25
25
  },
26
26
  "devDependencies": {
27
- "semantic-release": "^21.0.1",
28
27
  "standard": "^17.1.0"
29
28
  },
30
29
  "engines": {
@@ -37,10 +36,13 @@
37
36
  },
38
37
  "scripts": {
39
38
  "start": "bin/hubot",
39
+ "gen": "bin/hubot --create myhubot",
40
40
  "pretest": "standard",
41
41
  "test": "node --test",
42
42
  "test:smoke": "node src/**/*.js",
43
- "test:e2e": "bin/e2e-test.sh"
43
+ "test:e2e": "bin/e2e-test.sh",
44
+ "build:local": "npx @hubot-friends/sfab --folder ./docs --destination ./_site --verbose --serve /hubot/ --watch-path ./docs --scripts ./sfab-hooks",
45
+ "build": "npx @hubot-friends/sfab --folder ./docs --destination ./_site --verbose --scripts ./sfab-hooks"
44
46
  },
45
47
  "release": {
46
48
  "branches": [
@@ -0,0 +1,11 @@
1
+ export default () => {
2
+ return {
3
+ model (file, model) {
4
+ return {
5
+ base: {
6
+ href: '/hubot/'
7
+ }
8
+ }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,88 @@
1
+ const { spawnSync } = require('child_process')
2
+ const File = require('fs')
3
+ const path = require('path')
4
+
5
+ function runCommands (hubotDirectory, options) {
6
+ options.hubotInstallationPath = options?.hubotInstallationPath ?? 'hubot'
7
+ console.log('creating hubot directory', hubotDirectory)
8
+ try {
9
+ spawnSync('mkdir', [hubotDirectory])
10
+ } catch (error) {
11
+ console.log(`${hubotDirectory} exists, continuing to the next operation.`)
12
+ }
13
+ const envFilePath = path.resolve(process.cwd(), '.env')
14
+ process.chdir(hubotDirectory)
15
+
16
+ spawnSync('npm', ['init', '-y'])
17
+ spawnSync('npm', ['i', options.hubotInstallationPath].concat(options.adapter, 'hubot-help', 'hubot-rules', 'hubot-diagnostics'))
18
+ spawnSync('mkdir', ['scripts'])
19
+ spawnSync('touch', ['external-scripts.json'])
20
+
21
+ const externalScriptsPath = path.resolve('./', 'external-scripts.json')
22
+ let escripts = File.readFileSync(externalScriptsPath, 'utf8')
23
+ if (escripts.length === 0) escripts = '[]'
24
+ const externalScripts = JSON.parse(escripts)
25
+ externalScripts.push('hubot-help')
26
+ externalScripts.push('hubot-rules')
27
+ externalScripts.push('hubot-diagnostics')
28
+
29
+ File.writeFileSync(externalScriptsPath, JSON.stringify(externalScripts, null, 2))
30
+
31
+ File.writeFileSync('./scripts/example.mjs', `// Description:
32
+ // Test script
33
+ //
34
+ // Commands:
35
+ // hubot helo - Responds with Hello World!.
36
+ //
37
+ // Notes:
38
+ // This is a test script.
39
+ //
40
+
41
+ export default (robot) => {
42
+ robot.respond(/helo/, async res => {
43
+ await res.send('Hello World!')
44
+ })
45
+ }`)
46
+
47
+ const packageJsonPath = path.resolve(process.cwd(), 'package.json')
48
+ const packageJson = JSON.parse(File.readFileSync(packageJsonPath, 'utf8'))
49
+
50
+ packageJson.scripts = {
51
+ start: 'hubot'
52
+ }
53
+ if (options.adapter) {
54
+ packageJson.scripts.start += ` --adapter ${options.adapter}`
55
+ }
56
+
57
+ File.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
58
+ console.log('package.json updated successfully.')
59
+ const hubotEnvFilePath = path.resolve('.env')
60
+
61
+ try {
62
+ File.accessSync(envFilePath)
63
+ File.copyFileSync(envFilePath, hubotEnvFilePath)
64
+ console.log('.env file copied successfully.')
65
+
66
+ const envContent = File.readFileSync(hubotEnvFilePath, 'utf8')
67
+ const envLines = envContent.split('\n')
68
+
69
+ for (const line of envLines) {
70
+ const trimmedLine = line.trim()
71
+
72
+ if (trimmedLine && !trimmedLine.startsWith('#')) {
73
+ const [key, ...values] = trimmedLine.split('=')
74
+ const value = values.join('=')
75
+ process.env[key] = value
76
+ }
77
+ }
78
+ } catch (error) {
79
+ console.log('.env file not found, continuing to the next operation.')
80
+ }
81
+ }
82
+ module.exports = (hubotDirectory, options) => {
83
+ try {
84
+ runCommands(hubotDirectory, options)
85
+ } catch (error) {
86
+ console.error('An error occurred:', error)
87
+ }
88
+ }
package/src/robot.js CHANGED
@@ -37,6 +37,7 @@ class Robot {
37
37
  this.brain = new Brain(this)
38
38
  this.alias = alias
39
39
  this.adapter = null
40
+ this.shouldEnableHttpd = httpd ?? true
40
41
  this.datastore = null
41
42
  this.Response = Response
42
43
  this.commands = []
@@ -55,18 +56,13 @@ class Robot {
55
56
  this.globalHttpOptions = {}
56
57
 
57
58
  this.parseVersion()
58
- if (httpd) {
59
- this.setupExpress()
60
- } else {
61
- this.setupNullRouter()
62
- }
63
-
64
59
  this.adapterName = adapter ?? 'shell'
65
60
  this.errorHandlers = []
66
61
 
67
62
  this.on('error', (err, res) => {
68
63
  return this.invokeErrorHandlers(err, res)
69
64
  })
65
+ this.on('listening', this.herokuKeepalive.bind(this))
70
66
  }
71
67
 
72
68
  // Public: Adds a custom Listener with the provided matcher, options, and
@@ -407,8 +403,8 @@ class Robot {
407
403
 
408
404
  // Setup the Express server's defaults.
409
405
  //
410
- // Returns nothing.
411
- setupExpress () {
406
+ // Returns Server.
407
+ async setupExpress () {
412
408
  const user = process.env.EXPRESS_USER
413
409
  const pass = process.env.EXPRESS_PASSWORD
414
410
  const stat = process.env.EXPRESS_STATIC
@@ -444,27 +440,18 @@ class Robot {
444
440
  if (stat) {
445
441
  app.use(express.static(stat))
446
442
  }
447
-
448
- try {
449
- this.server = app.listen(port, address)
450
- this.router = app
451
- } catch (error) {
452
- this.logger.error(`Error trying to start HTTP server: ${error}\n${error.stack}`)
453
- throw error
454
- }
455
-
456
- let herokuUrl = process.env.HEROKU_URL
457
-
458
- if (herokuUrl) {
459
- if (!/\/$/.test(herokuUrl)) {
460
- herokuUrl += '/'
461
- }
462
- this.pingIntervalId = setInterval(() => {
463
- HttpClient.create(`${herokuUrl}hubot/ping`).post()((_err, res, body) => {
464
- this.logger.info('keep alive ping!')
443
+ const p = new Promise((resolve, reject) => {
444
+ try {
445
+ this.server = app.listen(port, address, () => {
446
+ this.router = app
447
+ this.emit('listening', this.server)
448
+ resolve(this.server)
465
449
  })
466
- }, 5 * 60 * 1000)
467
- }
450
+ } catch (err) {
451
+ reject(err)
452
+ }
453
+ })
454
+ return p
468
455
  }
469
456
 
470
457
  // Setup an empty router object
@@ -645,6 +632,11 @@ class Robot {
645
632
  //
646
633
  // Returns whatever the adapter returns.
647
634
  async run () {
635
+ if (this.shouldEnableHttpd) {
636
+ await this.setupExpress()
637
+ } else {
638
+ this.setupNullRouter()
639
+ }
648
640
  this.emit('running')
649
641
 
650
642
  return await this.adapter.run()
@@ -712,6 +704,20 @@ class Robot {
712
704
 
713
705
  return HttpClient.create(url, httpOptions).header('User-Agent', `Hubot/${this.version}`)
714
706
  }
707
+
708
+ herokuKeepalive (server) {
709
+ let herokuUrl = process.env.HEROKU_URL
710
+ if (herokuUrl) {
711
+ if (!/\/$/.test(herokuUrl)) {
712
+ herokuUrl += '/'
713
+ }
714
+ this.pingIntervalId = setInterval(() => {
715
+ HttpClient.create(`${herokuUrl}hubot/ping`).post()((_err, res, body) => {
716
+ this.logger.info('keep alive ping!')
717
+ })
718
+ }, 5 * 60 * 1000)
719
+ }
720
+ }
715
721
  }
716
722
 
717
723
  module.exports = Robot