2020
2121use anyhow:: { Context , Result , bail} ;
2222use chrono:: { DateTime , Duration , Utc } ;
23+ use render:: types:: ParsedEntry ;
2324use serde:: Deserialize ;
2425use std:: collections:: HashMap ;
2526use std:: env;
2627use std:: path:: { Path , PathBuf } ;
2728
28- /// A parsed tool entry from `data/tools/<name>.yml`.
29- #[ derive( Debug , Deserialize ) ]
30- struct ToolEntry {
31- name : String ,
32- source : Option < String > ,
33- }
34-
3529/// Response from `GET /repos/{owner}/{repo}`.
3630#[ derive( Debug , Deserialize ) ]
3731struct RepoInfo {
@@ -187,8 +181,7 @@ impl GithubClient {
187181 ///
188182 /// Returns an error if the API call fails.
189183 async fn list_pr_comments ( & self , repo : & str , pr : u64 ) -> Result < Vec < IssueComment > > {
190- let url =
191- format ! ( "https://api.github.com/repos/{repo}/issues/{pr}/comments?per_page=100" ) ;
184+ let url = format ! ( "https://api.github.com/repos/{repo}/issues/{pr}/comments?per_page=100" ) ;
192185 self . get :: < Vec < IssueComment > > ( & url) . await
193186 }
194187
@@ -276,7 +269,7 @@ fn parse_github_repo(url: &str) -> Option<(String, String)> {
276269/// # Errors
277270///
278271/// Returns an error if the file cannot be read or parsed.
279- fn read_tool ( path : & Path ) -> Result < ToolEntry > {
272+ fn read_tool ( path : & Path ) -> Result < ParsedEntry > {
280273 let f = std:: fs:: File :: open ( path) . with_context ( || format ! ( "Cannot open {}" , path. display( ) ) ) ?;
281274 serde_yaml:: from_reader ( f) . with_context ( || format ! ( "Cannot parse {}" , path. display( ) ) )
282275}
@@ -287,7 +280,7 @@ fn read_tool(path: &Path) -> Result<ToolEntry> {
287280///
288281/// Returns an error only for unexpected failures (network, auth). Missing
289282/// criteria produce `CheckResult::Fail` values, not errors.
290- async fn check_tool ( client : & GithubClient , tool : & ToolEntry ) -> Result < ToolReport > {
283+ async fn check_tool ( client : & GithubClient , tool : & ParsedEntry ) -> Result < ToolReport > {
291284 let source = tool. source . clone ( ) ;
292285
293286 let gh_coords = source. as_deref ( ) . and_then ( parse_github_repo) ;
@@ -302,9 +295,7 @@ async fn check_tool(client: &GithubClient, tool: &ToolEntry) -> Result<ToolRepor
302295 if s >= MIN_STARS {
303296 CheckResult :: Pass ( format ! ( "{s} stars" ) )
304297 } else {
305- CheckResult :: Fail ( format ! (
306- "{s} stars (minimum is {MIN_STARS})"
307- ) )
298+ CheckResult :: Fail ( format ! ( "{s} stars (minimum is {MIN_STARS})" ) )
308299 }
309300 }
310301 Err ( e) => CheckResult :: Fail ( format ! ( "Could not fetch repo info: {e}" ) ) ,
@@ -341,7 +332,7 @@ async fn check_tool(client: &GithubClient, tool: &ToolEntry) -> Result<ToolRepor
341332 } ;
342333
343334 Ok ( ToolReport {
344- name : tool. name . clone ( ) ,
335+ name : tool. name . to_string ( ) ,
345336 source,
346337 stars : stars_check,
347338 contributors : contributors_check,
@@ -357,7 +348,7 @@ async fn check_tool(client: &GithubClient, tool: &ToolEntry) -> Result<ToolRepor
357348 } ;
358349
359350 Ok ( ToolReport {
360- name : tool. name . clone ( ) ,
351+ name : tool. name . to_string ( ) ,
361352 source,
362353 stars : CheckResult :: Skip ( "N/A (non-GitHub source)" . into ( ) ) ,
363354 contributors : CheckResult :: Skip ( "N/A (non-GitHub source)" . into ( ) ) ,
@@ -432,12 +423,7 @@ fn render_comment(reports: &[ToolReport]) -> String {
432423/// # Errors
433424///
434425/// Returns an error if the GitHub API calls fail.
435- async fn upsert_comment (
436- client : & GithubClient ,
437- repo : & str ,
438- pr : u64 ,
439- body : & str ,
440- ) -> Result < ( ) > {
426+ async fn upsert_comment ( client : & GithubClient , repo : & str , pr : u64 , body : & str ) -> Result < ( ) > {
441427 let comments = client. list_pr_comments ( repo, pr) . await ?;
442428
443429 let existing = comments. iter ( ) . find ( |c| c. body . contains ( COMMENT_MARKER ) ) ;
@@ -462,8 +448,7 @@ fn parse_pr_number(s: &str) -> Result<u64> {
462448#[ tokio:: main]
463449async fn main ( ) -> Result < ( ) > {
464450 let token = env:: var ( "GITHUB_TOKEN" ) . context ( "GITHUB_TOKEN not set" ) ?;
465- let gh_repo =
466- env:: var ( "GITHUB_REPOSITORY" ) . context ( "GITHUB_REPOSITORY not set" ) ?;
451+ let gh_repo = env:: var ( "GITHUB_REPOSITORY" ) . context ( "GITHUB_REPOSITORY not set" ) ?;
467452 let pr_number_str = env:: var ( "PR_NUMBER" ) . context ( "PR_NUMBER not set" ) ?;
468453 let pr_number = parse_pr_number ( & pr_number_str) ?;
469454
@@ -475,18 +460,16 @@ async fn main() -> Result<()> {
475460 let tool_paths: Vec < PathBuf > = tool_paths
476461 . into_iter ( )
477462 . filter ( |p| {
478- p. starts_with ( "data/tools" )
479- && p. extension ( ) . and_then ( |e| e. to_str ( ) ) == Some ( "yml" )
463+ p. starts_with ( "data/tools" ) && p. extension ( ) . and_then ( |e| e. to_str ( ) ) == Some ( "yml" )
480464 } )
481465 . collect ( ) ;
482466
483467 let client = GithubClient :: new ( token) ?;
484468
485469 let mut reports = Vec :: new ( ) ;
486470 for path in & tool_paths {
487- let tool = read_tool ( path)
488- . with_context ( || format ! ( "Failed to read {}" , path. display( ) ) ) ?;
489- eprintln ! ( "Checking '{}'..." , tool. name) ;
471+ let tool = read_tool ( path) . with_context ( || format ! ( "Failed to read {}" , path. display( ) ) ) ?;
472+ eprintln ! ( "Checking '{}'..." , & tool. name) ;
490473 let report = check_tool ( & client, & tool) . await ?;
491474 reports. push ( report) ;
492475 }
@@ -549,4 +532,4 @@ mod tests {
549532 let comment = render_comment ( & [ ] ) ;
550533 assert ! ( comment. contains( COMMENT_MARKER ) ) ;
551534 }
552- }
535+ }
0 commit comments