forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConventionalCommitMessageBuilder.cs
More file actions
113 lines (94 loc) · 3.19 KB
/
Copy pathConventionalCommitMessageBuilder.cs
File metadata and controls
113 lines (94 loc) · 3.19 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
{
public class ConventionalCommitMessageBuilder : ObservableValidator
{
[Required(ErrorMessage = "Type of changes can not be null")]
public Models.ConventionalCommitType Type
{
get => _type;
set => SetProperty(ref _type, value, true);
}
public string Scope
{
get => _scope;
set => SetProperty(ref _scope, value);
}
[Required(ErrorMessage = "Short description can not be empty")]
public string Description
{
get => _description;
set => SetProperty(ref _description, value, true);
}
public string Detail
{
get => _detail;
set => SetProperty(ref _detail, value);
}
public string BreakingChanges
{
get => _breakingChanges;
set => SetProperty(ref _breakingChanges, value);
}
public string ClosedIssue
{
get => _closedIssue;
set => SetProperty(ref _closedIssue, value);
}
public ConventionalCommitMessageBuilder(Action<string> onApply)
{
_onApply = onApply;
}
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode")]
public bool Apply()
{
if (HasErrors)
return false;
ValidateAllProperties();
if (HasErrors)
return false;
var builder = new StringBuilder();
builder.Append(_type.Type);
if (!string.IsNullOrEmpty(_scope))
{
builder.Append("(");
builder.Append(_scope);
builder.Append(")");
}
if (!string.IsNullOrEmpty(_breakingChanges))
builder.Append("!");
builder.Append(": ");
builder.Append(_description);
builder.AppendLine().AppendLine();
if (!string.IsNullOrEmpty(_detail))
{
builder.Append(_detail);
builder.AppendLine().AppendLine();
}
if (!string.IsNullOrEmpty(_breakingChanges))
{
builder.Append("BREAKING CHANGE: ");
builder.Append(_breakingChanges);
builder.AppendLine().AppendLine();
}
if (!string.IsNullOrEmpty(_closedIssue))
{
builder.Append("Closed ");
builder.Append(_closedIssue);
}
_onApply?.Invoke(builder.ToString());
return true;
}
private Action<string> _onApply = null;
private Models.ConventionalCommitType _type = Models.ConventionalCommitType.Supported[0];
private string _scope = string.Empty;
private string _description = string.Empty;
private string _detail = string.Empty;
private string _breakingChanges = string.Empty;
private string _closedIssue = string.Empty;
}
}