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

Require parameters by default in TS #306

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Added `ScalaFileType` backed by ScalaMeta


### Fixed

- Fix: Elm parser failed on files with two multiline comments
Expand All @@ -29,6 +28,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
editors declare the same parameter. The first one is chosen.
https://github.com/atomist/rug/issues/258

- Ensure TS parameters are required by default, and ensure defaults are applied
before validation: https://github.com/atomist/rug/issues/224

### Changed

- Upgrade TS compiler to 2.1.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ trait ProjectEditorSupport
*/
def failOnNoModification: Boolean = false

override def modify(as: ArtifactSource, poa: ProjectOperationArguments): ModificationAttempt = {
override def modify(as: ArtifactSource, args: ProjectOperationArguments): ModificationAttempt = {
val poa = addDefaultParameterValues(args)
validateParameters(poa)

val r =
Expand All @@ -36,7 +37,7 @@ trait ProjectEditorSupport
} else if (meetsPostcondition(as)) {
NoModificationNeeded(s"Artifact source meets postcondition already")
} else {
modifyInternal(as, addDefaultParameterValues(poa))
modifyInternal(as, poa)
}

// We may need to make it fail-fast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ abstract class JavaScriptInvokingProjectOperation(
parameter.setDefaultRef(details.get("defaultRef").asInstanceOf[String])
val disp = details.get("displayable")
parameter.setDisplayable(if(disp != null) disp.asInstanceOf[Boolean] else true)
parameter.setRequired(details.get("required").asInstanceOf[Boolean])

if(details.hasMember("required")){
parameter.setRequired(details.get("required").asInstanceOf[Boolean])
}else{
parameter.setRequired(true)
}


parameter.addTags(readTagsFromMetadata(details))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.atomist.rug.runtime.js

import com.atomist.project.SimpleProjectOperationArguments
import com.atomist.project.common.MissingParametersException
import com.atomist.rug.ts.TypeScriptBuilder
import com.atomist.rug.{InvalidRugParameterDefaultValue, InvalidRugParameterPatternException, TestUtils}
import com.atomist.rug.{InvalidRugParameterDefaultValue, InvalidRugParameterPatternException}
import com.atomist.source.{FileArtifact, SimpleFileBasedArtifactSource, StringFileArtifact}
import org.scalatest.{FlatSpec, Matchers}

Expand Down Expand Up @@ -45,6 +46,26 @@ object JavaScriptInvokingProjectOperationTest {
|export let editor = new SimpleEditor()
""".stripMargin

val SimpleEditorWithRequiredParameterButNoDefault: String =
s"""
|import {Project} from '@atomist/rug/model/Core'
|import {ProjectEditor} from '@atomist/rug/operations/ProjectEditor'
|import {File} from '@atomist/rug/model/Core'
|import {Parameter} from '@atomist/rug/operations/RugOperation'
|
|class SimpleEditor implements ProjectEditor {
| name: string = "Simple"
| description: string = "A nice little editor"
| parameters: Parameter[] = [{name: "content", description: "Content", pattern: "@url", maxLength: 100}]
| edit(project: Project, {content} : {content: string}) {
| if(content != "http://t.co"){
| throw new Error("Content was not as expected");
| }
| }
| }
|export let editor = new SimpleEditor()
""".stripMargin

val SimpleReviewerInvokingOtherEditorAndAddingToOurOwnParameters: String =
s"""
|import {Project} from '@atomist/rug/model/Core'
Expand Down Expand Up @@ -245,7 +266,19 @@ class JavaScriptInvokingProjectOperationTest extends FlatSpec with Matchers {
jsed.jsVar.get("name") should be ("Simple")
}

private def invokeAndVerifySimpleEditor(tsf: FileArtifact): JavaScriptInvokingProjectEditor = {
it should "Should throw an exception if required parameters are not set" in {
val tsf = StringFileArtifact(s".atomist/editors/SimpleEditor.ts", SimpleEditorWithRequiredParameterButNoDefault)
val as = TypeScriptBuilder.compileWithModel(SimpleFileBasedArtifactSource(tsf))
val jsed = JavaScriptOperationFinder.fromJavaScriptArchive(as).head.asInstanceOf[JavaScriptInvokingProjectEditor]
assert(jsed.name == "Simple")
val target = SimpleFileBasedArtifactSource(StringFileArtifact("pom.xml", "nasty stuff"))

assertThrows[MissingParametersException]{
jsed.modify(target, SimpleProjectOperationArguments.Empty)
}
}

private def invokeAndVerifySimpleEditor(tsf: FileArtifact): JavaScriptInvokingProjectEditor = {
val as = TypeScriptBuilder.compileWithModel(SimpleFileBasedArtifactSource(tsf))
val jsed = JavaScriptOperationFinder.fromJavaScriptArchive(as).head.asInstanceOf[JavaScriptInvokingProjectEditor]
assert(jsed.name === "Simple")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class JavaScriptOperationFinderTest extends FlatSpec with Matchers {
| @Parameter({pattern: "^.*$$", description: "foo bar"})
| content: string = "Test String";
|
| @Parameter({pattern: "^\\d+$$", description: "A nice round number"})
| @Parameter({pattern: "^[0-9]+$$", description: "A nice round number"})
| amount: number = 10;
|
| @Parameter({pattern: "^\\d+$$", description: "A nice round number"})
| nope: boolean;
| @Parameter({pattern: "^.*$$", description: "A nice round number", required: false})
| nope: boolean
|
| edit(project: Project) {
| if(this.amount != 10) {
Expand Down