Skip to content

Commit

Permalink
Add 'Until' column to contributors index
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuay03 committed Aug 24, 2024
1 parent bc321ae commit 5df299d
Show file tree
Hide file tree
Showing 22 changed files with 127 additions and 327 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/screen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ TABLES GENERALS
font-size: 1.1em;
}

#table-wrap table td.contributor-since {
#table-wrap table td.contributor-timestamp {
white-space: nowrap;
text-align: left;
}
Expand Down
21 changes: 19 additions & 2 deletions app/models/contributor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def self._all_with_ncommits(joins, where=nil)
order('ncommits DESC, contributors.url_id ASC')
end

def self.set_first_contribution_timestamps(only_new)
scope = only_new ? 'first_contribution_at IS NULL' : '1 = 1'
def self.set_first_contribution_timestamps(only_missing)
scope = only_missing ? 'first_contribution_at IS NULL' : '1 = 1'

connection.execute(<<-SQL)
UPDATE contributors
Expand All @@ -56,6 +56,23 @@ def self.set_first_contribution_timestamps(only_new)
SQL
end

def self.set_last_contribution_timestamps(only_missing)
scope = only_missing ? 'last_contribution_at IS NULL' : '1 = 1'

connection.execute(<<-SQL)
UPDATE contributors
SET last_contribution_at = last_contributions.committer_date
FROM (
SELECT contributor_id, MAX(commits.committer_date) AS committer_date
FROM contributions
INNER JOIN commits ON commits.id = commit_id
GROUP BY contributor_id
) AS last_contributions
WHERE id = last_contributions.contributor_id
AND #{scope}
SQL
end

# The contributors table may change if new name equivalences are added and IDs
# in particular are expected to move. So, we just put the parameterized name
# in URLs, which is unique anyway.
Expand Down
5 changes: 3 additions & 2 deletions app/models/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def sync
if ncommits > 0 || nreleases > 0 || rebuild_all
sync_names
sync_ranks
sync_first_contribution_timestamps
sync_contribution_timestamps
end

RepoUpdate.create!(
Expand Down Expand Up @@ -188,8 +188,9 @@ def sync_ranks
end
end

def sync_first_contribution_timestamps
def sync_contribution_timestamps
Contributor.set_first_contribution_timestamps(!rebuild_all)
Contributor.set_last_contribution_timestamps(!rebuild_all)
end

# Determines whether the names mapping has been updated. This is useful because
Expand Down
5 changes: 3 additions & 2 deletions app/views/contributors/_contributor.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<tr class="<%= cycle 'even', 'odd' %>">
<tr id="<%= contributor.name.downcase.tr(' ', '-') %>" class="<%= cycle 'even', 'odd' %>">
<td class="contributor-rank">#<%= contributor.rank %></td>
<td class="contributor-name"><%= link_to_contributor contributor %></td>
<td class="contributor-since"><%= date contributor.first_contribution_at %></td>
<td class="contributor-timestamp"><%= date contributor.first_contribution_at %></td>
<td class="contributor-timestamp"><%= date contributor.last_contribution_at %></td>
<td class="no-commits">
<% path = if @time_window
contributor_commits_in_time_window_path(contributor, @time_window)
Expand Down
1 change: 1 addition & 0 deletions app/views/contributors/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<th></th>
<th>Name</th>
<th>Since</th>
<th>Until</th>
<th>Commits</th>
</tr>
<%= render @contributors %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class AddFirstContributionAtToContributors < ActiveRecord::Migration[4.2]
def up
add_column :contributors, :first_contribution_at, :datetime
Contributor.try(:fill_missing_first_contribution_timestamps)
Contributor.set_first_contribution_timestamps
end

def down
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddLastContributionAtToContributors < ActiveRecord::Migration[7.1]
def up
add_column :contributors, :last_contribution_at, :datetime
Contributor.set_last_contribution_timestamps
end

def down
remove_column :contributors, :last_contribution_at
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2016_05_12_095609) do
ActiveRecord::Schema[7.1].define(version: 2024_08_24_030051) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -42,6 +42,7 @@
t.string "url_id", null: false
t.integer "rank"
t.datetime "first_contribution_at", precision: nil
t.datetime "last_contribution_at"
t.index ["name"], name: "index_contributors_on_name", unique: true
t.index ["url_id"], name: "index_contributors_on_url_id", unique: true
end
Expand Down
67 changes: 0 additions & 67 deletions public/404.html

This file was deleted.

66 changes: 0 additions & 66 deletions public/406-unsupported-browser.html

This file was deleted.

67 changes: 0 additions & 67 deletions public/422.html

This file was deleted.

66 changes: 0 additions & 66 deletions public/500.html

This file was deleted.

Empty file removed public/favicon.ico
Empty file.
Loading

0 comments on commit 5df299d

Please sign in to comment.