Commit 3c983312 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'repository-contributors-group-by-email' into 'master'

Group repository contributors by email

See merge request gitlab-org/gitlab!26899
parents 53a9b4cc 6325eb6a
......@@ -66,12 +66,12 @@ export default {
individualChartsData() {
const maxNumberOfIndividualContributorsCharts = 100;
return Object.keys(this.parsedData.byAuthor)
.map(name => {
const author = this.parsedData.byAuthor[name];
return Object.keys(this.parsedData.byAuthorEmail)
.map(email => {
const author = this.parsedData.byAuthorEmail[email];
return {
name,
email: author.email,
name: author.name,
email,
commits: author.commits,
dates: [
{
......
export const showChart = state => Boolean(!state.loading && state.chartData);
export const parsedData = state => {
const byAuthor = {};
const byAuthorEmail = {};
const total = {};
state.chartData.forEach(({ date, author_name, author_email }) => {
total[date] = total[date] ? total[date] + 1 : 1;
const authorData = byAuthor[author_name];
const authorData = byAuthorEmail[author_email];
if (!authorData) {
byAuthor[author_name] = {
email: author_email.toLowerCase(),
byAuthorEmail[author_email] = {
name: author_name,
commits: 1,
dates: {
[date]: 1,
......@@ -25,7 +25,7 @@ export const parsedData = state => {
return {
total,
byAuthor,
byAuthorEmail,
};
};
......
---
title: Group repository contributors by email instead of name
merge_request: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/26899
author: Hilco van der Wilk
type: changed
......@@ -29,33 +29,39 @@ describe('Contributors Store Getters', () => {
beforeAll(() => {
state.chartData = [
{ author_name: 'John Smith', author_email: 'jawnnypoo@gmail.com', date: '2019-05-05' },
{ author_name: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-05-05' },
{ author_name: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-05-05' },
{ author_name: 'Carlson', author_email: 'jawnnypoo@gmail.com', date: '2019-03-03' },
{ author_name: 'Carlson', author_email: 'jawnnypoo@gmail.com', date: '2019-05-05' },
{ author_name: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-04-04' },
{ author_name: 'Carlson', author_email: 'carlson123@gitlab.com', date: '2019-03-03' },
{ author_name: 'Carlson', author_email: 'carlson123@gmail.com', date: '2019-05-05' },
{ author_name: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-04-04' },
{ author_name: 'Johan', author_email: 'jawnnypoo@gmail.com', date: '2019-04-04' },
{ author_name: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-03-03' },
];
parsed = getters.parsedData(state);
});
it('should group contributions by date ', () => {
it('should group contributions by date', () => {
expect(parsed.total).toMatchObject({ '2019-05-05': 3, '2019-03-03': 2, '2019-04-04': 2 });
});
it('should group contributions by author ', () => {
expect(parsed.byAuthor).toMatchObject({
Carlson: {
email: 'jawnnypoo@gmail.com',
commits: 2,
it('should group contributions by email and use most recent name', () => {
expect(parsed.byAuthorEmail).toMatchObject({
'carlson123@gmail.com': {
name: 'Carlson',
commits: 1,
dates: {
'2019-03-03': 1,
'2019-05-05': 1,
},
},
John: {
email: 'jawnnypoo@gmail.com',
'carlson123@gitlab.com': {
name: 'Carlson',
commits: 1,
dates: {
'2019-03-03': 1,
},
},
'jawnnypoo@gmail.com': {
name: 'John Smith',
commits: 5,
dates: {
'2019-03-03': 1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment