Skip to content

Commit be77bbb

Browse files
authored
Merge pull request #1179 from kriswest/1175-push-tables-to-render-email
fix: render committer and author email links instead of estimated profile links
2 parents 2950617 + ec69ab9 commit be77bbb

File tree

4 files changed

+68
-49
lines changed

4 files changed

+68
-49
lines changed

src/types/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface CommitData {
1515
commitTs?: number;
1616
message: string;
1717
committer: string;
18+
committerEmail: string;
1819
tree?: string;
1920
parent?: string;
2021
author: string;

src/ui/utils.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import axios from 'axios';
2+
import React from 'react';
23
import {
34
SCMRepositoryMetadata,
45
GitHubRepositoryMetadata,
56
GitLabRepositoryMetadata,
7+
CommitData,
68
} from '../types/models';
79
import moment from 'moment';
810

@@ -37,8 +39,51 @@ export const getGitProvider = (url: string) => {
3739
return 'unknown';
3840
};
3941

42+
/**
43+
* Renders a block of mailto: links for author user names and email addresses found in an array of commit data.
44+
*
45+
* @param {CommitData[]} commitData The user.name to render in the link.
46+
* @return {JSX.Element} A JSX Element representing the rendered links
47+
*/
48+
export const generateAuthorLinks = (commitData: CommitData[]) => {
49+
const orderedAuthors: JSX.Element[] = [];
50+
const uniqueAuthors: Set<string> = new Set();
51+
commitData.forEach((row) => {
52+
if (!uniqueAuthors.has(row.authorEmail)) {
53+
uniqueAuthors.add(row.authorEmail);
54+
orderedAuthors.push(
55+
<div>
56+
<a href={`mailto:${row.authorEmail}`}>
57+
&quot;{row.author}&quot; &lt;{row.authorEmail}&gt;
58+
</a>
59+
</div>,
60+
);
61+
}
62+
});
63+
return <div>{orderedAuthors}</div>;
64+
};
65+
66+
/**
67+
* Renders a mailto: link for user name and email address, for use in rendering details of pushes.
68+
*
69+
* @param {string} name The user.name to render in the link.
70+
* @param {string} email The email address to render in the link.
71+
* @return {JSX.Element} An <a> tag based on the username and email address.
72+
*/
73+
export const generateEmailLink = (name: string, email: string) => {
74+
return email ? (
75+
<a href={`mailto:${email}`}>
76+
&quot;{name}&quot; &lt;{email}&gt;
77+
</a>
78+
) : (
79+
<strong>No data...</strong>
80+
);
81+
};
82+
4083
/**
4184
* Predicts a user's profile URL based on their username and the SCM provider's details.
85+
* TODO: update this to attempt to resolve a user email to a profile URL
86+
*
4287
* @param {string} username The username.
4388
* @param {string} provider The name of the SCM provider.
4489
* @param {string} hostname The hostname of the SCM provider.
@@ -56,6 +101,9 @@ export const getUserProfileUrl = (username: string, provider: string, hostname:
56101

57102
/**
58103
* Attempts to construct a link to the user's profile at an SCM provider.
104+
*
105+
* TODO: update this to attempt to resolve a user email to a profile URL
106+
*
59107
* @param {string} username The username.
60108
* @param {string} provider The name of the SCM provider.
61109
* @param {string} hostname The hostname of the SCM provider.

src/ui/views/OpenPushRequests/components/PushesTable.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Search from '../../../components/Search/Search';
1717
import Pagination from '../../../components/Pagination/Pagination';
1818
import { PushData } from '../../../../types/models';
1919
import { trimPrefixRefsHeads, trimTrailingDotGit } from '../../../../db/helper';
20-
import { getGitProvider, getUserProfileLink } from '../../../utils';
20+
import { generateAuthorLinks, generateEmailLink } from '../../../utils';
2121

2222
interface PushesTableProps {
2323
[key: string]: any;
@@ -91,8 +91,7 @@ const PushesTable: React.FC<PushesTableProps> = (props) => {
9191
<TableCell align='left'>Branch</TableCell>
9292
<TableCell align='left'>Commit SHA</TableCell>
9393
<TableCell align='left'>Committer</TableCell>
94-
<TableCell align='left'>Author</TableCell>
95-
<TableCell align='left'>Author E-mail</TableCell>
94+
<TableCell align='left'>Authors</TableCell>
9695
<TableCell align='left'>Commit Message</TableCell>
9796
<TableCell align='left'>No. of Commits</TableCell>
9897
<TableCell align='right'></TableCell>
@@ -104,8 +103,9 @@ const PushesTable: React.FC<PushesTableProps> = (props) => {
104103
const repoBranch = trimPrefixRefsHeads(row.branch);
105104
const repoUrl = row.url;
106105
const repoWebUrl = trimTrailingDotGit(repoUrl);
107-
const gitProvider = getGitProvider(repoUrl);
108-
const hostname = new URL(repoUrl).hostname;
106+
// may be used to resolve users to profile links in future
107+
// const gitProvider = getGitProvider(repoUrl);
108+
// const hostname = new URL(repoUrl).hostname;
109109
const commitTimestamp =
110110
row.commitData[0]?.commitTs || row.commitData[0]?.commitTimestamp;
111111

@@ -134,19 +134,19 @@ const PushesTable: React.FC<PushesTableProps> = (props) => {
134134
</a>
135135
</TableCell>
136136
<TableCell align='left'>
137-
{getUserProfileLink(row.commitData[0].committer, gitProvider, hostname)}
138-
</TableCell>
139-
<TableCell align='left'>
140-
{getUserProfileLink(row.commitData[0].author, gitProvider, hostname)}
137+
{/* render github/gitlab profile links in future
138+
{getUserProfileLink(row.commitData[0].committerEmail, gitProvider, hostname)}
139+
*/}
140+
{generateEmailLink(
141+
row.commitData[0].committer,
142+
row.commitData[0]?.committerEmail,
143+
)}
141144
</TableCell>
142145
<TableCell align='left'>
143-
{row.commitData[0]?.authorEmail ? (
144-
<a href={`mailto:${row.commitData[0].authorEmail}`}>
145-
{row.commitData[0].authorEmail}
146-
</a>
147-
) : (
148-
'No data...'
149-
)}
146+
{/* render github/gitlab profile links in future
147+
{getUserProfileLink(row.commitData[0].authorEmail, gitProvider, hostname)}
148+
*/}
149+
{generateAuthorLinks(row.commitData)}
150150
</TableCell>
151151
<TableCell align='left'>{row.commitData[0]?.message || 'N/A'}</TableCell>
152152
<TableCell align='left'>{row.commitData.length}</TableCell>

src/ui/views/PushDetails/PushDetails.tsx

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Snackbar from '@material-ui/core/Snackbar';
2424
import Tooltip from '@material-ui/core/Tooltip';
2525
import { PushData } from '../../../types/models';
2626
import { trimPrefixRefsHeads, trimTrailingDotGit } from '../../../db/helper';
27-
import { getGitProvider } from '../../utils';
27+
import { generateEmailLink, getGitProvider } from '../../utils';
2828

2929
const Dashboard: React.FC = () => {
3030
const { id } = useParams<{ id: string }>();
@@ -304,7 +304,6 @@ const Dashboard: React.FC = () => {
304304
<TableCell>Timestamp</TableCell>
305305
<TableCell>Committer</TableCell>
306306
<TableCell>Author</TableCell>
307-
<TableCell>Author E-mail</TableCell>
308307
<TableCell>Message</TableCell>
309308
</TableRow>
310309
</TableHead>
@@ -314,37 +313,8 @@ const Dashboard: React.FC = () => {
314313
<TableCell>
315314
{moment.unix(c.commitTs || c.commitTimestamp || 0).toString()}
316315
</TableCell>
317-
<TableCell>
318-
{isGitHub && (
319-
<a
320-
href={`https://github.com/${c.committer}`}
321-
rel='noreferrer'
322-
target='_blank'
323-
>
324-
{c.committer}
325-
</a>
326-
)}
327-
{!isGitHub && <span>{c.committer}</span>}
328-
</TableCell>
329-
<TableCell>
330-
{isGitHub && (
331-
<a
332-
href={`https://github.com/${c.author}`}
333-
rel='noreferrer'
334-
target='_blank'
335-
>
336-
{c.author}
337-
</a>
338-
)}
339-
{!isGitHub && <span>{c.author}</span>}
340-
</TableCell>
341-
<TableCell>
342-
{c.authorEmail ? (
343-
<a href={`mailto:${c.authorEmail}`}>{c.authorEmail}</a>
344-
) : (
345-
'No data...'
346-
)}
347-
</TableCell>
316+
<TableCell>{generateEmailLink(c.committer, c.committerEmail)}</TableCell>
317+
<TableCell>{generateEmailLink(c.author, c.authorEmail)}</TableCell>
348318
<TableCell>{c.message}</TableCell>
349319
</TableRow>
350320
))}

0 commit comments

Comments
 (0)