diff --git a/src/app/MarketingWeek/Calendar.tsx b/src/app/MarketingWeek/Calendar.tsx index d4c60c9..be3756c 100644 --- a/src/app/MarketingWeek/Calendar.tsx +++ b/src/app/MarketingWeek/Calendar.tsx @@ -16,6 +16,7 @@ import { startOfMonth, startOfWeek, endOfWeek, + endOfDay, } from 'date-fns' import { useGitActivityGetMonth } from './ReactQueryWrappers' import { CalendarDaysIcon } from '@heroicons/react/24/outline' @@ -107,8 +108,8 @@ export default function Calendar({ const days = getMonthCalDays(date) const { data: gitActivity, isLoading: isLoadingGitActivity } = useGitActivityGetMonth({ - startDate: days[0]?.jsDate, - endDate: days.at(-1)?.jsDate, + startDate: days.at(0)?.jsDate, + endDate: days.at(-1)?.jsDate ? endOfDay(days.at(-1)!.jsDate) : undefined, }) const container = useRef(null) diff --git a/src/electron/marketingWeek/channels/GitActivityForMonthChannelSub.ts b/src/electron/marketingWeek/channels/GitActivityForMonthChannelSub.ts index 81c479f..1704ea5 100644 --- a/src/electron/marketingWeek/channels/GitActivityForMonthChannelSub.ts +++ b/src/electron/marketingWeek/channels/GitActivityForMonthChannelSub.ts @@ -26,6 +26,7 @@ export class GitActivityForMonthChannelSub // return the list of entries await validateSettingsForTool() + const analysis = await gitActivityForMonth( request.startDate, request.endDate, diff --git a/src/electron/marketingWeek/services/month-analyser.ts b/src/electron/marketingWeek/services/month-analyser.ts index c4097ca..8e86d50 100644 --- a/src/electron/marketingWeek/services/month-analyser.ts +++ b/src/electron/marketingWeek/services/month-analyser.ts @@ -3,6 +3,7 @@ import { endOfDay, isFuture, isSameDay, + isToday, startOfDay, } from 'date-fns' import { GitConfigsService } from '../../gitConfigurations/services/GitConfigsService' @@ -15,12 +16,16 @@ export async function gitActivityForMonth( endDate: Date, ): Promise> { // get the list of dates for a month using date-fns - const dates = eachDayOfInterval({ + const dateExcludingFutureDates = eachDayOfInterval({ start: startDate, end: endDate, - }) + }).filter(d => isToday(d) || !isFuture(d)) const gitConfigs = await GitConfigsService.loadGitConfigs() - console.log(`parsing ${gitConfigs.configList.length} git directories`) + console.log( + `parsing ${ + gitConfigs.configList.length + } git directories ${startDate.toISOString()} to ${endDate.toISOString()}`, + ) const hasCommitForDateMap = (await getFromCache(startDate.getTime(), endDate.getTime())) || new Map() @@ -32,23 +37,32 @@ export async function gitActivityForMonth( ) break } - // otherwise get the commits for this repo - const commits = await readSingleGitRepoHistory({ + const readOptions = { gitRepoPath: removeGitConfig(gitConfig.path), startDate: startOfDay(startDate), endDate: endOfDay(endDate), - }) + } + // otherwise get the commits for this repo + console.log(`reading git history for ${readOptions.gitRepoPath}`) + const commits = await readSingleGitRepoHistory(readOptions) + console.log( + `found ${commits.length} commits for ${ + readOptions.gitRepoPath + }. ${commits.map(c => c.date.toISOString())})}`, + ) // and for each date that is not true, check if there is a commit on that day - for (const date of dates) { - // skip any dates in the future, we don't want to cache or check those - if (isFuture(date)) { - continue - } + for (const date of dateExcludingFutureDates) { + console.log( + `checking if there is a commit for ${ + readOptions.gitRepoPath + } for ${date.toISOString()}`, + ) if (!hasCommitForDateMap.get(date.getTime())) { - hasCommitForDateMap.set( - date.getTime(), - commits.some(c => isSameDay(c.date, date)), + const hasCommit = commits.some(c => isSameDay(c.date, date)) + console.log( + `No EXISTING commit found for ${date.toISOString()}. Setting to ${hasCommit}`, ) + hasCommitForDateMap.set(date.getTime(), hasCommit) } } } @@ -63,7 +77,7 @@ export function removeGitConfig(filePath: string) { if (targetPath.endsWith(gitConfigPath)) { // Remove ".git/config" from the end of the path - return targetPath.slice(0, -gitConfigPath.length) + return targetPath.slice(0, -(gitConfigPath.length + 1)) } else { return targetPath } diff --git a/yarn.lock b/yarn.lock index e64fb1b..7f7f3f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3838,7 +3838,7 @@ create-require@^1.1.0: resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== -cross-env@^7.0.3: +cross-env@7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==