Skip to content

Commit 52f99bd

Browse files
committed
Added logic that routes user to appropiate message displayer
1 parent 88cb0dd commit 52f99bd

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

app/services/github_service.rb

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def initialize(user)
55
@connection = Hurley::Client.new("https://api.github.com")
66
@connection.query[:access_token] = user.token
77
@stats = GithubStats.new(user.nickname)
8+
@user = user
89
end
910

1011
def find_user_repos(user)
@@ -41,12 +42,14 @@ def total_starred_repos(user)
4142
parse(connection.get("users/#{user.nickname}/starred"))
4243
end
4344

45+
46+
4447
def commit_message(user)
4548
list = parse(connection.get("/users/#{user.nickname}/events"))
4649
if list == "[]"
4750
["User has no events"]
4851
else
49-
find_events_from_list(list)
52+
find_events_from_list(list, user)
5053
end
5154
end
5255

@@ -55,25 +58,33 @@ def followers_commit_message(name)
5558
if list == []
5659
["User has no events"]
5760
else
58-
find_events_from_list(list)
61+
find_events_from_list(list, name)
5962
end
6063
end
6164

62-
def find_events_from_list(list)
65+
def find_events_from_list(list, user_id)
6366
events = list.select { |item| item[:type] == "PushEvent" }
6467
if events == []
6568
["User has no Push Events"]
6669
else
67-
find_commits_from_events(events)
70+
find_commits_from_events(events, user_id)
6871
end
6972
end
7073

71-
def find_commits_from_events(events)
74+
def find_commits_from_events(events, user_id)
7275
commits = events.map{ |event| event[:payload][:commits] }.flatten!
7376
if commits.nil?
7477
["User has no commits"]
7578
else
76-
find_messages_from_commits_user(commits)
79+
user_redirect(commits, user_id)
80+
end
81+
end
82+
83+
def user_redirect(commits, user_id)
84+
if @user == user_id
85+
find_messages_from_commits_user(commits)
86+
else
87+
find_messages_from_commits(commits)
7788
end
7889
end
7990

@@ -86,14 +97,14 @@ def find_messages_from_commits_user(commits)
8697
end
8798
end
8899

89-
# def find_messages_from_commits(commits)
90-
# messages = commits.collect{ |commit| commit[:message] }
91-
# if messages == "[]"
92-
# ["User has no commit messages"]
93-
# else
94-
# messages[0]
95-
# end
96-
# end
100+
def find_messages_from_commits(commits)
101+
messages = commits.collect{ |commit| commit[:message] }
102+
if messages == "[]"
103+
["User has no commit messages"]
104+
else
105+
messages[0]
106+
end
107+
end
97108

98109
def followers_activity(user)
99110
names = find_user_follows(user).collect {|item| item[:login] }

0 commit comments

Comments
 (0)