Skip to content

Commit 8daf9f8

Browse files
committed
Add 'Until' column to contributors index
1 parent bc321ae commit 8daf9f8

15 files changed

+126
-25
lines changed

app/assets/stylesheets/screen.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ TABLES GENERALS
330330
font-size: 1.1em;
331331
}
332332

333-
#table-wrap table td.contributor-since {
333+
#table-wrap table td.contributor-timestamp {
334334
white-space: nowrap;
335335
text-align: left;
336336
}

app/models/contributor.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def self._all_with_ncommits(joins, where=nil)
3939
order('ncommits DESC, contributors.url_id ASC')
4040
end
4141

42-
def self.set_first_contribution_timestamps(only_new)
43-
scope = only_new ? 'first_contribution_at IS NULL' : '1 = 1'
42+
def self.set_first_contribution_timestamps(only_missing)
43+
scope = only_missing ? 'first_contribution_at IS NULL' : '1 = 1'
4444

4545
connection.execute(<<-SQL)
4646
UPDATE contributors
@@ -56,6 +56,23 @@ def self.set_first_contribution_timestamps(only_new)
5656
SQL
5757
end
5858

59+
def self.set_last_contribution_timestamps(only_missing)
60+
scope = only_missing ? 'last_contribution_at IS NULL' : '1 = 1'
61+
62+
connection.execute(<<-SQL)
63+
UPDATE contributors
64+
SET last_contribution_at = last_contributions.committer_date
65+
FROM (
66+
SELECT contributor_id, MAX(commits.committer_date) AS committer_date
67+
FROM contributions
68+
INNER JOIN commits ON commits.id = commit_id
69+
GROUP BY contributor_id
70+
) AS last_contributions
71+
WHERE id = last_contributions.contributor_id
72+
AND #{scope}
73+
SQL
74+
end
75+
5976
# The contributors table may change if new name equivalences are added and IDs
6077
# in particular are expected to move. So, we just put the parameterized name
6178
# in URLs, which is unique anyway.

app/models/repo.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def sync
8585
if ncommits > 0 || nreleases > 0 || rebuild_all
8686
sync_names
8787
sync_ranks
88-
sync_first_contribution_timestamps
88+
sync_contribution_timestamps
8989
end
9090

9191
RepoUpdate.create!(
@@ -188,8 +188,9 @@ def sync_ranks
188188
end
189189
end
190190

191-
def sync_first_contribution_timestamps
191+
def sync_contribution_timestamps
192192
Contributor.set_first_contribution_timestamps(!rebuild_all)
193+
Contributor.set_last_contribution_timestamps(!rebuild_all)
193194
end
194195

195196
# Determines whether the names mapping has been updated. This is useful because

app/views/contributors/_contributor.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<tr class="<%= cycle 'even', 'odd' %>">
1+
<tr id="<%= contributor.name.downcase.tr(' ', '-') %>" class="<%= cycle 'even', 'odd' %>">
22
<td class="contributor-rank">#<%= contributor.rank %></td>
33
<td class="contributor-name"><%= link_to_contributor contributor %></td>
4-
<td class="contributor-since"><%= date contributor.first_contribution_at %></td>
4+
<td class="contributor-timestamp"><%= date contributor.first_contribution_at %></td>
5+
<td class="contributor-timestamp"><%= date contributor.last_contribution_at %></td>
56
<td class="no-commits">
67
<% path = if @time_window
78
contributor_commits_in_time_window_path(contributor, @time_window)

app/views/contributors/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<th></th>
1515
<th>Name</th>
1616
<th>Since</th>
17+
<th>Until</th>
1718
<th>Commits</th>
1819
</tr>
1920
<%= render @contributors %>

db/migrate/20150326181907_add_first_contribution_at_to_contributors.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class AddFirstContributionAtToContributors < ActiveRecord::Migration[4.2]
22
def up
33
add_column :contributors, :first_contribution_at, :datetime
4-
Contributor.try(:fill_missing_first_contribution_timestamps)
4+
Contributor.set_first_contribution_timestamps
55
end
66

77
def down
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class AddLastContributionAtToContributors < ActiveRecord::Migration[7.1]
2+
def up
3+
add_column :contributors, :last_contribution_at, :datetime
4+
Contributor.set_last_contribution_timestamps
5+
end
6+
7+
def down
8+
remove_column :contributors, :last_contribution_at
9+
end
10+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

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

@@ -42,6 +42,7 @@
4242
t.string "url_id", null: false
4343
t.integer "rank"
4444
t.datetime "first_contribution_at", precision: nil
45+
t.datetime "last_contribution_at"
4546
t.index ["name"], name: "index_contributors_on_name", unique: true
4647
t.index ["url_id"], name: "index_contributors_on_url_id", unique: true
4748
end

test/controllers/contributors_controller_test.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class ContributorsControllerTest < ActionController::TestCase
44
def test_index_main_listing
55
# Order by ncommits DESC, url_id ASC.
6-
expected = [[:jeremy, 3], [:david, 2], [:jose, 1], [:vijay, 1], [:xavier, 1]]
6+
expected = [[:jeremy, 3], [:david, 2], [:jose, 2], [:vijay, 1], [:xavier, 1]]
77

88
get :index
99

@@ -13,13 +13,27 @@ def test_index_main_listing
1313
assert_equal expected.size, actual.size
1414

1515
expected.zip(actual).each do |e, a|
16-
assert_equal contributors(e.first).name, a.name
16+
contributor = contributors(e.first)
17+
18+
assert_equal contributor.name, a.name
1719
assert_equal e.second, a.ncommits
20+
21+
assert_select "tr##{contributor.name.downcase.tr(' ', '-') }" do |elements|
22+
assert_select 'td.contributor-rank', "##{contributor.rank.to_s}"
23+
assert_select 'td.contributor-name', /#{contributor.name}/
24+
assert_select 'td.contributor-timestamp' do |elements|
25+
assert_equal 2, elements.size
26+
assert_equal contributor.first_contribution_at.strftime("%d %b %Y"), elements[0].text.strip
27+
assert_equal contributor.last_contribution_at.strftime("%d %b %Y"), elements[1].text.strip
28+
end
29+
assert_select "td.no-commits", e.second.to_s
30+
end
1831
end
1932
end
2033

2134
def test_index_by_release
2235
releases = {
36+
'v4.0.0' => [[:jose, 1]],
2337
'v3.2.0' => [[:jeremy, 1], [:jose, 1], [:vijay, 1]],
2438
'v0.14.4' => [[:david, 1]]
2539
}
@@ -48,11 +62,11 @@ def test_in_time_window
4862
date_range = '20121201-20121231'
4963

5064
time_windows = {
51-
'all-time' => [[:jeremy, 3], [:david, 2], [:jose, 1], [:vijay, 1], [:xavier, 1]],
65+
'all-time' => [[:jeremy, 3], [:david, 2], [:jose, 2], [:vijay, 1], [:xavier, 1]],
5266
'today' => [[:jeremy, 1]],
5367
'this-week' => [[:jeremy, 1], [:xavier, 1]],
5468
'this-month' => [[:david, 1], [:jeremy, 1], [:xavier, 1]],
55-
'this-year' => [[:jeremy, 3], [:david, 1], [:jose, 1], [:vijay, 1], [:xavier, 1]],
69+
'this-year' => [[:jeremy, 3], [:jose, 2], [:david, 1], [:vijay, 1], [:xavier, 1]],
5670
since => [[:jeremy, 1], [:xavier, 1]],
5771
date_range => [[:david, 1], [:jeremy, 1], [:xavier, 1]],
5872
}

test/controllers/releases_controller_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ def test_index
55
get :index
66
assert_response :success
77

8-
assert_select 'span.listing-total', 'Showing 5 releases'
9-
108
expected = %w(
9+
v4_0_0
1110
v3_2_0
1211
v2_3_2_1
1312
v2_3_2
@@ -24,7 +23,7 @@ def test_index
2423
assert_equal e.contributors.count, a.ncontributors
2524
end
2625

27-
assert_select 'span.listing-total', 'Showing 5 releases'
26+
assert_select 'span.listing-total', 'Showing #{expected.size} releases'
2827
assert_select 'li.current', 'Releases'
2928
end
3029
end

0 commit comments

Comments
 (0)