lightbend / paradox

Markdown documentation
https://github.com/lightbend/paradox/blob/main/docs/src/main/paradox/index.md
Apache License 2.0
247 stars 76 forks source link

It's impossible to change hardcoded "/tree/master" suffix when ScmInfo is defined #198

Closed pshirshov closed 6 years ago

pshirshov commented 6 years ago

Theoretically this should do the job:

  private def treeUrl = baseUrl.collect {
    case TreeUrl(url)    => url
    case ProjectUrl(url) => url + "/tree/master"
    case _               => throw Url.Error("[github.base_url] is not a project or versioned tree URL")
}

As per:

@ val a = """(.*github.com/[^/]+/[^/]+/tree/[^/]+)""".r
a: scala.util.matching.Regex = (.*github.com/[^/]+/[^/]+/tree/[^/]+)

@ a.unapplySeq("https://github.com/pshirshov/izumi-r2/tree/develop/")
res1: Option[List[String]] = None

@ a.unapplySeq("https://github.com/pshirshov/izumi-r2/tree/develop")
res2: Option[List[String]] = Some(List("https://github.com/pshirshov/izumi-r2/tree/develop"))

But despite of how I define URL in ScmInfo, this match never triggers on TreeUrl. Why?

I guess because you don't convert URL to String here:

 "github.base_url" -> scmInfo.map(_.browseUrl).filter(_.getHost == "github.com)

So, in fact you match against an instance of URL and it fails. Eh.

2m commented 6 years ago

While working on a similar issue (#227) I created more tests around ScmInfo and TreeUrl and I could not make it fail in the same way as reported here.

@pshirshov, take a look at this test. It sets the ScmInfo to contain the /tree/... part and then asserts generated documentation has the corresponding /tree/... in the links.

2m commented 6 years ago

I think this now should be fixed after #253 got merged.