Skip to content

Commit 32b1e30

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 0ca55fe commit 32b1e30

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
@@ -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+
115129
pub 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

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)