File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,6 +61,23 @@ pub mod ar {
6161 trace ! ( "Got json from {repo}:\n {v}" ) ;
6262 Ok ( v[ "tag_name" ] . as_str ( ) . unwrap_or ( "" ) . to_owned ( ) )
6363 }
64+ #[ rhai_fn( return_raw, global) ]
65+ pub fn gh_releases ( ctx : NativeCallContext , repo : & str ) -> Res < rhai:: Array > {
66+ let req = ( AGENT . get ( & format ! ( "https://api.github.com/repos/{repo}/releases" ) ) )
67+ . header ( "Authorization" , & format ! ( "Bearer {}" , internal_env( "GITHUB_TOKEN" ) ?) )
68+ . header ( "User-Agent" , USER_AGENT ) ;
69+ let v: Value = req. call ( ) . ehdl ( & ctx) ?. into_body ( ) . read_json ( ) . ehdl ( & ctx) ?;
70+ trace ! ( "Got json from {repo}:\n {v}" ) ;
71+ let releases = v. as_array ( ) . ok_or_else ( || E :: from ( "gh_releases received not array" ) ) ?;
72+ let mut tags: Vec < String > = releases
73+ . iter ( )
74+ . filter_map ( |release| release[ "tag_name" ] . as_str ( ) . map ( ToOwned :: to_owned) )
75+ . collect ( ) ;
76+
77+ sort_git_tags ( & mut tags) ;
78+ Ok ( tags. into_iter ( ) . map ( rhai:: Dynamic :: from) . collect ( ) )
79+ }
80+
6481 #[ rhai_fn( return_raw, global) ]
6582 pub fn gh_tag ( ctx : NativeCallContext , repo : & str ) -> Res < String > {
6683 let req = ( AGENT . get ( & format ! ( "https://api.github.com/repos/{repo}/tags" ) ) )
You can’t perform that action at this time.
0 commit comments