Skip to content

Commit

Permalink
fix: prevent contributor duplication problem fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
tahadostifam committed Apr 1, 2024
1 parent 512940f commit 59dd7d7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions get_contributors.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'octokit'

module GetContributors
def self.has_contributor?(list, username)
list.find { |c| c[:username] == username} != nil
end

def self.get_contributors(github_pa, org_name)
client = Octokit::Client.new(:access_token => github_pa)

Expand All @@ -14,12 +18,15 @@ def self.get_contributors(github_pa, org_name)

if repo_contributors.instance_of? Array
repo_contributors.each do |contributor|
contributors << {
:id => contributor.id,
:username => contributor.login,
:url => contributor.url,
:avatar_url => contributor.avatar_url,
}
# Prevent duplicate contributor
if !self.has_contributor?(contributors, contributor.login)
contributors << {
:id => contributor.id,
:username => contributor.login,
:url => contributor.url,
:avatar_url => contributor.avatar_url,
}
end
end
else
puts "Can't get contributions of #{repo.full_name}."
Expand Down

0 comments on commit 59dd7d7

Please sign in to comment.