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

refactor(retrofit2): upgrade code to use retrofit2 #1313

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

alice485
Copy link

  • This PR upgrades all code to use retrofit2 and the retrofit2 boilerplate code implemented in kork-retrofit
  • Removes all dependencies to retrofit1
  • Removes all references to retrofit1 and RetrofitError

@dbyron-sf
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented Mar 12, 2025

update

✅ Branch has been successfully updated

OkHttpClient.Builder clientBuilder = client.newBuilder().readTimeout(timeout, TimeUnit.MILLISECONDS)
Interceptor requestInterceptor = (jenkinsRetrofitRequestInterceptorProvider != null) ? jenkinsRetrofitRequestInterceptorProvider.provide(host): null
OkHttpClient.Builder clientBuilder = okHttpClientConfig.createForRetrofit2().readTimeout(timeout, TimeUnit.MILLISECONDS)
if(requestInterceptor != null){
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if(requestInterceptor != null){
if (requestInterceptor != null) {

Copy link
Author

Choose a reason for hiding this comment

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

fixed

} catch (SpinnakerHttpException e) {
if (e.getResponseCode() == 404 || e.getResponseCode() >= 500) {
e.setRetryable(true); // 404 not retryable by default
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching this. Is there a test for this code path?

@@ -182,6 +190,7 @@ private Map<String, Object> getPropertyFileFromLog(String projectId, Long pipeli
} catch (SpinnakerHttpException e) {
// retry on 404 and 5XX
if (e.getResponseCode() == 404 || e.getResponseCode() >= 500) {
e.setRetryable(true); // 404 not retryable by default
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a test for this?

import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

please avoid star imports

Copy link
Author

Choose a reason for hiding this comment

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

fixed

.values()
.stream()
.collect(Collectors.toList());
return new ArrayList<>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not keep the .collect(Collectors.toList()); ?

@@ -54,8 +57,6 @@ class ConcourseClientSpec extends Specification {

req3.path == '/sky/userinfo'
req3.getHeader('Authorization') == "bearer my_token"

resp.status == 200
Copy link
Contributor

Choose a reason for hiding this comment

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

What can we do to keep this assertion? Is it a change to use Retrofit2SyncCall.executeCall instead of execute?

Copy link
Author

Choose a reason for hiding this comment

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

yeah, I was able to put the assertion back after changing the method call to Retrofit2syncCall.executeCall

Type type, Annotation[] annotations, Retrofit retrofit) {
// If the return type is a String, provide it as such
if (type.getTypeName().equals("java.lang.String")) {
return (Converter<ResponseBody, String>) value -> IOUtils.toString(value.byteStream());
Copy link
Contributor

Choose a reason for hiding this comment

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

The old code catches IOException and turns it into ConversionException. Is it more correct to throw SpinnakerConversion in that case here?

@@ -1,4 +1,4 @@
fiatVersion=1.53.0
Copy link
Contributor

Choose a reason for hiding this comment

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

I asked mergify to update, but it'd be cleaner for you to rebase and make this commit disappear.

Copy link
Author

Choose a reason for hiding this comment

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

removed the commit

Copy link
Contributor

Choose a reason for hiding this comment

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

github is still saying that this branch is out of date. Can you try rebasing again please?

.setLog(new Slf4jRetrofitLogger(TravisClient.class))
.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
return new Retrofit.Builder()
.baseUrl(address)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you refer this and make sure the address doesn't end up in baseUrl must end in / error. And this is applicable to all such retrofit2 client definitions.

@@ -264,7 +271,8 @@ public void updateBuild(String jobName, Long buildNumber, UpdatedBuild updatedBu

Copy link
Contributor

Choose a reason for hiding this comment

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

Retrofit2SyncCall.execute() is missing for jenkinsClient.submitDescription() at line 267

.setErrorHandler(SpinnakerRetrofitErrorHandler.getInstance())
BitBucketClient bitBucketClient(String address, String username, String password, OkHttp3ClientConfiguration okHttpClientConfig) {
new Retrofit.Builder()
.baseUrl(address)
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure the baseUrl doesn't cause baseUrl must end in /. Refer this for more details.

Copy link
Author

Choose a reason for hiding this comment

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

used the PR you linked as a reference to fix this and added some tests. Added all the missing Retrofit2SyncCall.execute() calls also.

Copy link
Contributor

@kirangodishala kirangodishala left a comment

Choose a reason for hiding this comment

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

@alice485 alice485 force-pushed the upgrade-to-retrofit2 branch from 6d69e8a to 0c4d482 Compare March 13, 2025 20:24
public Response userInfo() {
return skyServiceV1 != null ? skyServiceV1.userInfo() : skyServiceV2.userInfo();
public Response<ResponseBody> userInfo() {
return skyServiceV1 != null
Copy link
Contributor

Choose a reason for hiding this comment

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

a nit, but

Suggested change
return skyServiceV1 != null
return Retrofit2SyncCall.executeCall(skyServiceV1 != null ? skyServiceV1.userInfo() : skyServiceV2.userInfo());

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.

3 participants