-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommitMsgHook.cs
42 lines (32 loc) · 1.3 KB
/
CommitMsgHook.cs
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
using GitHooksCsharp.Commit.Message;
namespace GitHooksCsharp.Hooks.CommitMsg;
/// <summary>
/// Represents the commit message hook.
/// </summary>
public static class CommitMsgHook
{
/// <summary>
/// Gets the list of tasks to be executed by the hook.
/// </summary>
public static List<BaseHookTask> Tasks { get; } = [];
/// <summary>
/// Executes the commit message hook.
/// </summary>
public static void Execute()
{
Configuration.Synchronize();
string commitMsgFilepath = Environment.GetCommandLineArgs()[2];
string[] commitMsg = File.ReadAllLines(commitMsgFilepath).Where(x => !x.StartsWith('#')).ToArray();
HookLogger hookLogger = new(HookTypes.CommitMsg);
hookLogger.StartHook();
CommitMessage commitMessage = new(commitMsg);
Tasks.Add(new CheckSubjectTask(hookLogger, commitMessage));
Tasks.Add(new CheckBodyTask(hookLogger, commitMessage));
Tasks.Add(new CheckBlankLinesTask(hookLogger, commitMessage));
Tasks.Add(new CheckFooterTask(hookLogger, commitMessage));
Tasks.ForEach(t => t.Execute());
bool hookPassed = Tasks.TrueForAll(t => t.Success);
hookLogger.FinishHook(hookPassed);
Environment.Exit(hookPassed ? 0 : 1);
}
}