forked from code-corps/code-corps-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_app_installation.ex
More file actions
54 lines (46 loc) · 1.72 KB
/
github_app_installation.ex
File metadata and controls
54 lines (46 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
defmodule CodeCorps.GithubAppInstallation do
@moduledoc ~S"""
Represents an installation of the CodeCorps app to a user or an organization on GitHub.
"""
use CodeCorps.Model
@type t :: %__MODULE__{}
schema "github_app_installations" do
field :access_token, :string
field :access_token_expires_at, :utc_datetime
field :github_account_avatar_url, :string
field :github_account_id, :integer
field :github_account_login, :string
field :github_account_type, :string
field :github_id, :integer
field :installed, :boolean
field :origin, :string, default: "codecorps" # "codecorps" or "github"
field :sender_github_id, :integer
# "unprocessed", "processing", "processed" or "errored"
field :state, :string, default: "unprocessed"
belongs_to :project, CodeCorps.Project # The originating project
belongs_to :user, CodeCorps.User
has_many :github_repos, CodeCorps.GithubRepo
has_many :organization_github_app_installations, CodeCorps.OrganizationGithubAppInstallation
timestamps()
end
@doc ~S"""
Changeset used to create a GithubAppInstallation record from CodeCorps
"""
def create_changeset(struct, params \\ %{}) do
struct
|> cast(params, [:project_id, :user_id])
|> validate_required([:project_id, :user_id])
|> assoc_constraint(:project)
|> assoc_constraint(:user)
|> put_change(:origin, "codecorps")
|> put_change(:state, "unprocessed")
end
@doc ~S"""
Changeset used to refresh an access token for a GithubAppInstallation
"""
def access_token_changeset(struct, params \\ %{}) do
struct
|> cast(params, [:access_token, :access_token_expires_at])
|> validate_required([:access_token, :access_token_expires_at])
end
end