Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
Set default response when there are information not provided in github
Browse files Browse the repository at this point in the history
  • Loading branch information
carlogilmar committed Sep 22, 2019
1 parent e304a9a commit 522f5f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/spawnfest/github/github_engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ defmodule GitHubApiEngine do
repo_info = NetworkConsumer.get("#{@api}#{org}/#{repo}", @github_headers)

%GitHubRepository{
fullname: repo_info["full_name"],
avatar_url: repo_info["owner"]["avatar_url"],
description: repo_info["description"],
open_issues: repo_info["open_issues"],
forks: repo_info["forks"],
language: repo_info["language"],
default_branch: repo_info["default_branch"]
fullname: GitHubUtil.set_default_response.(repo_info["full_name"]),
avatar_url: GitHubUtil.set_default_response.(repo_info["owner"]["avatar_url"]),
description: GitHubUtil.set_default_response.(repo_info["description"]),
open_issues: GitHubUtil.set_default_response.(repo_info["open_issues"]),
forks: GitHubUtil.set_default_response.(repo_info["forks"]),
language: GitHubUtil.set_default_response.(repo_info["language"]),
default_branch: GitHubUtil.set_default_response.(repo_info["default_branch"])
}
end
end
Expand All @@ -31,10 +31,10 @@ defmodule GitHubApiEngine do
defp get_issues(repo_info) do
for issue <- repo_info do
%GitHubIssue{
url: issue["html_url"],
title: issue["title"],
state: issue["state"],
date_created: issue["created_at"]
url: GitHubUtil.set_default_response.(issue["html_url"]),
title: GitHubUtil.set_default_response.(issue["title"]),
state: GitHubUtil.set_default_response.(issue["state"]),
date_created: GitHubUtil.set_default_response.(issue["created_at"])
}
end
end
Expand All @@ -49,11 +49,11 @@ defmodule GitHubApiEngine do
defp get_pull_requests(pulls) do
for pull <- pulls do
%GitHubPR{
number: pull["number"],
title: pull["title"],
state: pull["state"],
url: pull["html_url"],
author: pull["author_association"]
number: GitHubUtil.set_default_response.(pull["number"]),
title: GitHubUtil.set_default_response.(pull["title"]),
state: GitHubUtil.set_default_response.(pull["state"]),
url: GitHubUtil.set_default_response.(pull["html_url"]),
author: GitHubUtil.set_default_response.(pull["author_association"])
}
end
end
Expand All @@ -68,9 +68,9 @@ defmodule GitHubApiEngine do
def get_contributors(repo_info) do
for contributor <- repo_info do
%GitHubContributor{
avatar_url: contributor["avatar_url"],
username: contributor["login"],
contributions: contributor["contributions"]
avatar_url: GitHubUtil.set_default_response.(contributor["avatar_url"]),
username: GitHubUtil.set_default_response.(contributor["login"]),
contributions: GitHubUtil.set_default_response.(contributor["contributions"])
}
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/spawnfest/utils/github_util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ defmodule GitHubUtil do
[repo, ""] = String.split(repo, ".git")
{repo, org}
end

def set_default_response do
fn
nil -> "No provided."
desc -> desc
end
end
end

0 comments on commit 522f5f4

Please sign in to comment.