Commit 6325eb6a authored by Hilco van der Wilk's avatar Hilco van der Wilk Committed by Martin Wortschack

Group repository contributors by email

This was changed because it seemed undesirable
to split chart when user changes git name.

Issue:
https://gitlab.com/gitlab-org/gitlab/issues/196961
parent 0a06be7d
...@@ -66,12 +66,12 @@ export default { ...@@ -66,12 +66,12 @@ export default {
individualChartsData() { individualChartsData() {
const maxNumberOfIndividualContributorsCharts = 100; const maxNumberOfIndividualContributorsCharts = 100;
return Object.keys(this.parsedData.byAuthor) return Object.keys(this.parsedData.byAuthorEmail)
.map(name => { .map(email => {
const author = this.parsedData.byAuthor[name]; const author = this.parsedData.byAuthorEmail[email];
return { return {
name, name: author.name,
email: author.email, email,
commits: author.commits, commits: author.commits,
dates: [ dates: [
{ {
......
export const showChart = state => Boolean(!state.loading && state.chartData); export const showChart = state => Boolean(!state.loading && state.chartData);
export const parsedData = state => { export const parsedData = state => {
const byAuthor = {}; const byAuthorEmail = {};
const total = {}; const total = {};
state.chartData.forEach(({ date, author_name, author_email }) => { state.chartData.forEach(({ date, author_name, author_email }) => {
total[date] = total[date] ? total[date] + 1 : 1; total[date] = total[date] ? total[date] + 1 : 1;
const authorData = byAuthor[author_name]; const authorData = byAuthorEmail[author_email];
if (!authorData) { if (!authorData) {
byAuthor[author_name] = { byAuthorEmail[author_email] = {
email: author_email.toLowerCase(), name: author_name,
commits: 1, commits: 1,
dates: { dates: {
[date]: 1, [date]: 1,
...@@ -25,7 +25,7 @@ export const parsedData = state => { ...@@ -25,7 +25,7 @@ export const parsedData = state => {
return { return {
total, 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', () => { ...@@ -29,33 +29,39 @@ describe('Contributors Store Getters', () => {
beforeAll(() => { beforeAll(() => {
state.chartData = [ 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: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-05-05' }, { author_name: 'Carlson', author_email: 'carlson123@gitlab.com', date: '2019-03-03' },
{ author_name: 'Carlson', author_email: 'jawnnypoo@gmail.com', date: '2019-03-03' }, { author_name: 'Carlson', author_email: 'carlson123@gmail.com', date: '2019-05-05' },
{ 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: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-04-04' }, { 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' }, { author_name: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-03-03' },
]; ];
parsed = getters.parsedData(state); 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 }); expect(parsed.total).toMatchObject({ '2019-05-05': 3, '2019-03-03': 2, '2019-04-04': 2 });
}); });
it('should group contributions by author ', () => { it('should group contributions by email and use most recent name', () => {
expect(parsed.byAuthor).toMatchObject({ expect(parsed.byAuthorEmail).toMatchObject({
Carlson: { 'carlson123@gmail.com': {
email: 'jawnnypoo@gmail.com', name: 'Carlson',
commits: 2, commits: 1,
dates: { dates: {
'2019-03-03': 1,
'2019-05-05': 1, '2019-05-05': 1,
}, },
}, },
John: { 'carlson123@gitlab.com': {
email: 'jawnnypoo@gmail.com', name: 'Carlson',
commits: 1,
dates: {
'2019-03-03': 1,
},
},
'jawnnypoo@gmail.com': {
name: 'John Smith',
commits: 5, commits: 5,
dates: { dates: {
'2019-03-03': 1, '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