Skip to content

Commit

Permalink
fix: remove slash from line end and add more logging around git commi…
Browse files Browse the repository at this point in the history
…t dates
  • Loading branch information
darraghoriordan committed Oct 2, 2023
1 parent 54cad69 commit 404e192
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/app/MarketingWeek/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
startOfMonth,
startOfWeek,
endOfWeek,
endOfDay,
} from 'date-fns'
import { useGitActivityGetMonth } from './ReactQueryWrappers'
import { CalendarDaysIcon } from '@heroicons/react/24/outline'
Expand Down Expand Up @@ -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<HTMLDivElement | null>(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class GitActivityForMonthChannelSub
// return the list of entries

await validateSettingsForTool()

const analysis = await gitActivityForMonth(
request.startDate,
request.endDate,
Expand Down
44 changes: 29 additions & 15 deletions src/electron/marketingWeek/services/month-analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
endOfDay,
isFuture,
isSameDay,
isToday,
startOfDay,
} from 'date-fns'
import { GitConfigsService } from '../../gitConfigurations/services/GitConfigsService'
Expand All @@ -15,12 +16,16 @@ export async function gitActivityForMonth(
endDate: Date,
): Promise<Map<number, boolean>> {
// 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<number, boolean>()
Expand All @@ -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)
}
}
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
[email protected]:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==
Expand Down

0 comments on commit 404e192

Please sign in to comment.