Skip to content

Commit fd0d095

Browse files
authored
find_inactive_members works with advisories (#289)
* private forks created to discuss and mitigate security advisories did work with find_incative_members.rb * readson: GitHub's API returns 404 (not found) instead of an empty set for issues and issue comments of such a private fork if no access is granted * fix: ignore 404 for issues and issue comments and proceed
1 parent 889524a commit fd0d095

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def organization_members
8282
# get all organization members and place into an array of hashes
8383
info "Finding #{@organization} members "
8484
@members = @client.organization_members(@organization).collect do |m|
85-
email =
85+
email =
8686
{
8787
login: m["login"],
8888
email: member_email(m[:login]),
@@ -136,30 +136,40 @@ def commit_activity(repo)
136136
def issue_activity(repo, date=@date)
137137
# get all issues after specified date and iterate
138138
info "...Issues"
139-
@client.list_issues(repo, { :since => date }).each do |issue|
140-
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
141-
if issue["user"].nil?
142-
next
143-
end
144-
# if creator is a member of the org and not active, make active
145-
if t = @members.find {|member| member[:login] == issue["user"]["login"] && member[:active] == false }
146-
make_active(t[:login])
139+
begin
140+
@client.list_issues(repo, { :since => date }).each do |issue|
141+
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
142+
if issue["user"].nil?
143+
next
144+
end
145+
# if creator is a member of the org and not active, make active
146+
if t = @members.find {|member| member[:login] == issue["user"]["login"] && member[:active] == false }
147+
make_active(t[:login])
148+
end
147149
end
150+
rescue Octokit::NotFound
151+
#API responds with a 404 (instead of an empty set) when repo is a private fork for security advisories
152+
info "...no access to issues in this repo ..."
148153
end
149154
end
150155

151156
def issue_comment_activity(repo, date=@date)
152157
# get all issue comments after specified date and iterate
153158
info "...Issue comments"
154-
@client.issues_comments(repo, { :since => date }).each do |comment|
155-
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
156-
if comment["user"].nil?
157-
next
158-
end
159-
# if commenter is a member of the org and not active, make active
160-
if t = @members.find {|member| member[:login] == comment["user"]["login"] && member[:active] == false }
161-
make_active(t[:login])
159+
begin
160+
@client.issues_comments(repo, { :since => date }).each do |comment|
161+
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
162+
if comment["user"].nil?
163+
next
164+
end
165+
# if commenter is a member of the org and not active, make active
166+
if t = @members.find {|member| member[:login] == comment["user"]["login"] && member[:active] == false }
167+
make_active(t[:login])
168+
end
162169
end
170+
rescue Octokit::NotFound
171+
#API responds with a 404 (instead of an empty set) when repo is a private fork for security advisories
172+
info "...no access to issue comments in this repo ..."
163173
end
164174
end
165175

0 commit comments

Comments
 (0)