-
Notifications
You must be signed in to change notification settings - Fork 10
/
wrapLatestCommitMsg.fsx
executable file
·69 lines (55 loc) · 1.49 KB
/
wrapLatestCommitMsg.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env -S dotnet fsi
open System.IO
open System
open System.Text.RegularExpressions
open System.Linq
#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#load "../src/FileConventions/Library.fs"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
open Fsdk
open Fsdk.Process
let commitMsg =
Fsdk
.Process
.Execute(
{
Command = "git"
Arguments = "log -1 --format=%B"
},
Echo.Off
)
.UnwrapDefault()
.Trim()
let header, maybeBody =
let singleEolToJustSeparateLines = 1u
let lines =
FileConventions.SplitByEOLs commitMsg singleEolToJustSeparateLines
if lines.Length = 1 then
commitMsg, None
else
let body = String.Join(Environment.NewLine, lines.Skip 2)
lines.[0], Some body
let maxCharsPerLine = 64
let maybeWrappedBody =
match maybeBody with
| Some body -> Some(FileConventions.WrapText body maxCharsPerLine)
| _ -> None
let EscapeDoubleQuotes(text: string) =
Regex.Replace(text, @"([^\\])""", @"$1\""")
let newCommitMsg =
match maybeWrappedBody with
| Some wrappedBody ->
header + Environment.NewLine + Environment.NewLine + wrappedBody
| _ -> header
Fsdk
.Process
.Execute(
{
Command = "git"
Arguments =
$"commit --amend --message \"{EscapeDoubleQuotes newCommitMsg}\""
},
Echo.Off
)
.UnwrapDefault()
.Trim()