Skip to content

Commit

Permalink
Merge branch 'master' of github.com:KeesCBakker/hubot-command-mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
KeesCBakker committed Sep 5, 2023
2 parents 59aa643 + f4a1ece commit eb614f2
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 77 deletions.
122 changes: 60 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
"remove-markdown": "^0.5.0"
},
"devDependencies": {
"@types/chai": "^4.3.5",
"@types/hubot": "^3.3.2",
"@types/chai": "^4.3.6",
"@types/hubot": "^3.3.3",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.6",
"chai": "^4.3.7",
"del-cli": "^5.0.0",
"@types/node": "^20.5.9",
"chai": "^4.3.8",
"del-cli": "^5.1.0",
"hubot": "^7.0.0",
"hubot-mock-adapter": "^1.1.1",
"hubot-mock-adapter": "^2.0.0",
"mocha": "^10.2.0",
"prettier": "^3.0.1",
"prettier": "^3.0.3",
"ts-node": "^10.9.1"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/entities/parameters/ValueExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getValues(

if (command.parameters) {
let r = convertCommandIntoRegexString(robotName, robotAlias, tool, command, true)
let nr = new NamedRegExp(r, "i")
let nr = new NamedRegExp(r, "si")

let answer = nr.exec(message).groups

Expand Down
2 changes: 1 addition & 1 deletion src/mappers/map_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function map_tool(robot: Hubot.Robot, tool: InternalTool, options: IOptio
//match edge cases in which certain phrases end with a command name
const strValidationRegex = convertCommandIntoRegexString(robot.name, robot.alias, tool, cmd)

cmd.validationRegex = new RegExp(strValidationRegex, "i")
cmd.validationRegex = new RegExp(strValidationRegex, "si")

if (robot.logger) {
robot.logger.info(`Mapping '${tool.name}.${cmd.name}' as '${strValidationRegex}'.`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function removeTrailingBotWhitespaceCharactersFromIncomingMessages(robot:
robot.receiveMiddleware((context, next, done) => {
const text = context.response.message.text
if (text) {
const newText = text.replace(new RegExp(`(${robotNameRegexString})\\s+`, "i"), "$1 ")
const newText = text.replace(new RegExp(`(${robotNameRegexString})\\s+`, "si"), "$1 ")
if (text != newText) {
context.response.message.text = newText
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ export function convertCommandIntoRegexString(
regexString += ")"

if (cmd.capture) {
//command / tool sperator!
//command / tool separator!
if (extraSpace) {
regexString += " "
}

//capture the capture in a group so it will
//be accessable through the matches
//be accessible through the matches
regexString += "("
regexString += cmd.capture
regexString += ")"
Expand Down
4 changes: 2 additions & 2 deletions test/_parameter-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { IParameter, ITool } from "../src"
import { convertCommandIntoRegexString } from "../src/utils/regex"

export function test(regex: string, dataToTest: string) {
var r = new RegExp(regex, "i")
var r = new RegExp(regex, "si")
return r.test(dataToTest)
}

export function exec(regex: string, dataToTest: string) {
var r = new RegExp(regex, "i")
var r = new RegExp(regex, "si")
return r.exec(dataToTest)
}

Expand Down
3 changes: 2 additions & 1 deletion test/common/test-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class TestBotContext {

shutdown(): void {
this.robot.shutdown()
delete process.env.HUBOT_LOG_LEVEL
}
}

Expand All @@ -56,7 +57,7 @@ export type TestBotSettings = {
}

export async function createTestBot(settings: TestBotSettings | null = null): Promise<TestBotContext> {
process.env["HUBOT_LOG_LEVEL"] = settings?.logLevel || "error"
process.env.HUBOT_LOG_LEVEL = settings?.logLevel || "silent"

return new Promise<TestBotContext>(async done => {
// create new robot, without http, using the mock adapter
Expand Down
6 changes: 6 additions & 0 deletions test/parameters/StringParameters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ describe("StringParameters.spec.ts", () => {
var r = createRegex([p])
expect(test(r, "hubot test cmd Capture all")).to.eq(true)
})

it("Multi line parameter", () => {
var p = new RestParameter("a")
var r = createRegex([p])
expect(test(r, "hubot test cmd Capture all\nnew lines\n")).to.eq(true)
})
})

describe("StringParameter", () => {
Expand Down
32 changes: 32 additions & 0 deletions test/scenarios/multiline.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createTestBot, TestBotContext } from "../common/test-bot"
import { expect } from "chai"
import { map_command, RestParameter } from "../../src"

describe("multiline.spec.ts > todo example", () => {
let context: TestBotContext

beforeEach(async () => {
context = await createTestBot()
map_command(context.robot, "act", new RestParameter("value"), context => context.res.reply(context.values.value))
})

afterEach(() => context.shutdown())

it("one line", async () => {
let line = "And now the end is here"
let result = await context.sendAndWaitForResponse("hubot act " + line)
expect(result).to.eql(line)
})

it("two lines", async () => {
let line = "And now the end is here\nAnd so I face that final curtain"
let result = await context.sendAndWaitForResponse("hubot act " + line)
expect(result).to.eql(line)
})

it("three lines", async () => {
let line = "And now the end is here\nAnd so I face that final curtain\nMy friend I'll make it clear"
let result = await context.sendAndWaitForResponse("hubot act " + line)
expect(result).to.eql(line)
})
})

0 comments on commit eb614f2

Please sign in to comment.