@@ -3,47 +3,47 @@ import Foundation
3
3
@main
4
4
struct ArchiveDetective {
5
5
static func main( ) async {
6
- print ( " Fetching JSON from source... " ) ; fflush ( stdout)
7
-
8
6
let jsonData : [ String : Any ]
9
7
do {
10
8
jsonData = try await JSONFetcher . fetch ( )
11
9
} catch {
12
- print ( " Failed to fetch JSON: \( error) " ) ; fflush ( stdout )
10
+ print ( " Failed to fetch JSON: \( error) " )
13
11
return
14
12
}
15
13
16
- print ( " Extracting GitHub repository links... " ) ; fflush ( stdout)
17
14
let repoLinks = RepoExtractor . extract ( from: jsonData)
18
- print ( " \( repoLinks. count) repositories to check. " ) ; fflush ( stdout )
15
+ print ( " \( repoLinks. count) repositories to check. " )
19
16
20
- let results = try await withThrowingTaskGroup ( of: Models . RepoStatus. self) { group -> [ Models . RepoStatus ] in
21
- for url in repoLinks {
22
- group. addTask {
23
- return await RepoStatusChecker . checkStatus ( for: url)
17
+ var results : [ Models . RepoStatus ] = [ ]
18
+ do {
19
+ results = try await withThrowingTaskGroup ( of: Models . RepoStatus. self) { group -> [ Models . RepoStatus ] in
20
+ for url in repoLinks {
21
+ group. addTask {
22
+ return await RepoStatusChecker . checkStatus ( for: url)
23
+ }
24
24
}
25
- }
26
25
27
- var all : [ Models . RepoStatus ] = [ ]
28
- for try await result in group {
29
- all. append ( result)
26
+ var all : [ Models . RepoStatus ] = [ ]
27
+ for try await result in group {
28
+ all. append ( result)
29
+ }
30
+ return all
30
31
}
31
- return all
32
+ } catch {
33
+ print ( " Error while checking repository statuses: \( error) " )
34
+ return
32
35
}
33
36
34
- print ( " Updating README... " ) ; fflush ( stdout )
37
+
35
38
do {
36
39
try ReadmeUpdater . update ( with: results)
37
40
} catch {
38
- print ( " Failed to update README: \( error) " ) ; fflush ( stdout )
41
+ print ( " Failed to update README: \( error) " )
39
42
}
40
43
41
- print ( " \n Summary: " ) ; fflush ( stdout)
42
44
let archived = results. filter { $0. status == " Archived " } . count
43
45
let notFound = results. filter { $0. status == " Not Found " } . count
44
46
let forbidden = results. filter { $0. status? . contains ( " Forbidden " ) == true } . count
45
- print ( " Archived: \( archived) " ) ; fflush ( stdout)
46
- print ( " Not Found: \( notFound) " ) ; fflush ( stdout)
47
- print ( " Forbidden: \( forbidden) " ) ; fflush ( stdout)
47
+ print ( " Archived: \( archived) " , " Not Found: \( notFound) " , " Forbidden: \( forbidden) " )
48
48
}
49
49
}
0 commit comments