forked from SwiftPackageIndex/PackageList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.stats.swift
executable file
·27 lines (22 loc) · 901 Bytes
/
.stats.swift
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
#!/usr/bin/swift sh
import Foundation
import ShellOut // @JohnSundell
let packageList = "packages.json"
let calendar = Calendar(identifier: .gregorian)
let fmt = DateFormatter()
fmt.dateFormat = "yyyy-MM-dd"
fmt.timeZone = .init(abbreviation: "UTC")
let start = fmt.date(from: "2019-05-15")!
let reportFrom = calendar.date(byAdding: .day, value: -30, to: .now)!
var date = start
while date <= Date.now {
defer { date = calendar.date(byAdding: .init(day: 7), to: date)! }
if date < reportFrom { continue }
let rev = try shellOut(to: #"git rev-list -n 1 --before="\#(date)" main"#)
if !rev.isEmpty {
try shellOut(to: "git checkout \(rev)")
let data = try Data(contentsOf: URL(fileURLWithPath: packageList))
let packages = try JSONDecoder().decode([String].self, from: data)
print(fmt.string(from: date), " ", packages.count, separator: "")
}
}