Get-MsDocsAdditions.ps1


<#PSScriptInfo
 
.GUID 0c6df4be-ff4b-481f-a7eb-31637849e580
 
.VERSION 1.0
 
.AUTHOR Jan-Henrik Damaschke
 
.COMPANYNAME Visorian GmbH
 
#>


<#
 
.SYNOPSIS
  This cmdlet helps with analyzing Git changes to the Microsoft Azure Docs
  repository (https://github.com/MicrosoftDocs/azure-docs). It is based on
  Git diff and though needs git to be installed.
 
.DESCRIPTION
  This cmdlet helps with analyzing Git changes to the Microsoft Azure Docs
  repository by using Git diff. You can use it for automation or just for
  checking which articles had major changes to stay up-to-date with Azure
  documentation.
 
.EXAMPLE
  PS C:\> Get-MsDocsAdditions | ft
  Get changes from the most current commit
 
.EXAMPLE
  PS C:\> Get-MsDocsAdditions -commitOffset 50 -additionThreshold 200 | ft
  Get the additions from the last 50 commits with a delta of at least 200
  between additions and deletions.
 
.EXAMPLE
  PS C:\> Get-MsDocsAdditions -commitOffset 50 -additionThreshold 200 | select -First 1
  Get the additions from the last 50 commits with a delta of at least 200
  between additions and deletions and show the details for the first entry.
 
.EXAMPLE
  PS C:\> Get-MsDocsAdditions -commitOffset 50 -additionThreshold 200 | Where-Object Product -like "active-directory*" | ft
  Get the additions from the last 50 commits with a delta of at least 200
  between additions and deletions where product starts with "active-directory".
 
.LINK
  https://github.com/MicrosoftDocs/azure-docs
 
.LINK
  https://gist.github.com/itpropro/55e2b716262ceafb90825a19faf35261
 
.Parameter commitOffset
  How many past commits should be analyzed
 
.Parameter additionThreshold
  Only show commits with the given delta of Git additions and deletions.
  200 additions and 200 deletions would lead to an offset of 0.
 
.Parameter excludeFileOperation
  Default $true. Exclude operations like a file move (represented with => in the Git diff)
 
#>


param (
  $commitOffset = 1,
  $additionThreshold,
  $excludeFileOperation = $true
)
try { $null = git } catch { Write-Output 'Please install Git or add the Git binary to your PATH'; break }
$commits = git diff HEAD HEAD~$commitOffset --numstat | ConvertFrom-Csv -Header 'Additions', 'Deletions', 'File' -Delimiter "`t"
$commits = $commits | Where-Object { $_.File -like 'articles*' }
if ($excludeFileOperation) {
  $commits = $commits | Where-Object { ($_.Additions -ne '-') -and ($_.Deletions -ne '-') }
  $commits | ForEach-Object {
    $_.Additions = [int]$_.Additions
    $_.Deletions = [int]$_.Deletions
  }
}
else {
  $commits | ForEach-Object {
    $_.Additions = [int]$_.Additions.replace('-', '0')
    $_.Deletions = [int]$_.Deletions.replace('-', '0')
  }
}
if ($additionThreshold) {
  $commits = $commits | Where-Object {
    ($_.Additions - $_.Deletions) -gt $additionThreshold
  }
}
foreach ($commit in $commits) {
  Add-Member -InputObject $commit -Type NoteProperty -Name 'Name' -Value ($commit.file.split("/")[-1].split('.md')[0])
  Add-Member -InputObject $commit -Type NoteProperty -Name 'Product' -Value ($commit.file.split("/")[1])
  Add-Member -InputObject $commit -Type NoteProperty -Name 'Blame' -Value ('https://github.com/MicrosoftDocs/azure-docs/blame/master/{0}' -f $commit.file) 
  Add-Member -InputObject $commit -Type NoteProperty -Name 'History' -Value ('https://github.com/MicrosoftDocs/azure-docs/commits/master/{0}' -f $commit.file)
  Add-Member -InputObject $commit -Type NoteProperty -Name 'Url' -Value ('https://docs.microsoft.com/en-us/azure{0}' -f $commit.file.replace('.md', '').replace('articles', ''))
  $commit
}