Skip to content

Commit

Permalink
fixup! fix: comments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Nov 21, 2024
1 parent 0bb9efd commit 28e050f
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 77 deletions.
2 changes: 1 addition & 1 deletion libs/nes/init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@herodevs/core-types": "^0.0.1",
"@herodevs/utility": "^0.0.1",
"@inquirer/prompts": "^5.0.2",
"ora": "^5.3.0".
"ora": "^5.3.0",
"tslib": "^2.3.0",
"yargs": "^17.2.1"
},
Expand Down
2 changes: 1 addition & 1 deletion libs/nes/init/src/lib/get-product-choices.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('getProductChoices', () => {

getReleaseTrainsMock.mockResolvedValue(mockTrains);

const result = await getProductChoices(accessToken, types);
const result = await getProductChoices(accessToken);
expect(result[0].name).toEqual('a');
expect(result[1].name).toEqual('b');
});
Expand Down
6 changes: 1 addition & 5 deletions libs/nes/init/src/lib/get-product-choices.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { ProjectType } from '@herodevs/core-types';
import { sortByName } from '@herodevs/utility';
import { Choice, ReleaseTrain } from './models';
import { getReleaseTrains } from './get-release-trains';

export async function getProductChoices(
accessToken: string,
types: ProjectType[]
): Promise<Choice<ReleaseTrain[]>[]> {
export async function getProductChoices(accessToken: string): Promise<Choice<ReleaseTrain[]>[]> {
const releaseTrains = await getReleaseTrains(accessToken);

const products = releaseTrains.reduce((acc, rt) => {
Expand Down
4 changes: 1 addition & 3 deletions libs/nes/init/src/lib/get-release-trains.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ApolloClient, gql, InMemoryCache } from '@apollo/client/core';
import { ReleaseTrain } from './models';

export async function getReleaseTrains(
accessToken: string
): Promise<ReleaseTrain[]> {
export async function getReleaseTrains(accessToken: string): Promise<ReleaseTrain[]> {
const client = new ApolloClient({
cache: new InMemoryCache(),
uri: 'https://api.nes.herodevs.com/graphql',
Expand Down
2 changes: 1 addition & 1 deletion libs/nes/init/src/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function run(args: ArgumentsCamelCase<Options>): Promise<void> {
});

spinner.start('loading your products');
const productList = await getProductChoices(accessToken, projectType.types);
const productList = await getProductChoices(accessToken);
spinner.stop();

const releaseTrains =
Expand Down
90 changes: 45 additions & 45 deletions libs/report/committers/src/lib/committer-counts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,66 @@ import { getLastCommitDatePerUser } from './get-committer-counts';
import { type Commit } from './types';

describe('getLastCommitDatePerUser', () => {
test('returns the latest commit date for each committer', () => {
const commits: Commit[] = [
{ commitHash: 'abc123', committer: 'Marco', date: new Date('2024-11-20T12:00:00.000Z') },
{ commitHash: 'def456', committer: 'Greg', date: new Date('2024-11-19T12:00:00.000Z') },
{ commitHash: 'ghi789', committer: 'Marco', date: new Date('2024-11-21T12:00:00.000Z') },
];
test('returns the latest commit date for each committer', () => {
const commits: Commit[] = [
{ commitHash: 'abc123', committer: 'Marco', date: new Date('2024-11-20T12:00:00.000Z') },
{ commitHash: 'def456', committer: 'Greg', date: new Date('2024-11-19T12:00:00.000Z') },
{ commitHash: 'ghi789', committer: 'Marco', date: new Date('2024-11-21T12:00:00.000Z') },
];

const result = getLastCommitDatePerUser(commits);
expect(result).toMatchObject({
Greg: '11/19/2024, 12:00:00 PM',
Marco: '11/21/2024, 12:00:00 PM',
});
const result = getLastCommitDatePerUser(commits);
expect(result).toMatchObject({
Greg: '11/19/2024, 12:00:00 PM',
Marco: '11/21/2024, 12:00:00 PM',
});
});

test('handles a single committer with multiple commits', () => {
const commits = [
{ commitHash: 'abc123', committer: 'Marco', date: new Date('2024-11-20T12:00:00.000Z') },
{ commitHash: 'def456', committer: 'Marco', date: new Date('2024-11-21T12:00:00.000Z') },
{ commitHash: 'ghi789', committer: 'Marco', date: new Date('2024-11-19T12:00:00.000Z') },
];
test('handles a single committer with multiple commits', () => {
const commits = [
{ commitHash: 'abc123', committer: 'Marco', date: new Date('2024-11-20T12:00:00.000Z') },
{ commitHash: 'def456', committer: 'Marco', date: new Date('2024-11-21T12:00:00.000Z') },
{ commitHash: 'ghi789', committer: 'Marco', date: new Date('2024-11-19T12:00:00.000Z') },
];

const result = getLastCommitDatePerUser(commits);
const result = getLastCommitDatePerUser(commits);

expect(result).toMatchObject({
Marco: '11/21/2024, 12:00:00 PM',
});
expect(result).toMatchObject({
Marco: '11/21/2024, 12:00:00 PM',
});
});

test('returns an empty object when there are no commits', () => {
const commits: Commit[] = [];
test('returns an empty object when there are no commits', () => {
const commits: Commit[] = [];

const result = getLastCommitDatePerUser(commits);
const result = getLastCommitDatePerUser(commits);

expect(result).toEqual({});
});
expect(result).toEqual({});
});

test('handles multiple committers with no overlap', () => {
const commits = [
{ commitHash: 'abc123', committer: 'Marco', date: new Date('2024-11-20T12:00:00.000Z') },
{ commitHash: 'def456', committer: 'Greg', date: new Date('2024-11-19T12:00:00.000Z') },
];
test('handles multiple committers with no overlap', () => {
const commits = [
{ commitHash: 'abc123', committer: 'Marco', date: new Date('2024-11-20T12:00:00.000Z') },
{ commitHash: 'def456', committer: 'Greg', date: new Date('2024-11-19T12:00:00.000Z') },
];

const result = getLastCommitDatePerUser(commits);
const result = getLastCommitDatePerUser(commits);

expect(result).toMatchObject({
Marco: '11/20/2024, 12:00:00 PM',
Greg: '11/19/2024, 12:00:00 PM',
});
expect(result).toMatchObject({
Marco: '11/20/2024, 12:00:00 PM',
Greg: '11/19/2024, 12:00:00 PM',
});
});

test('ignores commits with invalid dates', () => {
const commits = [
{ commitHash: 'abc123', committer: 'Marco', date: new Date('Invalid date') },
{ commitHash: 'def456', committer: 'Marco', date: new Date('2024-11-21T12:00:00.000Z') },
];
test('ignores commits with invalid dates', () => {
const commits = [
{ commitHash: 'abc123', committer: 'Marco', date: new Date('Invalid date') },
{ commitHash: 'def456', committer: 'Marco', date: new Date('2024-11-21T12:00:00.000Z') },
];

const result = getLastCommitDatePerUser(commits);
const result = getLastCommitDatePerUser(commits);

expect(result).toEqual({
Marco: '11/21/2024, 12:00:00 PM',
});
expect(result).toEqual({
Marco: '11/21/2024, 12:00:00 PM',
});
});
});
5 changes: 2 additions & 3 deletions libs/report/committers/src/lib/committers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('reportCommittersCommand', () => {
]);

// eslint-disable-next-line @typescript-eslint/no-empty-function
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
const consoleTableSpy = jest.spyOn(console, 'table').mockImplementation(() => {});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
await reportCommittersCommand.handler(args as any);
Expand All @@ -125,8 +125,7 @@ describe('reportCommittersCommand', () => {
},
]);

// Since we use console.table console is only called once
expect(consoleLogSpy).toHaveBeenCalledTimes(1);
expect(consoleTableSpy).toHaveBeenCalledTimes(1);
});
});
});
8 changes: 7 additions & 1 deletion libs/report/committers/src/lib/committers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ async function run(args: ArgumentsCamelCase<Options>): Promise<void> {
}

function outputCommitters(committerCounts: CommitterCount[]) {
console.table(committerCounts.map((c) => ({ Committer: c.name, Commits: c.count, 'Last Commit': c.lastCommit })));
console.table(
committerCounts.map((c) => ({
Committer: c.name,
Commits: c.count,
'Last Commit Date': c.lastCommitDate,
}))
);
}

function outputCommittersJson(committerCounts: CommitterCount[]) {
Expand Down
32 changes: 16 additions & 16 deletions libs/report/committers/src/lib/get-committer-counts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ import { type Commit, type CommitterCount, type CommitterLastCommitDate } from '

export function getCommitterCounts(entries: Commit[]): CommitterCount[] {
const lastCommits = getLastCommitDatePerUser(entries);
return entries
.reduce((acc, entry) => {
let committerCount = acc.find((c) => c.name === entry.committer);
if (!committerCount) {
committerCount = { name: entry.committer, count: 0, lastCommit: lastCommits[entry.committer] ?? ''};
acc.push(committerCount);
}
committerCount.count++;
return acc;
}, [] as CommitterCount[])
.sort((a, b) => b.count - a.count);
const counts = new Map<string, CommitterCount>();

for (const { committer } of entries) {
if (!counts.has(committer)) {
counts.set(committer, {
name: committer,
count: 0,
lastCommitDate: lastCommits[committer] ?? '',
});
}
counts.get(committer)!.count++;
}

return Array.from(counts.values()).sort((a, b) => b.count - a.count);
}

export function getLastCommitDatePerUser(entries: Commit[]): CommitterLastCommitDate {
const lastCommitDates: CommitterLastCommitDate = {};

for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
const { committer, date } = entry;

for (const { committer, date } of entries) {
if (Number.isNaN(date.getTime())) continue;

const currentTimestamp = date.getTime();

if (!lastCommitDates[committer] || currentTimestamp > new Date(lastCommitDates[committer]).getTime()) {
if (!lastCommitDates[committer] || currentTimestamp > Date.parse(lastCommitDates[committer])) {
lastCommitDates[committer] = date.toLocaleString('en-US', { timeZone: 'UTC' });
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/report/committers/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type CommitterCommits = { name: string; commits: string[] };
export type CommitterCount = {
name: string;
count: number;
lastCommit: string;
lastCommitDate: string;
};

export type MonthlyData = {
Expand Down

0 comments on commit 28e050f

Please sign in to comment.