Skip to content

Commit ab9b16c

Browse files
committed
Allow using a custom GitHub API endpoint for releasing
This lets me test the release scripts against a custom, fault-injected Python server, but I suppose it might also be useful for downstream users who have GHES, maybe. Patches welcome if anyone is using this and it doesn't quite work right!
1 parent f232ea0 commit ab9b16c

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/github.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
157171
pub 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

src/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ fn main_impl() -> Result<()> {
7070
.action(ArgAction::Set)
7171
.default_value("python-build-standalone")
7272
.help("GitHub repository name"),
73+
)
74+
.arg(
75+
Arg::new("github-uri")
76+
.long("github-uri")
77+
.action(ArgAction::Set)
78+
.help("Alternative GitHub URI"),
7379
),
7480
);
7581

@@ -154,6 +160,12 @@ fn main_impl() -> Result<()> {
154160
.action(ArgAction::Set)
155161
.default_value("python-build-standalone")
156162
.help("GitHub repository name"),
163+
)
164+
.arg(
165+
Arg::new("github-uri")
166+
.long("github-uri")
167+
.action(ArgAction::Set)
168+
.help("Alternative GitHub URI"),
157169
),
158170
);
159171

0 commit comments

Comments
 (0)