Skip to content

Commit 9ddf215

Browse files
committed
add the ability to find unrecognized author emails
Urecognized authors can cause an error because we don't have a login for them. This commit: * Adds the ability to find unauthorized users * Creates a new file for the unauthorized users
1 parent 6dba587 commit 9ddf215

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

api/ruby/find-inactive-members/find_inactive_members.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class InactiveMemberSearch
8-
attr_accessor :organization, :members, :repositories, :date
8+
attr_accessor :organization, :members, :repositories, :date, :unrecognized_authors
99

1010
SCOPES=["read:org", "read:user", "repo", "user:email"]
1111

@@ -26,6 +26,7 @@ def initialize(options={})
2626
@date = options[:date]
2727
@organization = options[:organization]
2828
@email = options[:email]
29+
@unrecognized_authors = []
2930

3031
organization_members
3132
organization_repositories
@@ -101,6 +102,10 @@ def organization_repositories
101102
info "#{@repositories.length} repositories discovered\n"
102103
end
103104

105+
def add_unrecognized_author(author)
106+
@unrecognized_authors << author
107+
end
108+
104109
# method to switch member status to active
105110
def make_active(login)
106111
hsh = @members.find { |member| member[:login] == login }
@@ -112,6 +117,10 @@ def commit_activity(repo)
112117
info "...commits"
113118
@client.commits_since(repo, @date).each do |commit|
114119
# if commmitter is a member of the org and not active, make active
120+
if commit["author"].nil?
121+
add_unrecognized_author(commit[:commit][:author])
122+
next
123+
end
115124
if t = @members.find {|member| member[:login] == commit["author"]["login"] && member[:active] == false }
116125
make_active(t[:login])
117126
end
@@ -188,12 +197,20 @@ def member_activity
188197
# iterate and print inactive members
189198
@members.each do |member|
190199
if member[:active] == false
191-
member_detail = "#{member[:login]} <#{member[:email] unless member[:email].nil?}>"
200+
member_detail = "#{member[:login]},#{member[:email] unless member[:email].nil?}"
192201
info "#{member_detail} is inactive\n"
193202
csv << [member_detail]
194203
end
195204
end
196205
end
206+
207+
CSV.open("unrecognized_authors.csv", "wb") do |csv|
208+
@unrecognized_authors.each do |author|
209+
author_detail = "#{author[:name]},#{author[:email]}"
210+
info "#{author_detail} is unrecognized\n"
211+
csv << [author_detail]
212+
end
213+
end
197214
end
198215
end
199216

0 commit comments

Comments
 (0)