Bors-NG v0.1.0 BorsNG.GitHub.ServerMock View Source

Provides a fake connection to GitHub's REST API.

This is used for unit testing and when running in a "dev" environment, like on a local machine. It's basically just a genserver frontend for a big map; you can put and get its state, and other functions will mutate or read subsets of it.

For example, I can run iex -S mix phx.server and do this:

iex> # Push state to "GitHub"
iex> alias BorsNG.GitHub
iex> alias BorsNG.GitHub.ServerMock
iex> ServerMock.put_state(%{
...>   {:installation, 91} => %{ repos: [
...>     %GitHub.Repo{
...>       id: 14,
...>       name: "test/repo",
...>       owner: %{
...>         id: 6,
...>         login: "bors-fanboi",
...>         avatar_url: "data:image/svg+xml,<svg></svg>",
...>         type: :user
...>       }}
...>   ] },
...>   {{:installation, 91}, 14} => %{
...>     branches: %{},
...>     commits: %{},
...>     comments: %{1 => []},
...>     pulls: %{
...>       1 => %GitHub.Pr{
...>         number: 1,
...>         title: "Test",
...>         body: "Mess",
...>         state: :open,
...>         base_ref: "master",
...>         head_sha: "00000001",
...>         user: %GitHub.User{
...>           id: 6,
...>           login: "bors-fanboi",
...>           avatar_url: "data:image/svg+xml,<svg></svg>"}}},
...>     pr_commits: %{
...>       1 => [
...>         %GitHub.Commit{
...>           sha: "00000001",
...>           author_name: "Bors Fanboi",
...>           author_email: "bors-fanboi@example.com"}
...>       ] },
...>     statuses: %{},
...>     files: %{}}})
iex> GitHub.get_open_prs!({{:installation, 91}, 14})
[
  %BorsNG.GitHub.Pr{
    number: 1,
    title: "Test",
    body: "Mess",
    state: :open,
    base_ref: "master",
    head_sha: "00000001",
    user: %BorsNG.GitHub.User{
      id: 6,
      login: "bors-fanboi",
      avatar_url: "data:image/svg+xml,<svg></svg>"}}]

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for GenServer.init/1.

Link to this section Types

Link to this type

tstate()

View Source
tstate() :: %{
  optional(tconn()) => %{
    branches: %{optional(tbranch()) => tcommit()},
    comments: %{optional(integer()) => [bitstring()]},
    commits: %{optional(bitstring()) => tsynthesized()},
    statuses: %{
      optional(tbranch()) => %{
        optional(bitstring()) => :open | :closed | :running
      }
    },
    files: %{optional(tbranch()) => %{optional(bitstring()) => bitstring()}},
    collaborators: [tcollaborator()]
  },
  optional({:installation, number()}) => %{repos: [trepo()]},
  :users => %{optional(bitstring()) => tuser()},
  :merge_conflict => integer()
}
Link to this type

tsynthesized()

View Source
tsynthesized() :: %{commit_message: bitstring(), parents: [bitstring()]}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

do_handle_call(atom, repo_conn, params, state)

View Source

Callback implementation for GenServer.init/1.