     end
   end
 
-  # Returns a gproc via tuple for identifying pipeline Agents.
-  defp via_tuple(identifier) do
-    {:via, :gproc, gproc_key(identifier)}
-  end
+  defp via_tuple(pipeline), do: {:via, :gproc, gproc_key(pipeline)}
 
-  # Returns a key for identifying pipelines in the gproc extended process
-  # registry.
-  #
-  # * type ':n` means 'name' and is unique within the given context
-  # * scope `:l` means the 'local' context
+  @spec gproc_key(t | Repo.t | String.t) :: tuple
   defp gproc_key(%Pipeline{} = pipeline), do: gproc_key(pipeline.repo)
   defp gproc_key(%Repo{} = repo), do: gproc_key("#{repo}")
   defp gproc_key(name) when is_binary(name) do
     {:n, :l, {__MODULE__, name}}
   end
 
-  # Returns the pid of the specified pipeline's agent.
+  # TODO: remove this after figuring out appropriate module interfaces
+  def __whereis__(pipeline), do: :gproc.where(gproc_key(pipeline))
+
+  # Creates a new pipeline with the given `config` settings.
   #
-  # Returns `:undefined` if no process is registered with the given key.
-  def __whereis__(identifier) do
-    :gproc.where(gproc_key(identifier))
-  end
-
-  @doc """
-  Creates a new pipeline with the given `config` settings.
-
-  Returns `{:ok, pipeline}` if the configuration is valid, otherwise `:error`.
-  """
-  @spec new(Config.t) :: {:ok, t} | :error
-  def new(config) do
+  # Returns `{:ok, pipeline}` if the configuration is valid, otherwise
+  # `{:error, :invalid_config}`.
+  @spec new(Config.t) :: {:ok, t} | {:error, :invalid_config}
+  defp new(config) do
     with config = Config.parse_runtime_settings(config),
          true <- valid_config?(config),
-         repo = Repo.new(config[:repo_provider], config[:repo_owner], config[:repo_name]),
-         pipeline = %Pipeline{config: config, repo: repo, worker: config[:worker]} do
+         pipeline = from_config(config) do
       {:ok, pipeline}
     else
-      _ -> :error
+      _ -> {:error, :invalid_config}
     end
   end
 

  defstruct [
    config: [],
    repo: nil,
    merge_requests: %{},
    worker: nil
  ]

  alias Gullintanni.Comment
  alias Gullintanni.Repo
  alias Gullintanni.Worker

  @typedoc "The pipeline type"
  @type t ::
    %Pipeline{
      config: Config.t,
      repo: Repo.t,
      bot_name: String.t,
      merge_requests: map,
      worker: Worker.t
    }
