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

Commit

Permalink
Adding mix format corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
carlogilmar committed Sep 22, 2019
1 parent dd76db3 commit ed4af48
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 461 deletions.
2 changes: 1 addition & 1 deletion lib/spawnfest/analyzer_manager.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule AnalyzerManager do
use GenServer
alias SpawnfestWeb.Endpoint
alias SpawnfestWeb.Endpoint

def start_link(_opts \\ []) do
GenServer.start_link(__MODULE__, nil, name: __MODULE__)
Expand Down
5 changes: 2 additions & 3 deletions lib/spawnfest/application.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
defmodule Spawnfest.Application do

use Application

def start(_type, _args) do
children = [
SpawnfestWeb.Endpoint,
{AnalyzerManager, []}
SpawnfestWeb.Endpoint,
{AnalyzerManager, []}
]

opts = [strategy: :one_for_one, name: Spawnfest.Supervisor]
Expand Down
45 changes: 23 additions & 22 deletions lib/spawnfest/branch_engine.ex
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
defmodule BranchEngine do

def analize_branch(repo_dir) do
commits = get_commits_in_branch(repo_dir)
authors = get_authors_in_branch(commits)
frequency = FrequencyEngine.get_frequency(commits)
def analize_branch(repo_dir) do
commits = get_commits_in_branch(repo_dir)
authors = get_authors_in_branch(commits)
frequency = FrequencyEngine.get_frequency(commits)
words = get_words_by_commits(commits)
%Branch{
commits: commits,
authors: authors,
words: words,
frequency: frequency
}
end

%Branch{
commits: commits,
authors: authors,
words: words,
frequency: frequency
}
end

def get_commits_in_branch(repo_dir) do
repo_dir
|> get_commit_history_string()
|> Utils.get_commits()
|> get_commit_history_string()
|> Utils.get_commits()
end

def get_commit_history_string(repo_dir) do
{body, 0} =
System.cmd(
"git",
["log", "--all", "--pretty=format:'%h<->%cn<->%ad<->%s%Creset'"],
cd: repo_dir)
System.cmd(
"git",
["log", "--all", "--pretty=format:'%h<->%cn<->%ad<->%s%Creset'"],
cd: repo_dir
)

body
end

def get_words_by_commits(commits) do
commits
|> Utils.get_list_of_words_in_commits()
|> Utils.get_words_counters()
|> Utils.get_list_of_words_in_commits()
|> Utils.get_words_counters()
end

def get_authors_in_branch(commits), do: Utils.get_authors(commits)
def get_authors_in_branch(commits), do: Utils.get_authors(commits)
end

12 changes: 5 additions & 7 deletions lib/spawnfest/core.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
defmodule DiscoverMyProject do

def start_analyze(url_repo) do
IO.puts "1. Starting..."
IO.puts("1. Starting...")
repo_dir = GitEngine.clone_repo(url_repo)
IO.puts "2. Repo cloned..."
IO.puts("2. Repo cloned...")
branches = GitEngine.get_all_branches(repo_dir)
IO.puts "3. Branches done"
IO.puts("3. Branches done")
branch = BranchEngine.analize_branch(repo_dir)
IO.puts "4. Getting github information"
IO.puts("4. Getting github information")
[github_repo, issues, pr, contributors] = GitHubData.get_data_from_github(url_repo)
IO.puts "5. DONE!!!"
IO.puts("5. DONE!!!")
{url_repo, branches, branch, github_repo, issues, pr, contributors}
end

Expand All @@ -18,5 +17,4 @@ defmodule DiscoverMyProject do
branch = BranchEngine.analize_branch(repo_dir)
{branches, branch}
end

end
47 changes: 27 additions & 20 deletions lib/spawnfest/frequency_engine.ex
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
defmodule FrequencyEngine do

def get_frequency(commits) do
frequency_counters = %Frequency{}
update_frequency_counters(commits, frequency_counters)
frequency_counters = %Frequency{}
update_frequency_counters(commits, frequency_counters)
end

def update_frequency_counters([], frequency_counters), do: frequency_counters
def update_frequency_counters([commit|commits], frequency_counters) do
{day, date_created} = commit.date_created
day_key = get_day_key(day)
current_day = Map.get(frequency_counters, day_key)
hour_key = String.to_atom("hour_#{date_created.hour}")
hour_counter = Map.get(current_day, hour_key)
current_day_updated = Map.put(current_day, hour_key, hour_counter+1)
frequency_counters_updated = Map.put(frequency_counters, day_key, current_day_updated)
update_frequency_counters(commits, frequency_counters_updated)
end
def update_frequency_counters([], frequency_counters), do: frequency_counters

def update_frequency_counters([commit | commits], frequency_counters) do
{day, date_created} = commit.date_created
day_key = get_day_key(day)
current_day = Map.get(frequency_counters, day_key)
hour_key = String.to_atom("hour_#{date_created.hour}")
hour_counter = Map.get(current_day, hour_key)
current_day_updated = Map.put(current_day, hour_key, hour_counter + 1)
frequency_counters_updated = Map.put(frequency_counters, day_key, current_day_updated)
update_frequency_counters(commits, frequency_counters_updated)
end

defp get_day_key(day) do
days =
%{"Mon" => :monday, "Tue" => :tuesday, "Wed" => :wednesday,
"Thu" => :thursday, "Fri" => :friday, "Sat" => :saturday, "Sun" => :sunday}
days[day]
end
defp get_day_key(day) do
days = %{
"Mon" => :monday,
"Tue" => :tuesday,
"Wed" => :wednesday,
"Thu" => :thursday,
"Fri" => :friday,
"Sat" => :saturday,
"Sun" => :sunday
}

days[day]
end
end
7 changes: 3 additions & 4 deletions lib/spawnfest/git_engine.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
defmodule GitEngine do

def clone_repo(repo) do
date = :os.system_time(:millisecond)
tmp_dir = "#{System.tmp_dir()}repo-#{date}"
{"", 0} = System.cmd("git", ["clone", repo, tmp_dir])
tmp_dir
end

def get_all_branches(repo_dir) do
def get_all_branches(repo_dir) do
{body, 0} = System.cmd("git", ["branch", "--all"], cd: repo_dir)
Utils.get_branches_names(body)
end
Utils.get_branches_names(body)
end
end
38 changes: 20 additions & 18 deletions lib/spawnfest/github_engine.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
defmodule GitHubApiEngine do
@api"https://api.github.com/repos/"
@api "https://api.github.com/repos/"
@github_headers [{"Accept", "application/vnd.github.mercy-preview+json"}]

def get_repo_info do
fn {repo, org} ->
repo_info = NetworkConsumer.get("#{@api}#{org}/#{repo}", @github_headers)

%GitHubRepository{
fullname: repo_info["full_name"],
avatar_url: repo_info["owner"]["avatar_url"],
Expand All @@ -19,9 +20,9 @@ defmodule GitHubApiEngine do

def get_repo_issues do
fn {repo, org} ->
repo_info = NetworkConsumer.get("#{@api}#{org}/#{repo}/issues?state=all", @github_headers)
get_issues(repo_info)
end
repo_info = NetworkConsumer.get("#{@api}#{org}/#{repo}/issues?state=all", @github_headers)
get_issues(repo_info)
end
end

defp get_issues(repo_info) do
Expand All @@ -37,9 +38,9 @@ defmodule GitHubApiEngine do

def get_repo_pull_requests do
fn {repo, org} ->
repo_info = NetworkConsumer.get("#{@api}#{org}/#{repo}/pulls?state=all", @github_headers)
get_pull_requests(repo_info)
end
repo_info = NetworkConsumer.get("#{@api}#{org}/#{repo}/pulls?state=all", @github_headers)
get_pull_requests(repo_info)
end
end

defp get_pull_requests(pulls) do
Expand All @@ -58,7 +59,7 @@ defmodule GitHubApiEngine do
fn {repo, org} ->
repo_info = NetworkConsumer.get("#{@api}#{org}/#{repo}/contributors", @github_headers)
get_contributors(repo_info)
end
end
end

def get_contributors(repo_info) do
Expand All @@ -70,33 +71,34 @@ defmodule GitHubApiEngine do
}
end
end

end

defmodule GitHubUtil do
def get_repo_and_org(url) do
url_words = String.split(url, "/")
[repo|[org|_url_words]] = Enum.reverse(url_words)
[repo | [org | _url_words]] = Enum.reverse(url_words)
[repo, ""] = String.split(repo, ".git")
{repo, org}
end
end

defmodule GitHubData do

def get_data_from_github(url) do
repo_and_org = GitHubUtil.get_repo_and_org(url)
api_request =
[{GitHubApiEngine.get_repo_info, repo_and_org},
{GitHubApiEngine.get_repo_issues, repo_and_org},
{GitHubApiEngine.get_repo_pull_requests, repo_and_org},
{GitHubApiEngine.get_repo_contributors, repo_and_org}]
res =

api_request = [
{GitHubApiEngine.get_repo_info(), repo_and_org},
{GitHubApiEngine.get_repo_issues(), repo_and_org},
{GitHubApiEngine.get_repo_pull_requests(), repo_and_org},
{GitHubApiEngine.get_repo_contributors(), repo_and_org}
]

res =
api_request
|> Enum.map(fn {builder, args} -> apply_execution(builder, args) end)
|> Enum.map(fn builder -> Task.async(builder) end)
|> Enum.map(fn task -> Task.await(task, 9000) end)
end

defp apply_execution(fun, args), do: fn -> fun.(args) end
defp apply_execution(fun, args), do: fn -> fun.(args) end
end
1 change: 0 additions & 1 deletion lib/spawnfest/network_consumer.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule NetworkConsumer do

@options [recv_timeout: 5000]

def get(url) do
Expand Down
81 changes: 43 additions & 38 deletions lib/spawnfest/structs.ex
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
defmodule Branch do
defstruct [:commits, :authors, :words, :frequency]
defstruct [:commits, :authors, :words, :frequency]
end

defmodule Commit do
defstruct [:hash, :description, :author, :date_created, :words]
defstruct [:hash, :description, :author, :date_created, :words]
end

defmodule Day do
defstruct [
hour_0: 0,
hour_1: 0,
hour_2: 0,
hour_3: 0,
hour_4: 0,
hour_5: 0,
hour_6: 0,
hour_7: 0,
hour_8: 0,
hour_9: 0,
hour_10: 0,
hour_11: 0,
hour_12: 0,
hour_13: 0,
hour_14: 0,
hour_15: 0,
hour_16: 0,
hour_17: 0,
hour_18: 0,
hour_19: 0,
hour_20: 0,
hour_21: 0,
hour_22: 0,
hour_23: 0,
hour_24: 0
]
defstruct hour_0: 0,
hour_1: 0,
hour_2: 0,
hour_3: 0,
hour_4: 0,
hour_5: 0,
hour_6: 0,
hour_7: 0,
hour_8: 0,
hour_9: 0,
hour_10: 0,
hour_11: 0,
hour_12: 0,
hour_13: 0,
hour_14: 0,
hour_15: 0,
hour_16: 0,
hour_17: 0,
hour_18: 0,
hour_19: 0,
hour_20: 0,
hour_21: 0,
hour_22: 0,
hour_23: 0,
hour_24: 0
end

defmodule Frequency do
defstruct [
monday: %Day{},
tuesday: %Day{},
wednesday: %Day{},
thursday: %Day{},
friday: %Day{},
saturday: %Day{},
sunday: %Day{}]
defstruct monday: %Day{},
tuesday: %Day{},
wednesday: %Day{},
thursday: %Day{},
friday: %Day{},
saturday: %Day{},
sunday: %Day{}
end

defmodule GitHubRepository do
defstruct [:fullname, :avatar_url, :description, :open_issues, :forks, :language, :default_branch]
defstruct [
:fullname,
:avatar_url,
:description,
:open_issues,
:forks,
:language,
:default_branch
]
end

defmodule GitHubIssue do
Expand Down
Loading

0 comments on commit ed4af48

Please sign in to comment.