Skip to content

Commit f9e2dad

Browse files
committed
check GH printer for custom checkout dir
1 parent a7ea6c8 commit f9e2dad

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

.github/workflows/ci.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ jobs:
2424
- name: Build and Release
2525
run: ./gradlew clean check shadowJar
2626

27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
with:
30+
path: test
31+
2732
- name: Test validate
2833
continue-on-error: true
29-
run: ./rmf-gen.sh validate -f GITHUB -r ./api-spec/ruleset.xml ./api-spec/api.raml
34+
run: ./rmf-gen.sh validate -f GITHUB ./api-spec/api.raml
35+
working-directory: test
3036
test_node:
3137
name: Build npm package
3238

api-spec/types/error.raml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ types:
1818
type: string
1919
error_description?:
2020
type: string
21+
error_description2?:
22+
type: string
2123
errors?:
2224
type: ErrorObject[]
2325
ErrorObject:

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

+19-9
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ import java.nio.file.Paths
2828
import java.util.*
2929
import java.util.concurrent.Callable
3030
import java.util.concurrent.TimeUnit
31-
import kotlin.io.path.Path
32-
import kotlin.io.path.relativeTo
33-
import kotlin.io.path.relativeToOrSelf
34-
import kotlin.io.path.toPath
31+
import kotlin.io.path.*
3532

3633
enum class DiagnosticSeverity(val severity: String, val value: Int) {
3734
INFO("info", Diagnostic.INFO),
@@ -67,6 +64,9 @@ class ValidateSubcommand : Callable<Int> {
6764
@CommandLine.Option(names = ["-l", "--link-base"])
6865
var linkBase: java.net.URI? = null
6966

67+
@CommandLine.Option(names = ["-d", "--dir-base"])
68+
var dirBase: Path? = null
69+
7070
@CommandLine.Option(names = ["-lf", "--link-format"], description = ["Specifies the link format","Valid values: ${LinkFormat.VALID_VALUES}"] )
7171
var linkFormat: LinkFormat = LinkFormat.CLI
7272

@@ -92,6 +92,10 @@ class ValidateSubcommand : Callable<Int> {
9292
return uri
9393
}
9494

95+
private fun dirBase(): Path {
96+
return dirBase ?: Paths.get("").toAbsolutePath()
97+
}
98+
9599
override fun call(): Int {
96100
if (listRules) {
97101
println("Available validators:")
@@ -198,7 +202,7 @@ class ValidateSubcommand : Callable<Int> {
198202
OutputFormat.PHP_MARKDOWN -> MarkdownFormatPrinter(linkFormatter)
199203
OutputFormat.TS_MARKDOWN -> MarkdownFormatPrinter(linkFormatter)
200204
OutputFormat.DOTNET_MARKDOWN -> MarkdownFormatPrinter(linkFormatter)
201-
OutputFormat.GITHUB -> GithubFormatPrinter(linkFormatter)
205+
OutputFormat.GITHUB -> GithubFormatPrinter(dirBase(), linkFormatter)
202206
OutputFormat.JSON -> TODO()
203207
}
204208
}
@@ -280,24 +284,30 @@ class ValidateSubcommand : Callable<Int> {
280284
}
281285
}
282286

283-
class GithubFormatPrinter(override val linkFormatter: LinkFormatter): FormatPrinter {
287+
class GithubFormatPrinter(val dirBase: Path, override val linkFormatter: LinkFormatter): FormatPrinter {
284288

285289
override fun print(fileURI: URI, result: RamlModelResult<Api>): String {
290+
System.out.println(dirBase)
286291
val validationResults = result.validationResults
287292
var output = ""
288293
if (validationResults.isNotEmpty()) {
289294
val errors = validationResults.filter { diagnostic -> diagnostic.severity == Diagnostic.ERROR }
290295
val warnings = validationResults.filter { diagnostic -> diagnostic.severity == Diagnostic.WARNING }
291296
val infos = validationResults.filter { diagnostic -> diagnostic.severity == Diagnostic.INFO }
292297

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()}" }
298+
if (errors.isNotEmpty()) output += errors.joinToString("\n") { "::error file=${it.toLocation(dirBase)},line=${it.line}::${it.detailMessage()}" }
299+
if (warnings.isNotEmpty()) output += errors.joinToString("\n") { "::warning file=${it.toLocation(dirBase)},line=${it.line}::${it.detailMessage()}" }
300+
if (infos.isNotEmpty()) output += errors.joinToString("\n") { "::notice file=${it.toLocation(dirBase)},line=${it.line}::${it.detailMessage()}" }
296301

297302
return output
298303
}
299304
return "::notice ::Specification at ${fileURI.toFileString()} is valid."
300305
}
306+
307+
fun RamlDiagnostic.toLocation(filePath: Path): Path {
308+
return java.net.URI.create(this.location).toPath().relativeToOrSelf(filePath)
309+
}
310+
301311
}
302312

303313
class MarkdownFormatPrinter(override val linkFormatter: LinkFormatter): FormatPrinter {

0 commit comments

Comments
 (0)