-
Notifications
You must be signed in to change notification settings - Fork 70
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
Avoid caching when getting a raw file from raw.githubusercontent.com #376
Conversation
09a70a4
to
88c241f
Compare
...-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java
Outdated
Show resolved
Hide resolved
07de739
to
c24fd44
Compare
...-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java
Outdated
Show resolved
Hide resolved
...-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java
Show resolved
Hide resolved
...-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java
Outdated
Show resolved
Hide resolved
...-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java
Outdated
Show resolved
Hide resolved
...ain/java/org/eclipse/che/api/factory/server/github/GithubAuthorizingFileContentProvider.java
Outdated
Show resolved
Hide resolved
@vinokurig @vitaliy-guliy I have removed the prefix |
5a7d3a6
to
74bbb18
Compare
"Accept", | ||
"application/vnd.github.v3+json") | ||
.timeout(DEFAULT_HTTP_TIMEOUT) | ||
.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a code duplication, why not to define the headers array out of the return
statement?
String[] headers = {"Accept", "application/vnd.github.v3+json"};
if (!isNullOrEmpty(authenticationToken)) {
headers[2] = "Authorization";
headers[3] = "token " + authenticationToken;
}
return HttpRequest.newBuilder(uri)
.headers(headers)
.timeout(DEFAULT_HTTP_TIMEOUT)
.build();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's a duplication.
There is only one if statement, which makes the code easy to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a duplication because there are several identical code lines:
private HttpRequest buildGithubApiRequest(URI uri, @Nullable String authenticationToken) {
if (isNullOrEmpty(authenticationToken)) {
> return HttpRequest.newBuilder(uri)
.headers("Accept", "application/vnd.github.v3+json")
> .timeout(DEFAULT_HTTP_TIMEOUT)
> .build();
} else {
> return HttpRequest.newBuilder(uri)
.headers(
"Authorization",
"token " + authenticationToken,
"Accept",
"application/vnd.github.v3+json")
> .timeout(DEFAULT_HTTP_TIMEOUT)
> .build();
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a question of taste and it should not block merging of this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't block the merging, I just express my point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or a little bit simpler with wrapping to list:
private HttpRequest buildGithubApiRequest(URI uri, String authenticationToken) {
List<String> headers = Arrays.asList("Accept", "application/vnd.github.v3+json");
if (!isNullOrEmpty(authenticationToken)) {
headers.addAll(Arrays.asList("Authorization", "token " + authenticationToken));
}
return HttpRequest.newBuilder(uri)
.headers(headers.toArray(String[]::new))
.timeout(DEFAULT_HTTP_TIMEOUT)
.build();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better. Let's go with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fails with java.lang.UnsupportedOperationException
on
headers.addAll(Arrays.asList("Authorization", "token " + authenticationToken));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a code duplication, why not to define the headers array out of the
return
statement?String[] headers = {"Accept", "application/vnd.github.v3+json"}; if (!isNullOrEmpty(authenticationToken)) { headers[2] = "Authorization";
Throws ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
headers[3] = "token " + authenticationToken;
}
return HttpRequest.newBuilder(uri)
.headers(headers)
.timeout(DEFAULT_HTTP_TIMEOUT)
.build();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throws ArrayIndexOutOfBoundsException
I haven't tested it but I think wrapping to a list should work:
List<String> headers = Arrays.asList("Accept", "application/vnd.github.v3+json");
if (!isNullOrEmpty(authenticationToken)) {
headers.addAll(Arrays.asList("Authorization", "token " + authenticationToken));
}
...-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java
Show resolved
Hide resolved
...-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubURLParser.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I haven't detected a problem with caching. Tested with quay.io/vgulyy/che-server:test-fetching-git-files che-server image and my public git repository
I've tested the flow and confirm that it works.
|
02736cb
to
8d8206f
Compare
8d8206f
to
e6c7e09
Compare
…ching raw file content Signed-off-by: Vitaliy Gulyy <[email protected]>
e6c7e09
to
68c8172
Compare
Have been changed on private.
The current |
@vitaliy-guliy we should probably backport the fix to 7.56.x wdyt? |
If backported to 7.56.x, please update https://issues.redhat.com/browse/CRW-3449 with link to the successful build. |
Signed-off-by: Vitaliy Gulyy [email protected]
What does this PR do?
At the moment it's difficult to test the flow on custom git servers, so the functionality is temporary enabled only for github.com.
To prevent caching of raw file content, when addressing the file via https://raw.githubusercontent.com it needs to use SHA of the last commit instead of the branch name.
It gives us the unique URI on each file change.
E.g., use
instead of
When client asks the content of
devfile.yaml
indevfilev2
branch, che-serverdevfilev2
branch using GitHub rest APIScreenshot/screencast of this PR
What issues does this PR fix or reference?
eclipse-che/che#21184
Potentially fixes https://issues.redhat.com/browse/CRW-3449
How to test this PR?
PR Checklist
As the author of this Pull Request I made sure that:
What issues does this PR fix or reference
andHow to test this PR
completedReviewers
Reviewers, please comment how you tested the PR when approving it.