Skip to content

Instantly share code, notes, and snippets.

@jobou363
Last active January 31, 2021 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jobou363/44d1947909b4db4bddde357f0dc0e04c to your computer and use it in GitHub Desktop.
Save jobou363/44d1947909b4db4bddde357f0dc0e04c to your computer and use it in GitHub Desktop.
Get log between 2 dates for a specific author and output log to CSV file.
# git get last month commit
function Get-GitCommit {
[CmdletBinding()] #<<-- This turns a regular function into an advanced function
param (
$dateString
)
if((test-path ".git") -eq $false)
{
Write-Error "Current folder is not a git remote"
Return
}
# get all remote branch
git fetch
$date = Get-Date
if($null -ne $dateString)
{
$date = Get-Date -Date $dateString
}
$previousMonth = ($date).AddMonths(-1)
# $previousMonth
$previousMonthStart = New-Object DateTime $previousMonth.Year, $previousMonth.Month, 1, 0, 0, 0
# $previousMonthStart
$daysInMonth = [DateTime]::DaysInMonth($previousMonth.Year, $previousMonth.Month)
# $daysInMonth
$previousMonthEnd = New-Object DateTime $previousMonth.Year, $previousMonth.Month, $daysInMonth, 23, 59, 59
# $previousMonthEnd
$csv = git log --all --author="jo" --after="$($previousMonthStart)" --before="$($previousMonthEnd)" --pretty="%C(reset)%ad ;%C(Cyan)%an: ;%C(reset)%s" --date=short
$branch = git branch --show-current
$project = Split-Path -Leaf (git remote get-url origin)
$temp = "c:\temp"
$csvfile = "$($temp)\$($project)_log_$($branch)_$($([Guid]::NewGuid())).csv"
$csvfile
if([string]::IsNullOrEmpty($csv))
{
Write-Warning "Current folder {$project} as no work for current year"
Return
}
out-file -InputObject $csv -FilePath $csvfile -Encoding utf8
ii "$($csvfile)"
}
# git get last month commit
function Get-AllCommitCsvFromProject {
[CmdletBinding()] #<<-- This turns a regular function into an advanced function
param (
$date
)
set-location "D:\Git\projet1"
Get-GitCommit $date
set-location "D:\Git\projet2"
Get-GitCommit $date
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment