@@ -154,6 +154,20 @@ async fn upload_release_artifact(
154154 Ok ( ( ) )
155155}
156156
157+ fn new_github_client ( args : & ArgMatches ) -> Result < ( Octocrab , String ) > {
158+ let token = args
159+ . get_one :: < String > ( "token" )
160+ . expect ( "token should be specified" )
161+ . to_string ( ) ;
162+ let github_uri = args. get_one :: < String > ( "github-uri" ) ;
163+
164+ let mut builder = OctocrabBuilder :: new ( ) . personal_token ( token. clone ( ) ) ;
165+ if let Some ( github_uri) = github_uri {
166+ builder = builder. base_uri ( github_uri. clone ( ) ) ?;
167+ }
168+ Ok ( ( builder. build ( ) ?, token) )
169+ }
170+
157171pub async fn command_fetch_release_distributions ( args : & ArgMatches ) -> Result < ( ) > {
158172 let dest_dir = args
159173 . get_one :: < PathBuf > ( "dest" )
@@ -163,13 +177,7 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches) -> Result<()
163177 . expect ( "organization should be set" ) ;
164178 let repo = args. get_one :: < String > ( "repo" ) . expect ( "repo should be set" ) ;
165179
166- let client = OctocrabBuilder :: new ( )
167- . personal_token (
168- args. get_one :: < String > ( "token" )
169- . expect ( "token should be required argument" )
170- . to_string ( ) ,
171- )
172- . build ( ) ?;
180+ let ( client, _) = new_github_client ( args) ?;
173181
174182 let release_version_range = pep440_rs:: VersionSpecifier :: from_str ( ">=3.9" ) ?;
175183
@@ -398,10 +406,6 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
398406 . get_one :: < String > ( "tag" )
399407 . expect ( "tag should be specified" ) ;
400408 let ignore_missing = args. get_flag ( "ignore_missing" ) ;
401- let token = args
402- . get_one :: < String > ( "token" )
403- . expect ( "token should be specified" )
404- . to_string ( ) ;
405409 let organization = args
406410 . get_one :: < String > ( "organization" )
407411 . expect ( "organization should be specified" ) ;
@@ -491,9 +495,7 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
491495 return Err ( anyhow ! ( "missing {} release artifacts" , missing. len( ) ) ) ;
492496 }
493497
494- let client = OctocrabBuilder :: new ( )
495- . personal_token ( token. clone ( ) )
496- . build ( ) ?;
498+ let ( client, token) = new_github_client ( args) ?;
497499 let repo_handler = client. repos ( organization, repo) ;
498500 let releases = repo_handler. releases ( ) ;
499501
0 commit comments