forked from nblockchain/conventions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wrapLatestCommitMsg.fsx
67 lines (55 loc) · 1.41 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
#!/usr/bin/env -S dotnet fsi
open System.IO
open System
open System.Text.RegularExpressions
#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 newLineIndex = commitMsg.IndexOf Environment.NewLine
if newLineIndex > 0 then
commitMsg.Substring(0, newLineIndex).Trim(),
Some(commitMsg.Substring(newLineIndex).Trim())
else
commitMsg, None
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
+ Environment.NewLine
| _ -> header
Fsdk
.Process
.Execute(
{
Command = "git"
Arguments =
$"commit --amend --message \"{EscapeDoubleQuotes newCommitMsg}\""
},
Echo.Off
)
.UnwrapDefault()
.Trim()