@@ -112,6 +112,20 @@ async fn upload_release_artifact(
112112 Ok ( ( ) )
113113}
114114
115+ fn new_github_client ( args : & ArgMatches ) -> Result < ( Octocrab , String ) > {
116+ let token = args
117+ . get_one :: < String > ( "token" )
118+ . expect ( "token should be specified" )
119+ . to_string ( ) ;
120+ let github_uri = args. get_one :: < String > ( "github-uri" ) ;
121+
122+ let mut builder = OctocrabBuilder :: new ( ) . personal_token ( token. clone ( ) ) ;
123+ if let Some ( github_uri) = github_uri {
124+ builder = builder. base_uri ( github_uri. clone ( ) ) ?;
125+ }
126+ Ok ( ( builder. build ( ) ?, token) )
127+ }
128+
115129pub async fn command_fetch_release_distributions ( args : & ArgMatches ) -> Result < ( ) > {
116130 let dest_dir = args
117131 . get_one :: < PathBuf > ( "dest" )
@@ -121,13 +135,7 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches) -> Result<()
121135 . expect ( "organization should be set" ) ;
122136 let repo = args. get_one :: < String > ( "repo" ) . expect ( "repo should be set" ) ;
123137
124- let client = OctocrabBuilder :: new ( )
125- . personal_token (
126- args. get_one :: < String > ( "token" )
127- . expect ( "token should be required argument" )
128- . to_string ( ) ,
129- )
130- . build ( ) ?;
138+ let ( client, _) = new_github_client ( args) ?;
131139
132140 let release_version_range = pep440_rs:: VersionSpecifier :: from_str ( ">=3.9" ) ?;
133141
@@ -358,10 +366,6 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
358366 . get_one :: < String > ( "tag" )
359367 . expect ( "tag should be specified" ) ;
360368 let ignore_missing = args. get_flag ( "ignore_missing" ) ;
361- let token = args
362- . get_one :: < String > ( "token" )
363- . expect ( "token should be specified" )
364- . to_string ( ) ;
365369 let organization = args
366370 . get_one :: < String > ( "organization" )
367371 . expect ( "organization should be specified" ) ;
@@ -451,9 +455,7 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
451455 return Err ( anyhow ! ( "missing {} release artifacts" , missing. len( ) ) ) ;
452456 }
453457
454- let client = OctocrabBuilder :: new ( )
455- . personal_token ( token. clone ( ) )
456- . build ( ) ?;
458+ let ( client, token) = new_github_client ( args) ?;
457459 let repo_handler = client. repos ( organization, repo) ;
458460 let releases = repo_handler. releases ( ) ;
459461
0 commit comments