-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- model, state transition, and tests - views and tests - controller, policies, tests - API blueprint docs
- Loading branch information
Showing
19 changed files
with
695 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
lib/code_corps/transition/github_app_installation_state.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule CodeCorps.Transition.GithubAppInstallationState do | ||
@moduledoc """ | ||
Governs the transitioning from one state to the next. | ||
The possible `state` values are: | ||
- `initiated_on_code_corps` - The user clicks a button or link in the Code Corps UI and is redirected to GitHub to install. This process creates the `GithubAppInstallation` record before redirecting. | ||
- `initiated_on_github` - We receive an installation webhook with a matching user, but an installation was never created on Code Corps. This can happen because GitHub does not assume an app will _only_ be installed at a starting point outside GitHub. | ||
- `processing` - When the installation webhook is received, was matched, and is now processing. | ||
- `processed` - The integration process is completed. There is now a working installation attached to the project. | ||
- `unmatched_user` - When we receive a webhook but there is no Code Corps user matching the given GitHub user's GitHub `id`. This is sent in the `sender` key of the `installation` event by GitHub. | ||
It is possible to resolve more problematic states like `unmatched_user` when the user provides more information, e.g. connecting their GitHub account. The transitions below allow for some of these edge cases. | ||
""" | ||
|
||
def next(nil, "initiated_on_code_corps"), do: {:ok, "initiated_on_code_corps"} | ||
|
||
def next(current_state, nil), do: {:ok, current_state} | ||
|
||
def next("initiated_on_code_corps", "processing"), do: {:ok, "processing"} | ||
def next("initiated_on_code_corps", "processed"), do: {:ok, "processed"} | ||
def next("initiated_on_code_corps", "unmatched_user"), do: {:ok, "unmatched_user"} | ||
|
||
def next("processing", "processed"), do: {:ok, "processed"} | ||
def next("processing", "unmatched_user"), do: {:ok, "unmatched_user"} | ||
|
||
def next("unmatched_user", "processing"), do: {:ok, "processing"} | ||
def next("unmatched_user", "processed"), do: {:ok, "processed"} | ||
|
||
def next(current_state, next_state) when current_state == next_state, do: {:ok, next_state} | ||
def next(current_state, next_state), do: {:error, "invalid transition to #{next_state} from #{current_state}"} | ||
end |
19 changes: 19 additions & 0 deletions
19
priv/repo/migrations/20170622205732_create_github_app_installation.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule CodeCorps.Repo.Migrations.CreateGithubAppInstallation do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:github_app_installations) do | ||
add :github_id, :integer | ||
add :installed, :boolean, default: true | ||
add :state, :string | ||
|
||
add :project_id, references(:projects, on_delete: :nothing) | ||
add :user_id, references(:users, on_delete: :nothing) | ||
|
||
timestamps() | ||
end | ||
|
||
create index(:github_app_installations, [:project_id]) | ||
create index(:github_app_installations, [:user_id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.