-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sync.pas
241 lines (200 loc) · 8.77 KB
/
Sync.pas
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
namespace SwiftEvolutionSync;
const SWIFT_PROPOSALS = "/Users/mh/Code/_Others/swift-evolution/proposals"; // folder with propoals
const ELEMENTS_DOCS = "/Users/mh/Code/RemObjects/ElementsDocs/";
const LEGACY = ELEMENTS_DOCS+"Silver/__SwiftEvolution_Legacy.md"; // old MD file, for one-time import
const STATUS_OUT = ELEMENTS_DOCS+"Silver/__SwiftEvolutionElementsStatus2.txt"; // generated status file for comparisson
const STATUS_IN = ELEMENTS_DOCS+"Silver/__SwiftEvolutionElementsStatus.txt";
const OPEN_ISSUES_PHAB = "/Users/mh/Library/Caches/RemObjects Software/Bugs/issues-status-open.cached.json";
const OPEN_ISSUES = "/Users/mh/Library/Caches/RemObjects Software/Bugs/issues-opened.json";
const OUTPUT = ELEMENTS_DOCS+"Silver/__SwiftEvolutionStatus";
const MD = ELEMENTS_DOCS+"Silver/SwiftEvolution";
const SWIFT_ORG_BASE_URL = "https://github.com/apple/swift-evolution/blob/main/proposals/";
type
Sync = public class
fProposals: Dictionary<String, Proposal>;
method LoadProposals();
begin
fProposals := new Dictionary<String, Proposal>;
for each f in Folder.GetFiles(SWIFT_PROPOSALS) do begin
var lProposal := new Proposal withFileName(f);
fProposals[lProposal.ID] := lProposal;
//writeLn(String.Format("SE-{0} {1}", lProposal.ID, lProposal.Name));
end;
end;
method ParseLegacy();
begin
var lLegacy := File.ReadLines(LEGACY);
for each l in lLegacy do begin
if l.StartsWith("* SE-") then begin
l := l.Substring(5);
var lID := l.Substring(0, 4);
var lProposal := fProposals[lID];
if assigned(lProposal) then begin
lProposal.Known := true;
var lSplit := l.SplitAtFirstOccurrenceOf("—");
if lSplit.Count > 1 then begin
var lStatus := lSplit[1].Trim;
if lStatus.Contains("not applicable") then begin
lProposal.NotApplicable := true;
end
else if lStatus.Contains("SBL") then begin
lProposal.SwiftBaseLibrary := true
end
else if lStatus.Contains("done") then begin
lProposal.Implemented := true;
lSplit := lStatus.SplitAtFirstOccurrenceOf(",");
if lSplit.Count > 1 then
lProposal.ImplementedIn := lSplit[1].Trim();
end;
if lStatus.StartsWith("#") then begin
lProposal.IssueID := lStatus.Substring(1);
end
else if lStatus.Contains("#") then begin
lProposal.IssueID := lStatus.Substring(lStatus.IndexOf("#")+1, 5).Trim;
end;
//else
//writeLn(String.Format("KNOWN SE-{0} {1}", lID, lStatus));
end
else begin
//writeLn(String.Format("KNOWN SE-{0} NO STATUS: {1}", lID, l));
end;
end
else begin
writeLn(String.Format("UNKNOWN SE-{0}", lID));
end;
end;
end;
end;
method ParseStatus();
begin
var lOpenIssues := JsonDocument.FromFile(OPEN_ISSUES);
var lLegacy := File.ReadLines(STATUS_IN);
for each l in lLegacy do begin
if length(l) > 0 then begin
l := l.Trim();
var lSplit := l.SPlit(",");
var lID := lSplit[0];
var lProposal := fProposals[lID];
if assigned(lProposal) then begin
lProposal.Known := true;
for each s in lSplit index i do begin
if i = 0 then
continue;
s := s.Trim;
var sl := s.ToLower;
if sl = "not applicable" then
lProposal.NotApplicable := true
else if sl in ["SBL", "swift base library"] then begin
lProposal.SwiftBaseLibrary := true
end
else if sl = "implemented" then
lProposal.Implemented := true
else if sl = "wontimplement" then
lProposal.WontImplement := true
else if sl.StartsWith("in=") then
lProposal.ImplementedIn := sl.SubString(3)
else if sl.StartsWith("id=") then
lProposal.IssueID := s.SubString(3).ToUpperInvariant
else if sl.StartsWith("comment=") then
lProposal.Comment := s.SubString(8)
else if sl = "" then
//ignore?
else
writeLn(String.Format("Unknown value for SE-{0}: {1}", lID, s));
end;
if assigned(lProposal.IssueID) then begin
var lOpenIssue := if lProposal.IssueID.ToUpperInvariant.StartsWith("E") then
(lOpenIssues.Root as JsonArray).Where(i -> i["iid"]:StringValue = lProposal.IssueID.Substring(1)).FirstOrDefault
else
(lOpenIssues.Root as JsonArray).Where(i -> i["description"]:StringValue.StartsWith($"Original: T{lProposal.IssueID}")).FirstOrDefault;
if assigned(lOpenIssue) and lProposal.Implemented then begin
writeLn(String.Format("SE-{0} ({1}) is marked as done, but issue {2} ({3}) is open.", lProposal.ID, lProposal.Name, lProposal.IssueID, lOpenIssue["title"]));
end;
if not assigned(lOpenIssue) and not lProposal.Implemented and not lProposal.WontImplement and not lProposal.NotApplicable then begin
writeLn(String.Format("SE-{0} ({1}) is not marked as done, but issue {2} is not open.", lProposal.ID, lProposal.Name, lProposal.IssueID));
end;
end;
if l.ToLower.Trim([',']) ≠ lProposal.GetElementsStatusString.ToLower then begin
writeLn(String.Format("Data changed for SE-{0}", lID));
writeLn($" '{l}'");
writeLn($" '{lProposal.GetElementsStatusString}'");
end;
end
else begin
writeLn(String.Format("Unkown SE-{0}", lID));
end;
end;
end;
end;
method PrintPlain(): String;
begin
result := "";
for each from p in fProposals.Values order by p.ID desc do begin
result := result+String.Format("* SE-{0} {1} ({2})", p.ID, p.Name, p.GetElementsStatusString);
result := result+Environment.LineBreak;
end;
writeLn(result);
end;
method PrintMarkdown;
begin
writeLn(GetMarkdownByStatus());
end;
//
// Status
//
method SaveStatus;
begin
File.WriteText(STATUS_OUT, GetStatus());
end;
method GetStatus: String;
begin
result := "";
for each from p in fProposals.Values order by p.ID desc do
result := result+p.GetElementsStatusString+Environment.LineBreak;
end;
//
// Markdown
//
method SaveDocs;
begin
File.WriteText(OUTPUT+"_ByID.md", GetMarkdown());
File.WriteText(OUTPUT+"_ByAppleStatus.md", GetMarkdownByStatus());
File(MD+".md").DateModified := DateTime.UtcNow;
File(MD+"ByID.md").DateModified := DateTime.UtcNow;
end;
method GetMarkdown: String;
begin
result := "";
for each from p in fProposals.Values order by p.ID desc do
result := result+p.GetMarkdown+Environment.LineBreak;
end;
method GetMarkdownByStatus: String;
begin
result := "";
var lKnownAppleStatusValues := ["Review", "Accepted", "Implemented", "Deferred", "Rejected", "Returned" ,"Withdrawn"];
//writeLn("==");
//var lAppleStatusValues := fProposals.Values.Select(p -> p.AppleStatus).Distinct;
//for each s in lAppleStatusValues do
//writeLn(s);
//writeLn("==");
for each s in lKnownAppleStatusValues do begin
if s = "Implemented" then begin
var lAppleSwiftVersions := fProposals.Values.Select(p -> p.AppleImplementedIn).Distinct.OrderByDescending(v -> v).Where(p -> assigned(p));
for each v in lAppleSwiftVersions do begin
result := result+Environment.LineBreak+"### "+s+" for "+v+Environment.LineBreak+Environment.LineBreak;
for each from p in fProposals.Values where (p.AppleStatus = s) and (p.AppleImplementedIn = v) order by p.ID desc do
result := result+p.GetMarkdown+Environment.LineBreak;
end;
end
else begin
result := result+Environment.LineBreak+"### "+s+Environment.LineBreak+Environment.LineBreak;
for each from p in fProposals.Values where p.AppleStatus = s order by p.ID desc do
result := result+p.GetMarkdown+Environment.LineBreak;
end;
end;
end;
method Sync();
begin
end;
end;
end.