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

fix: Improve robustness when building Codacy API base URL #42

Merged
merged 1 commit into from
Jan 26, 2021

Conversation

prcr
Copy link
Contributor

@prcr prcr commented Jan 18, 2021

On codacy/docs#404 a user noticed that the upload fails if the defined CODACY_API_BASE_URL environment variable includes a trailing slash character (/).

By using the java.net.URL constructor we ensure that the version path "/2.0" is always appended after the authority component of the URL.

By using the java.net.URL constructor we ensure that the version path
"/2.0" is always appended after the authority component of the URL.
@@ -25,7 +26,7 @@ class CodacyClient(
apiToken.map(t => "api_token" -> t) ++
projectToken.map(t => "project_token" -> t)

private val remoteUrl = apiUrl.getOrElse("https://api.codacy.com") + "/2.0"
private val remoteUrl = new URL(new URL(apiUrl.getOrElse("https://api.codacy.com")), "/2.0").toString()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lolgab, perhaps you have a suggestion on how to do this in a more "Scala way"? 😄

We should also have some error handling here in case the URL coming from user input is malformed. 🤔 Can you help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is fine.. I was thinking about files, that's why I told you there was a "Scala way" to interpolate 😄
I'm merging this one.

@prcr prcr marked this pull request as ready for review January 26, 2021 10:20
@prcr prcr merged commit d198b69 into master Jan 26, 2021
@delete-merged-branch delete-merged-branch bot deleted the fix/api-url-concatenation branch January 26, 2021 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants