Skip to content

Commit d95ef71

Browse files
authored
on the contributors page, only lists the closed PRs and the last date (#281)
* on the contributors page, only lists the closed PRs and the last date * test fix * test fix
1 parent 0d06e93 commit d95ef71

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

application/contributors-list.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default class ContributorsList extends React.Component {
6464
<td>
6565
<ul>
6666
{st.substantiveContributors[i].prs.map((pr) => {
67-
return <li key={pr}><a href={`https://github.com/${st.owner}/${st.shortName}/pull/${pr}`}>PR #{pr}</a></li>
67+
return <li key={pr.num}><a href={`https://github.com/${st.owner}/${st.shortName}/pull/${pr.num}`}>PR #{pr.num}</a> (closed on {pr.lastUpdated})</li>
6868
})}
6969
</ul>
7070
</td>

server.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -690,23 +690,25 @@ router.get("/api/repos/:owner/:shortName/contributors", function (req, res) {
690690
if (err) return error(res, err);
691691
const substantiveContributors = {};
692692
const nonSubstantiveContributors = {};
693-
docs.forEach(function (doc) {
694-
if (doc.markedAsNonSubstantiveBy) {
695-
for (const contributor of doc.contributors) {
696-
if (!nonSubstantiveContributors[contributor]) {
697-
nonSubstantiveContributors[contributor] = { name: contributor, prs: []};
693+
docs
694+
.filter(doc => doc.status === "closed")
695+
.forEach(function (doc) {
696+
if (doc.markedAsNonSubstantiveBy) {
697+
for (const contributor of doc.contributors) {
698+
if (!nonSubstantiveContributors[contributor]) {
699+
nonSubstantiveContributors[contributor] = { name: contributor, prs: []};
700+
}
701+
nonSubstantiveContributors[contributor].prs.push({num: doc.num, lastUpdated: new Date(...doc.lastUpdated).toDateString()});
698702
}
699-
nonSubstantiveContributors[contributor].prs.push(doc.num);
700-
}
701-
} else {
702-
for (const affiliationId in doc.affiliations) {
703-
if (!substantiveContributors[affiliationId]) {
704-
substantiveContributors[affiliationId] = { name: doc.affiliations[affiliationId], prs: []};
703+
} else {
704+
for (const affiliationId in doc.affiliations) {
705+
if (!substantiveContributors[affiliationId]) {
706+
substantiveContributors[affiliationId] = { name: doc.affiliations[affiliationId], prs: []};
707+
}
708+
substantiveContributors[affiliationId].prs.push({num: doc.num, lastUpdated: new Date(...doc.lastUpdated).toDateString()});
705709
}
706-
substantiveContributors[affiliationId].prs.push(doc.num);
707710
}
708-
}
709-
});
711+
});
710712
res.json({substantiveContributors, nonSubstantiveContributors});
711713
});
712714
});

test/server-spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ describe('Server starts and responds with no login', function () {
408408
"shortName": "existingrepo",
409409
"owner": "acme",
410410
"num": "42",
411-
"status": "opened",
411+
"status": "closed",
412412
"contributors": [
413413
"--ghtest"
414414
],
@@ -421,7 +421,7 @@ describe('Server starts and responds with no login', function () {
421421
"shortName": "existingrepo",
422422
"owner": "acme",
423423
"num": "43",
424-
"status": "opened",
424+
"status": "closed",
425425
"contributors": [
426426
"--ghtest"
427427
],
@@ -442,15 +442,17 @@ describe('Server starts and responds with no login', function () {
442442
});
443443
});
444444

445-
it('responds with an empty list of contributors', function testProtectedPOSTRoutes(done) {
445+
it('responds with an empty list of contributors', function testContributorsList(done) {
446446
req
447447
.get('/api/repos/acme/newrepo/contributors')
448448
.expect(200, {substantiveContributors: {}, nonSubstantiveContributors:{}}, done);
449449
});
450-
it('responds with the list of contributors', function testProtectedPOSTRoutes(done) {
450+
it('responds with the list of contributors', function testContributorsList(done) {
451+
const currentDate = new Date();
452+
currentDate.setMonth(currentDate.getMonth() + 1); // to match couchNow in store.js
451453
req
452454
.get('/api/repos/acme/existingrepo/contributors')
453-
.expect(200, {substantiveContributors: {"456": {"name": "ACME Inc", "prs": ["42"]}}, nonSubstantiveContributors:{"--ghtest": {"name": "--ghtest", "prs": ["43"]}}}, done);
455+
.expect(200, {substantiveContributors: {"456": {"name": "ACME Inc", "prs": [{"num":"42", "lastUpdated": currentDate.toDateString()}]}}, nonSubstantiveContributors:{"--ghtest": {"name": "--ghtest", "prs": [{"num":"43", "lastUpdated": currentDate.toDateString()}]}}}, done);
454456
});
455457
});
456458
});

0 commit comments

Comments
 (0)