forked from tarsgate/conventions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapLatestCommitMsg.fsx
More file actions
executable file
·59 lines (45 loc) · 1.37 KB
/
Copy pathwrapLatestCommitMsg.fsx
File metadata and controls
executable file
·59 lines (45 loc) · 1.37 KB
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
#!/usr/bin/env -S dotnet fsi
open System
open System.IO
open System.Linq
open System.Text.RegularExpressions
#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: YamlDotNet, Version=16.1.3"
#load "../src/FileConventions/Library.fs"
#r "nuget: Fsdk, Version=0.9.99--date20260618-1029.git-79ec1be"
open Fsdk
open Fsdk.Process
let commitMsg =
Process
.ExecDefault("git log -1 --format=%B", echo = 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
Process
.ExecDefault(
$"git commit --amend --message \"{EscapeDoubleQuotes newCommitMsg}\"",
echo = Echo.OutputOnly
)
.UnwrapDefault()
.Trim()
|> ignore<string>