Skip to content

Commit

Permalink
docs: Sam-I-Am correction
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyguerra committed Apr 17, 2023
2 parents 1749af8 + bfcf710 commit ed011a4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 41 deletions.
32 changes: 0 additions & 32 deletions ROADMAP.md

This file was deleted.

10 changes: 5 additions & 5 deletions docs/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,23 @@ Messages can be sent to a specified room or user using the messageRoom function.
module.exports = (robot) => {
robot.hear(/green eggs/i, (response) => {
const room = 'mytestroom'
robot.messageRoom(room, 'I do not like green eggs and ham. I do not like them sam-I-am.')
robot.messageRoom(room, 'I do not like green eggs and ham. I do not like them Sam-I-Am.')
}
}
```
User name can be explicitely specified if desired ( for a cc to an admin/manager), or using the response object a private message can be sent to the original sender.
```javascript
robot.respond(/I don't like Sam-I-am/i, (response) => {
robot.respond(/I don't like sam-i-am/i, (response) => {
const room = 'joemanager'
robot.messageRoom(room, 'Someone does not like Dr. Seus')
response.reply('That Sam-I-am\nThat Sam-I-am\nI do not like\nthat Sam-I-am')
response.reply('That Sam-I-Am\nThat Sam-I-Am\nI do not like\nthat Sam-I-Am')
}

robot.hear(/Sam-I-am/i, (response) => {
robot.hear(/Sam-I-Am/i, (response) => {
const room = response.envelope.user.name
robot.messageRoom(room, 'That Sam-I-am\nThat Sam-I-am\nI do not like\nthat Sam-I-am')
robot.messageRoom(room, 'That Sam-I-Am\nThat Sam-I-Am\nI do not like\nthat Sam-I-Am')
}
```
Expand Down
34 changes: 32 additions & 2 deletions src/httpclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/*
April 15, 2023
Reasoning:
ScopedHttpClient is no longer maintained.
Decision:
Implement a phased approach to deprecate `robot.http` all together in favor of `fetch`.
1. Convert ScopedHttpClient to Javascript and include the module in this repo
2. Add a deprecation warning to `robot.http`
3. Remove `robot.http` in a future release
*/
const path = require('path')
const http = require('http')
const https = require('https')
Expand Down Expand Up @@ -240,7 +252,26 @@ class ScopedClient {
const ty = typeof arguments[i]
if (ty === 'string') {
const parsedUrl = new URL(arguments[i])
extend(options, parsedUrl)
const query = {}
parsedUrl.searchParams.forEach((v, k) => {
query[k] = v
})

extend(options, {
href: parsedUrl.href,
origin: parsedUrl.origin,
protocol: parsedUrl.protocol,
username: parsedUrl.username,
password: parsedUrl.password,
host: parsedUrl.host,
hostname: parsedUrl.hostname,
port: parsedUrl.port,
pathname: parsedUrl.pathname,
search: parsedUrl.search,
searchParams: parsedUrl.searchParams,
query,
hash: parsedUrl.hash
})
delete options.url
delete options.href
delete options.search
Expand All @@ -249,7 +280,6 @@ class ScopedClient {
}
i += 1
}

if (!options.headers) { options.headers = {} }
if (options.encoding == null) { options.encoding = 'utf-8' }
return options
Expand Down
2 changes: 1 addition & 1 deletion src/robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class Robot {
const full = path.join(filepath, path.basename(filename, ext))

// see https://github.com/hubotio/hubot/issues/1355
if (['.js', '.mjs'].indexOf(ext) == -1) { // eslint-disable-line
if (['.js', '.mjs', '.coffee'].indexOf(ext) == -1) { // eslint-disable-line
return
}

Expand Down
1 change: 1 addition & 0 deletions test/middleware_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ describe('Middleware', function () {
warnOnUnregistered: false
})
mockery.registerMock('hubot-mock-adapter', require('./fixtures/mock-adapter'))
process.env.EXPRESS_PORT = 0
this.robot = new Robot(null, 'mock-adapter', true, 'TestHubot')
this.robot.run

Expand Down
11 changes: 10 additions & 1 deletion test/robot_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ describe('Robot', function () {
warnOnUnregistered: false
})
mockery.registerMock('hubot-mock-adapter', require('./fixtures/mock-adapter'))
process.env.EXPRESS_PORT = 0
this.robot = new Robot(null, 'mock-adapter', true, 'TestHubot')
this.robot.alias = 'Hubot'
this.robot.run()

// Re-throw AssertionErrors for clearer test failures
this.robot.on('error', function (name, err, response) {
if (err.constructor.name === 'AssertionError') {
if (err?.constructor.name === 'AssertionError' || name instanceof chai.AssertionError) {
process.nextTick(function () {
throw err
})
Expand Down Expand Up @@ -91,6 +92,14 @@ describe('Robot', function () {
const httpClient = this.robot.http('http://localhost', { agent: agentB })
expect(httpClient.options.agent).to.equal(agentB)
})

it('builds the url correctly from a string', function () {
const options = this.httpClient.buildOptions('http://localhost:3001')
expect(options.host).to.equal('localhost:3001')
expect(options.pathname).to.equal('/')
expect(options.protocol).to.equal('http:')
expect(options.port).to.equal('3001')
})
})

describe('#respondPattern', function () {
Expand Down

0 comments on commit ed011a4

Please sign in to comment.