Skip to content

Commit

Permalink
Display top contributors in collection sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jul 25, 2024
1 parent 6294e60 commit 440c8d3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
12 changes: 12 additions & 0 deletions app/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ def hosts
projects.map(&:host).flatten.group_by(&:itself).transform_values(&:count).sort_by{|k,v| v}.reverse
end

def contributors
combined_hash = Hash.new(0)

projects.map(&:contributors).each do |contributors|
contributors.each do |k,v|
combined_hash[k] += v
end
end

combined_hash.sort_by{|k,v| v}.reverse
end

def import_keyword(keyword)
resp = Faraday.get("https://packages.ecosyste.ms/api/v1/keywords/#{keyword}?per_page=1000")
if resp.status == 200
Expand Down
23 changes: 23 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Project < ApplicationRecord
scope :language, ->(language) { where("(repository ->> 'language') = ?", language) }
scope :owner, ->(owner) { where("(repository ->> 'owner') = ?", owner) }
scope :with_repository, -> { where.not(repository: nil) }
scope :with_issues, -> { where.not(issues: nil) }

def self.sync_least_recently_synced
Project.where(last_synced_at: nil).or(Project.where("last_synced_at < ?", 1.day.ago)).order('last_synced_at asc nulls first').limit(500).each do |project|
Expand Down Expand Up @@ -244,6 +245,28 @@ def raw_committers
commits["committers"]
end

def contributors
return [] unless issues.present?

combined_authors = issue_authors.merge(pull_request_authors) do |key, oldval, newval|
oldval + newval
end

combined_authors
end

def issue_authors
return {} unless issues.present?
return {} unless issues.issue_authors.present?
issues.issue_authors.to_h.map{|k,v| [k.downcase.to_s, v] }.to_h
end

def pull_request_authors
return {} unless issues.present?
return {} unless issues.pull_request_authors.present?
issues.pull_request_authors.to_h.map{|k,v| [k.downcase.to_s, v] }.to_h
end

def fetch_dependencies
return unless repository.present?
conn = Faraday.new(url: repository['manifests_url']) do |faraday|
Expand Down
35 changes: 29 additions & 6 deletions app/views/collections/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Keywords
</div>
<div class="list-group list-group-flush">
<% @collection.keywords.first(50).each do |keyword, count| %>
<% @collection.keywords.first(30).each do |keyword, count| %>
<% next if keyword.blank? %>
<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <%= 'active' if keyword == params[:keyword]%>" href="<%= collection_path(@collection, keyword: keyword) %>">
<%= keyword %>
Expand All @@ -33,7 +33,7 @@
Languages
</div>
<div class="list-group list-group-flush">
<% @collection.languages.first(50).each do |keyword, count| %>
<% @collection.languages.first(30).each do |keyword, count| %>
<% next if keyword.blank? %>
<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <%= 'active' if keyword == params[:language]%>" href="<%= collection_path(@collection, language: keyword) %>">
<%= keyword %>
Expand All @@ -43,12 +43,31 @@
</div>
</div>

<div class='card mb-3'>
<div class="card-header">
Most Issues and Pull Requests
</div>
<div class="list-group list-group-flush">
<% @collection.contributors.first(30).each do |login, count| %>
<% next if login.blank? %>

<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <%= 'active' if login == params[:contributor]%>" href="<%= collection_path(@collection, contributor: login) %>">
<span>
<img class="float-start me-2" src="https://github.com/<%= login %>.png" alt="<%= login %>" width='20' onerror="this.style.display='none'">
<%= login %>
</span>
<span class="badge bg-primary rounded-pill" href='https://github.com/<%= login %>' target='_blank'><%= number_with_delimiter count%></span>
</a>
<% end %>
</div>
</div>

<div class='card mb-3'>
<div class="card-header">
Committers
</div>
<div class="list-group list-group-flush">
<% @collection.committers.first(50).each do |keyword, count| %>
<% @collection.committers.first(30).each do |keyword, count| %>
<% next if keyword.blank? %>
<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <%= 'active' if keyword == params[:committer]%>" href="<%= collection_path(@collection, committer: keyword) %>">
<%= keyword %>
Expand All @@ -63,7 +82,7 @@
Most Commits
</div>
<div class="list-group list-group-flush">
<% @collection.commits.first(50).each do |keyword, count| %>
<% @collection.commits.first(30).each do |keyword, count| %>
<% next if keyword.blank? %>
<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <%= 'active' if keyword == params[:committer]%>" href="<%= collection_path(@collection, committer: keyword) %>">
<%= keyword %>
Expand All @@ -78,7 +97,7 @@
Direct Dependencies
</div>
<div class="list-group list-group-flush">
<% @collection.dependencies.first(50).each do |keyword, count| %>
<% @collection.dependencies.first(30).each do |keyword, count| %>
<% next if keyword.blank? %>
<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <%= 'active' if keyword.join(':') == params[:dependency]%>" href="<%= collection_path(@collection, dependency: keyword.join(':')) %>">
<%= keyword.join ':' %>
Expand All @@ -96,7 +115,11 @@
<% @collection.owners.first(50).each do |owner, count| %>
<% next if owner.blank? %>
<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <%= 'active' if owner == params[:owner]%>" href="<%= collection_path(@collection, owner: owner) %>">
<%= owner %>
<span>
<img class="float-start me-2" src="https://github.com/<%= owner %>.png" alt="<%= owner %>" width='20' onerror="this.style.display='none'">
<%= owner %>
</span>

<span class="badge bg-primary rounded-pill" href='https://github.com/<%= owner %>' target='_blank'><%= number_with_delimiter count%></span>
</a>
<% end %>
Expand Down

0 comments on commit 440c8d3

Please sign in to comment.