Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #453 from atomist/empty
Browse files Browse the repository at this point in the history
Allow construction of Message without a body
  • Loading branch information
johnsonr authored Mar 20, 2017
2 parents 4a14393 + 06ecb67 commit 4c51f4e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

[Unreleased]: https://github.com/atomist/rug/compare/0.17.1...HEAD

### Changed

- Allow construction of Message without body

## [0.17.1] - 2017-03-20

[0.17.1]: https://github.com/atomist/rug/compare/0.17.0...0.17.1
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/com/atomist/rug/runtime/js/PlanBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.atomist.rug.spi.Handlers._
import com.atomist.tree.TreeNode
import com.atomist.util.JsonUtils
import jdk.nashorn.api.scripting.ScriptObjectMirror
import jdk.nashorn.internal.runtime.Undefined
import jdk.nashorn.internal.runtime.{ScriptRuntime, Undefined}

/**
* Constructs plans from Nashorn response to a Handler/handle operation
Expand Down Expand Up @@ -60,6 +60,7 @@ class PlanBuilder {
JsonBody(json.entrySet().toString)
case text: String =>
MessageText(text)
case ScriptRuntime.UNDEFINED => MessageText(null)
case _ =>
throw new InvalidHandlerResultException(s"Cannot determine message content from body: ${jsMessage.getMember("body")}")
}
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {HandleCommand, Instruction, Response, HandlerContext, Plan, Message} from '@atomist/rug/operations/Handlers'
import {CommandHandler, Parameter, Tags, Intent} from '@atomist/rug/operations/Decorators'

@CommandHandler("ShowMeTheKitties","Search Youtube for kitty videos and post results to slack")
class KittieFetcher implements HandleCommand{

handle(ctx: HandlerContext) : Message {
return new Message();
}
}

export let command = new KittieFetcher();
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.atomist.rug.spi.Handlers._
import com.atomist.rug.spi.Secret
import com.atomist.rug.ts.TypeScriptBuilder
import com.atomist.source.{SimpleFileBasedArtifactSource, StringFileArtifact}
import com.atomist.util.JsonUtils
import org.scalatest.{FlatSpec, Matchers}

import scala.concurrent.Await
Expand Down Expand Up @@ -41,6 +42,18 @@ class JavaScriptCommandHandlerTest extends FlatSpec with Matchers {
val simpleCommandHandlerReturningMessage = StringFileArtifact(atomistConfig.handlersRoot + "/Handler.ts",
contentOf(this, "SimpleCommandHandlerReturningMessage.ts"))

val simpleCommandHandlerReturningEmptyMessage = StringFileArtifact(atomistConfig.handlersRoot + "/Handler.ts",
contentOf(this, "SimpleCommandHandlerReturningEmptyMessage.ts"))

it should "allow us to return an empty message" in {
val rugArchive = TypeScriptBuilder.compileWithModel(SimpleFileBasedArtifactSource(simpleCommandHandlerReturningEmptyMessage))
val rugs = RugArchiveReader.find(rugArchive, Nil)
val com = rugs.commandHandlers.head
val plan = com.handle(null,SimpleParameterValues.Empty).get
assert(plan.messages.size === 1)
assert(plan.messages.head.body.value == null)
assert(JsonUtils.toJson(plan.messages.head) == """{"body":{},"instructions":[]}""")
}
it should "allow us to return a message directly from a handler" in {
val rugArchive = TypeScriptBuilder.compileWithModel(SimpleFileBasedArtifactSource(simpleCommandHandlerReturningMessage))
val rugs = RugArchiveReader.find(rugArchive, Nil)
Expand Down

0 comments on commit 4c51f4e

Please sign in to comment.