-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathgithub_mock.ex
More file actions
136 lines (116 loc) · 3.03 KB
/
github_mock.ex
File metadata and controls
136 lines (116 loc) · 3.03 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
defmodule Algora.Support.GithubMock do
@moduledoc false
@behaviour Algora.Github.Behaviour
defp random_id(n \\ 1000), do: :rand.uniform(n)
@impl true
def get_issue(_access_token, owner, repo, number) do
{:ok,
%{
"id" => random_id(),
"title" => "title #{number}",
"body" => "body #{number}",
"number" => number,
"html_url" => "https://github.com/#{owner}/#{repo}/issues/#{number}"
}}
end
@impl true
def get_repository(_access_token, owner, repo) do
{:ok,
%{
"id" => random_id(),
"name" => repo,
"html_url" => "https://github.com/#{owner}/#{repo}",
"owner" => %{
"login" => owner
}
}}
end
@impl true
def get_repository(_access_token, id) do
owner = "owner_#{random_id()}"
name = "repo_#{random_id()}"
{:ok,
%{
"id" => id,
"name" => name,
"html_url" => "https://github.com/#{owner}/#{name}",
"owner" => %{
"login" => owner
}
}}
end
@impl true
def get_pull_request(_access_token, owner, repo, number) do
{:ok,
%{
"id" => random_id(),
"title" => "title #{number}",
"body" => "body #{number}",
"number" => number,
"html_url" => "https://github.com/#{owner}/#{repo}/pull/#{number}"
}}
end
@impl true
def get_current_user(_access_token) do
{:ok, %{"id" => random_id(), "login" => "user_#{random_id()}"}}
end
@impl true
def get_current_user_emails(_access_token) do
{:ok, [%{"email" => "user_#{random_id()}@example.com"}]}
end
@impl true
def get_user(_access_token, id) do
{:ok, %{"id" => id, "login" => "user_#{random_id()}"}}
end
@impl true
def get_user_by_username(_access_token, username) do
{:ok, %{"id" => random_id(), "login" => username}}
end
@impl true
def get_repository_permissions(_access_token, _owner, _repo, username) do
{:ok,
%{
"permission" =>
case username do
"admin" <> _ -> "admin"
_ -> "none"
end
}}
end
@impl true
def list_installations(_token, _page \\ 1) do
{:ok, %{"installations" => []}}
end
@impl true
def find_installation(_token, _installation_id, _page \\ 1) do
{:ok, %{"id" => random_id()}}
end
@impl true
def get_installation_token(_installation_id) do
{:ok, %{"token" => "token_#{random_id()}"}}
end
@impl true
def list_installation_repos(_access_token) do
{:ok, []}
end
@impl true
def create_issue_comment(_access_token, _owner, _repo, _number, _body) do
{:ok, %{"id" => random_id()}}
end
@impl true
def update_issue_comment(_access_token, _owner, _repo, _comment_id, _body) do
{:ok, %{"id" => random_id()}}
end
@impl true
def list_repository_events(_access_token, _owner, _repo, _opts \\ []) do
{:ok, []}
end
@impl true
def list_repository_comments(_access_token, _owner, _repo, _opts \\ []) do
{:ok, []}
end
@impl true
def add_labels(_access_token, _owner, _repo, _number, _labels) do
{:ok, []}
end
end