forked from code-corps/code-corps-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepository.ex
More file actions
72 lines (66 loc) · 2.15 KB
/
repository.ex
File metadata and controls
72 lines (66 loc) · 2.15 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
defmodule CodeCorps.GitHub.API.Repository do
@moduledoc ~S"""
Functions for retrieving a GitHub repository's issues, pull requests, and
comments from the GitHub API.
"""
alias CodeCorps.{
GitHub,
GitHub.API,
GithubAppInstallation,
GithubRepo,
}
@doc ~S"""
Retrieves issues for a repository
All pages of records are retrieved.
Closed issues are included.
"""
@spec issues(GithubRepo.t) :: {:ok, list(map)} | {:error, GitHub.paginated_endpoint_error}
def issues(%GithubRepo{
github_app_installation: %GithubAppInstallation{
github_account_login: owner
} = installation,
name: repo
}) do
with {:ok, access_token} <- API.Installation.get_access_token(installation) do
"repos/#{owner}/#{repo}/issues"
|> GitHub.get_all(%{}, [access_token: access_token, params: [per_page: 100, state: "all"]])
else
{:error, error} -> {:error, error}
end
end
@doc ~S"""
Retrieves pull requests for a repository.
All pages of records are retrieved.
"""
@spec pulls(GithubRepo.t) :: {:ok, list(map)} | {:error, GitHub.paginated_endpoint_error}
def pulls(%GithubRepo{
github_app_installation: %GithubAppInstallation{
github_account_login: owner
} = installation,
name: repo
}) do
with {:ok, access_token} <- API.Installation.get_access_token(installation) do
"repos/#{owner}/#{repo}/pulls"
|> GitHub.get_all(%{}, [access_token: access_token, params: [per_page: 100, state: "all"]])
else
{:error, error} -> {:error, error}
end
end
@doc ~S"""
Retrieves comments from all issues in a github repository.
"""
@spec issue_comments(GithubRepo.t) :: {:ok, list(map)} | {:error, GitHub.paginated_endpoint_error}
def issue_comments(%GithubRepo{
github_app_installation: %GithubAppInstallation{
github_account_login: owner
} = installation,
name: repo
}) do
with {:ok, access_token} <- API.Installation.get_access_token(installation) do
"repos/#{owner}/#{repo}/issues/comments"
|> GitHub.get_all(%{}, [access_token: access_token, params: [per_page: 100]])
else
{:error, error} -> {:error, error}
end
end
end