Created
December 9, 2015 22:21
-
-
Save vgaltes/52cbc80a81d4d3645659 to your computer and use it in GitHub Desktop.
Gitlog parse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "../packages/FSharp.Data.2.2.5/lib/net40/FSharp.Data.dll" | |
open VGA.CodeMaatSharp | |
open System | |
open System.IO | |
open FSharp.Data | |
// Define your library scripting code here | |
// git log --pretty=format:'[%h],%aN,%ad,%s' --date=short --numstat > pollz.log | |
[<Literal>] | |
let lineBreak = "\r\n" | |
type CommitInfo = {Hash : string; Author : string; TimeStamp : DateTime; Message : string} | |
type CommitedFile = {LinesAdded: int option; LinesDeleted: int option; FileName: string} | |
type Commit = {CommitInfo: CommitInfo; Files: CommitedFile[]} | |
let filePath =Path.Combine(__SOURCE_DIRECTORY__, "..\..\Data\sfa-log2.log") | |
let file = File.ReadAllText(filePath) | |
type CommitInfoCsv = CsvProvider<"Hash,Author,Date,Message", HasHeaders = false, Schema = "Hash,Author,Date(date),Message"> | |
type CommitLineCsv = CsvProvider<"LinesAdded\tLinesDeleted\tFile", HasHeaders = false, Schema = "LinesAdded(int option),LinesDeleted(int option),FileName"> | |
let commits = file.Split([|lineBreak + lineBreak|], StringSplitOptions.RemoveEmptyEntries) | |
let extractCommitInfo (commit:string) = | |
let isCommitInfoLine (line: string) = | |
line.StartsWith("[") | |
let extractCommitedFilesInfo c = | |
let commitFileLine = CommitLineCsv.Parse(c).Rows |> Seq.head | |
{LinesAdded = commitFileLine.LinesAdded; LinesDeleted = commitFileLine.LinesDeleted; FileName = commitFileLine.FileName} | |
let commitLines = commit.Split([|lineBreak|], StringSplitOptions.RemoveEmptyEntries) | |
let commitInfoLine = commitLines |> Array.takeWhile(isCommitInfoLine) |> Array.last | |
let infoRow = CommitInfoCsv.Parse(commitInfoLine).Rows |> Seq.head | |
let commitInfo = {Hash = infoRow.Hash; Author = infoRow.Author; TimeStamp = infoRow.Date; Message = infoRow.Message} | |
let fileRows = commitLines |> Array.skipWhile(isCommitInfoLine) | |
{CommitInfo = commitInfo; Files = fileRows |> Array.map(fun c -> extractCommitedFilesInfo c )} | |
let totalCommits = | |
commits | |
|> Array.map(fun c -> extractCommitInfo c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment