-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-json-and-xml.fsx
83 lines (64 loc) · 2.43 KB
/
parse-json-and-xml.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#if INTERACTIVE
#r "System.Xml.Linq"
#endif
#load ".paket/load/fsharp.data.fsx"
open FSharp.Data
open FSharp.Data.JsonExtensions
#load "helpers.fsx"
open Helpers
open System
open System.IO
open System.Text
open System.Xml
open System.Xml.Linq
open System.Xml.XPath
let ReleasesJsonDirectory = Path.Combine(HomeDirectory, "git", "xamarinhq", "releases")
let InstallerXmlDirectory = Path.Combine(HomeDirectory, "git", "xamarinhq", "updater-release-xml")
let insert (name: string) (value: string) (e: XElement) =
let name = XName.Get name
let element = e.Element name
if isNull element then
e.Add(XElement(name, value))
else
element.Value <- value
e
let processProduct (product: JsonValue) (commit: string) (filename: string) =
let guid = product.["productGuid"].AsString()
let id = product.["releaseId"].AsString()
if (id.Length = 0) then () else
let xml = Path.Combine(InstallerXmlDirectory, guid + ".xml")
let doc = XDocument.Parse(File.ReadAllText xml)
let update = doc.XPathSelectElement(sprintf "/ApplicationInfo/Update[@id='%s']" id)
if (isNull update) then () else
printfn "Inserting %s %s into %s in %s" (commit.Substring(0, 8)) filename id xml
update
|> insert "ReleaseHash" commit
|> insert "ReleaseName" filename
|> ignore
use w = XmlWriter.Create(xml, XmlWriterSettings
(Encoding = UTF8Encoding false,
Indent = true,
IndentChars = (String.replicate 4 " ")))
doc.Save(w)
let processCommit commit filename =
let output = system ((sprintf "git show '%s:%s'" commit filename).Split(' ')) |> String.concat "\n"
let data = JsonValue.Parse output
let products = [for r in data.["release"] -> r.TryGetProperty("updaterProduct")]
printfn "Processing %s:%s" (commit.Substring(0, 8)) filename
for p in products do
match p with
| Some(product) -> processProduct product commit filename
| None -> ()
let main =
Environment.CurrentDirectory <- ReleasesJsonDirectory
let commits = system ("git log --reverse --pretty=tformat:'%H %s' 627dc925afb4fbf38e084e9ec3b9504a8d8c22a4..HEAD".Split(' '))
for c in commits do
match c with
| Regex @"(\w{40}) New Release - (.+)$" [commit; filename] ->
processCommit commit filename
|_ -> ()
#if INTERACTIVE
#else
[<EntryPoint; STAThread>]
let entryPoint args = main; 0
#endif