Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize REPOSITORY_URL #2206

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ pub struct PublishOpt {
}

impl PublishOpt {
const DEFAULT_REPOSITORY_URL: &'static str = "https://upload.pypi.org/legacy/";
const TEST_REPOSITORY_URL: &'static str = "https://test.pypi.org/legacy/";
const DEFAULT_REPOSITORY_URL: &'static str = "https://upload.pypi.org/legacy";
const TEST_REPOSITORY_URL: &'static str = "https://test.pypi.org/legacy";

/// Set to non interactive mode if we're running on CI
pub fn non_interactive_on_ci(&mut self) {
Expand All @@ -69,6 +69,10 @@ impl PublishOpt {
self.non_interactive = true;
}
}
/// Helper function to normalize URLs by removing trailing slashes
fn normalize_url(url: &str) -> &str {
url.trim_end_matches('/')
}
}

/// Error type for different types of errors that can happen when uploading a
Expand Down Expand Up @@ -316,9 +320,10 @@ fn complete_registry(opt: &PublishOpt) -> Result<Registry> {
let pypirc = load_pypirc();
let (registry_name, registry_url) = if let Some(repository_url) = opt.repository_url.as_deref()
{
let name = match repository_url {
PublishOpt::DEFAULT_REPOSITORY_URL => Some("pypi"),
PublishOpt::TEST_REPOSITORY_URL => Some("testpypi"),
let normalized_url = PublishOpt::normalize_url(repository_url);
let name = match normalized_url {
normalized if normalized == PublishOpt::DEFAULT_REPOSITORY_URL => Some("pypi"),
normalized if normalized == PublishOpt::TEST_REPOSITORY_URL => Some("testpypi"),
_ => None,
};
(name, repository_url.to_string())
Expand Down
Loading