Skip to content

Commit 838e41a

Browse files
committed
test GH output printer
1 parent df4ad50 commit 838e41a

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

.github/workflows/ci.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ jobs:
2222
java-version: '11'
2323

2424
- name: Build and Release
25-
run: ./gradlew clean check
25+
run: ./gradlew clean check shadowJar
26+
27+
- name: Test validate
28+
continue-on-error: true
29+
run: ./rmf-gen.sh validate -f GITHUB ./api-spec/api.raml
2630
test_node:
2731
name: Build npm package
2832

tools/cli-application/src/main/kotlin/io/vrap/rmf/codegen/cli/DiffSubcommand.kt

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class DiffSubcommand : Callable<Int> {
8383
OutputFormat.PHP_MARKDOWN -> PHPMarkdownFormatPrinter()
8484
OutputFormat.TS_MARKDOWN -> TSMarkdownFormatPrinter()
8585
OutputFormat.DOTNET_MARKDOWN -> DotNetMarkdownFormatPrinter()
86+
OutputFormat.GITHUB -> CliFormatPrinter()
8687
OutputFormat.JSON -> JsonFormatPrinter()
8788
}
8889
}

tools/cli-application/src/main/kotlin/io/vrap/rmf/codegen/cli/Utils.kt

+3-7
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ enum class OutputFormat {
2828
PHP_MARKDOWN,
2929
TS_MARKDOWN,
3030
DOTNET_MARKDOWN,
31-
JSON;
31+
JSON,
32+
GITHUB;
3233

3334
companion object {
34-
const val VALID_VALUES = "CLI, JSON, MARKDOWN"
35+
const val VALID_VALUES = "CLI, JSON, MARKDOWN, GITHUB"
3536
}
3637
}
3738

@@ -183,8 +184,3 @@ object InternalLogger {
183184
}
184185
}
185186
}
186-
187-
188-
189-
190-

tools/cli-application/src/main/kotlin/io/vrap/rmf/codegen/cli/ValidateSubcommand.kt

+21-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import io.vrap.rmf.raml.model.RamlDiagnostic
1616
import io.vrap.rmf.raml.model.RamlModelBuilder
1717
import io.vrap.rmf.raml.model.RamlModelResult
1818
import io.vrap.rmf.raml.model.modules.Api
19-
import io.vrap.rmf.raml.validation.Source
2019
import io.vrap.rmf.raml.validation.Violation
2120
import org.eclipse.emf.common.util.Diagnostic
2221
import org.eclipse.emf.common.util.URI
@@ -199,6 +198,7 @@ class ValidateSubcommand : Callable<Int> {
199198
OutputFormat.PHP_MARKDOWN -> MarkdownFormatPrinter(linkFormatter)
200199
OutputFormat.TS_MARKDOWN -> MarkdownFormatPrinter(linkFormatter)
201200
OutputFormat.DOTNET_MARKDOWN -> MarkdownFormatPrinter(linkFormatter)
201+
OutputFormat.GITHUB -> GithubFormatPrinter(linkFormatter)
202202
OutputFormat.JSON -> TODO()
203203
}
204204
}
@@ -280,6 +280,26 @@ class ValidateSubcommand : Callable<Int> {
280280
}
281281
}
282282

283+
class GithubFormatPrinter(override val linkFormatter: LinkFormatter): FormatPrinter {
284+
285+
override fun print(fileURI: URI, result: RamlModelResult<Api>): String {
286+
val validationResults = result.validationResults
287+
var output = ""
288+
if (validationResults.isNotEmpty()) {
289+
val errors = validationResults.filter { diagnostic -> diagnostic.severity == Diagnostic.ERROR }
290+
val warnings = validationResults.filter { diagnostic -> diagnostic.severity == Diagnostic.WARNING }
291+
val infos = validationResults.filter { diagnostic -> diagnostic.severity == Diagnostic.INFO }
292+
293+
if (errors.isNotEmpty()) output += errors.joinToString("\n") { "::error file=${java.net.URI.create(it.location).path},line=${it.line}::${it.detailMessage()}" }
294+
if (warnings.isNotEmpty()) output += errors.joinToString("\n") { "::warning file=${java.net.URI.create(it.location).path},line=${it.line}::${it.detailMessage()}" }
295+
if (infos.isNotEmpty()) output += errors.joinToString("\n") { "::notice file=${java.net.URI.create(it.location).path},line=${it.line}::${it.detailMessage()}" }
296+
297+
return output
298+
}
299+
return "✅ Specification at ${fileURI.toFileString()} is valid."
300+
}
301+
}
302+
283303
class MarkdownFormatPrinter(override val linkFormatter: LinkFormatter): FormatPrinter {
284304
override fun print(fileURI: URI, result: RamlModelResult<Api>): String {
285305
val relativeFileLink = Path(fileURI.toFileString()).relativeTo(linkFormatter.filePath)
@@ -321,5 +341,3 @@ class ValidateSubcommand : Callable<Int> {
321341
}
322342
}
323343
}
324-
325-

0 commit comments

Comments
 (0)