@@ -8,59 +8,55 @@ enum ReadmeUpdater {
8
8
let content = try String ( contentsOfFile: readmePath, encoding: . utf8)
9
9
10
10
guard let markerRange = content. range ( of: marker) else {
11
- print ( " Marker not found in README. " ) ; fflush ( stdout )
11
+ print ( " Marker not found in README. " )
12
12
return
13
13
}
14
14
15
- // Build table content
16
15
var tableLines = [
17
- " | Repository URL | Status | " ,
18
- " |----------------|--------| "
16
+ " | # | Repository URL | Status | " ,
17
+ " |---|--- -------------|--------| "
19
18
]
20
19
21
- let filteredResults = results. filter { $0. status != nil }
20
+ let filteredResults = results. enumerated ( ) . filter { $0. element . status != nil }
22
21
23
- for result in filteredResults {
24
- tableLines. append ( " | \( result. url) | \( result. status!) | " )
22
+ for (index, result) in filteredResults {
23
+ let status = result. status!. trimmingCharacters ( in: . whitespacesAndNewlines)
24
+ tableLines. append ( " | \( index + 1 ) | \( result. url) | \( status) | " )
25
25
}
26
26
27
- // Timestamps
28
27
let now = formattedDate ( )
29
- let lastUpdated : String
30
- if filteredResults. isEmpty {
31
- lastUpdated = extractPreviousUpdatedDate ( from: content) ?? now
32
- } else {
33
- lastUpdated = now
34
- }
28
+ let lastUpdated : String = filteredResults. isEmpty
29
+ ? extractPreviousUpdatedDate ( from: content) ?? now
30
+ : now
35
31
36
32
tableLines. append ( " " ) // blank line before timestamps
37
33
tableLines. append ( " *Last updated: \( lastUpdated) * " )
38
34
tableLines. append ( " *Last checked: \( now) * " )
39
35
40
- // Inject new section
41
36
let newSection = " \( marker) \n \n " + tableLines. joined ( separator: " \n " )
42
37
let updatedContent = content [ ..< markerRange. lowerBound] + newSection
43
38
44
39
try updatedContent. write ( toFile: readmePath, atomically: true , encoding: . utf8)
45
- print ( " README.md updated. " ) ; fflush ( stdout)
46
40
}
47
41
48
42
private static func formattedDate( ) -> String {
49
43
let formatter = DateFormatter ( )
50
- formatter. dateFormat = " yyyy-MM-dd HH:mm:ss 'UTC' "
44
+ formatter. locale = Locale ( identifier : " en_US_POSIX " )
51
45
formatter. timeZone = TimeZone ( abbreviation: " UTC " )
46
+ formatter. dateFormat = " MMMM d, yyyy 'at' h:mm a (z) "
52
47
return formatter. string ( from: Date ( ) )
53
48
}
54
49
55
50
private static func extractPreviousUpdatedDate( from content: String ) -> String ? {
56
51
let pattern = #"\*Last updated: (.*?)\*"#
57
- if let match = content. range ( of: pattern, options: . regularExpression) {
58
- let line = String ( content [ match] )
59
- return line
60
- . replacingOccurrences ( of: " *Last updated: " , with: " " )
61
- . replacingOccurrences ( of: " * " , with: " " )
62
- . trimmingCharacters ( in: . whitespacesAndNewlines)
52
+ guard let match = content. range ( of: pattern, options: . regularExpression) else {
53
+ return nil
63
54
}
64
- return nil
55
+
56
+ let line = String ( content [ match] )
57
+ return line
58
+ . replacingOccurrences ( of: " *Last updated: " , with: " " )
59
+ . replacingOccurrences ( of: " * " , with: " " )
60
+ . trimmingCharacters ( in: . whitespacesAndNewlines)
65
61
}
66
62
}
0 commit comments