Search code examples
elixirdocumentation-generation

ExDoc: getting source links working with private repository


I'm trying to generate documentation for my project.

I've added {:ex_doc, "~> 0.16", only: :dev, runtime: false} to my deps, set source_url to my repository and run mix docs.

I'm using Github Enterprise so my setting is something like this: source_url: "https://my.private.repo/adam/projname"

However, in the generated docs, all of the links to the source point directly to https://my.private.repo/adam/projname rather than the the relvant file and line number.

An example of what I want to do:

https://hexdocs.pm/ex_doc/Mix.Tasks.Docs.html

The link at the top-right of this file links to https://github.com/elixir-lang/ex_doc/blob/v0.18.3/lib/mix/tasks/docs.ex#L1

In my generated docs, every link just links to https://my.private.repo/adam/projname.

I've tried setting source_ref to master, but this made no difference.

How do I get ExDoc to generate properly specific links to the source code?

Here's a simplified version of my mix.exs file:

defmodule ProjectName.MixProject do
  use Mix.Project

  def project do
    [
      app: :project_name,
      version: "0.1.0",
      elixir: "~> 1.6",
      deps: deps(),

      # Docs
      name: "ProjectName",
      source_url: "https://my.private.repo/adam/projname"
    ]
  end
end

Solution

  • ex_doc will only automatically figure out where to find the file when you're using one of the following domains as source_url. ex_docs source

    • github.com
    • bitbucket.com
    • gitlab.com

    In the cases where the domain is different, you will have to supply a source_url_pattern in the docs section of your mix.exs file

      def project do
        [
          app: :test_exdoc,
          version: "0.1.0",
          elixir: "~> 1.7-dev",
          start_permanent: Mix.env() == :prod,
          source_url: "https://yourprivate-repo.com/adam/projname",
          deps: deps(),
          docs: [
            source_url_pattern: "https://yourprivate-repo.com/adam/projname/blob/master/%{path}#L%{line}"
          ]
        ]
      end