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

Improve Gerrit connector usability #230

Merged
merged 6 commits into from
Jan 28, 2021

Conversation

corebonts
Copy link
Contributor

Allow usage of Gerrit HTTP password tokens (#220)
URL encode changeId when creating GerritPatchset (#221)
Support gerrit configuration to omit duplicate comments (#108)

This makes it possible to use http password token that is defined in
Settings -> HTTP Password page instead of the regular site password.

https://gerrit-review.googlesource.com/Documentation/rest-api.html#authentication
When a cherry-pick is done and there are more commits with the same
changeId, an exended id can be used to distinguish between them.

It has a tilde separated format:
project/subproject~branch/subbranch~changeId

If this is not encoded but just put in the URL, an error message comes
from the server like:
Request not successful. Message: Not Found. Status-Code: 404.
Content: Not found: project
As it's a Gerrit feature and not a client side deduplication, it should
not have a large overhead, therefore it's enabled by default.
@codecov-io
Copy link

Codecov Report

Merging #230 (448173c) into master (b9482aa) will increase coverage by 1.78%.
The diff coverage is 76.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #230      +/-   ##
============================================
+ Coverage     72.38%   74.16%   +1.78%     
- Complexity      608      625      +17     
============================================
  Files           146      147       +1     
  Lines          1988     2009      +21     
  Branches        131      131              
============================================
+ Hits           1439     1490      +51     
+ Misses          489      457      -32     
- Partials         60       62       +2     
Impacted Files Coverage Δ Complexity Δ
.../sputnik/connector/gerrit/GerritFacadeBuilder.java 69.69% <64.28%> (+56.65%) 6.00 <2.00> (+4.00)
...l/touk/sputnik/connector/gerrit/GerritOptions.java 87.50% <87.50%> (ø) 5.00 <5.00> (?)
...a/pl/touk/sputnik/configuration/GeneralOption.java 98.46% <100.00%> (+0.04%) 3.00 <0.00> (ø)
...pl/touk/sputnik/connector/gerrit/GerritFacade.java 92.30% <100.00%> (+44.93%) 11.00 <0.00> (+3.00)
...ava/pl/touk/sputnik/connector/http/HttpHelper.java 88.88% <0.00%> (+3.70%) 11.00% <0.00%> (+1.00%)
src/main/java/pl/touk/sputnik/review/Review.java 67.50% <0.00%> (+5.00%) 15.00% <0.00%> (+3.00%)
.../touk/sputnik/connector/gerrit/GerritPatchset.java 80.00% <0.00%> (+20.00%) 4.00% <0.00%> (+1.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9482aa...448173c. Read the comment docs.

Copy link
Collaborator

@SpOOnman SpOOnman left a comment

Choose a reason for hiding this comment

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

Thank you for your support. There are a few things to rephrase and I'll be happy to merge it.

}
// To keep the changeId readable, we don't encode '~' (it is not needed according to RFC2396)
return StreamSupport.stream(Splitter.on('~').split(changeId).spliterator(), false)
.map(GerritFacadeBuilder::safeUrlEncode).collect(Collectors.joining("~"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just hope you're right and it works :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add a comment with a reference to
ChangesRestClient.id where they do it in a very similar way with the 2 and 3 argument methods.

}

@Test
void build_shouldEscapeChangeIdWithSlash() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to fit project style please skip build_ prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

void build_shouldEscapeChangeIdWithSlash() {
GerritFacade connector = gerritFacadeBuilder.build(configuration);

assertEquals("project%2Fsubproject~branch%2Fsubbranch~changeId", connector.gerritPatchset.getChangeId());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use assertj assertions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

@Test
void build_optionsPassed() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldBuildOptions maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -56,7 +67,38 @@ void shouldNotListDeletedFiles() throws IOException, RestApiException {
assertThat(reviewFiles).hasSize(1);
}

@Test
void publish() throws IOException, RestApiException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use should... naming style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Gabor Garancsi added 2 commits January 22, 2021 07:28
This actually does the same as the old 'safeUrlEncode(String)'.
Also a reference is now added for the ID encoding method.
@corebonts
Copy link
Contributor Author

@SpOOnman Please check the changes again, I think I considered all your comments.

Copy link
Collaborator

@SpOOnman SpOOnman left a comment

Choose a reason for hiding this comment

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

Thank you for your support!

// To keep the changeId readable, we don't encode '~' (it is not needed according to RFC2396)
// See also: ChangesRestClient.id(String, String) and ChangesRestClient.id(String, String, String)
return StreamSupport.stream(Splitter.on('~').split(changeId).spliterator(), false)
.map(Url::encode).collect(Collectors.joining("~"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great!

@SpOOnman SpOOnman merged commit b2c5fe9 into TouK:master Jan 28, 2021
rufuslevi pushed a commit to rufuslevi/sputnik that referenced this pull request Mar 12, 2024
* Allow usage of Gerrit HTTP password tokens (TouK#220)

This makes it possible to use http password token that is defined in
Settings -> HTTP Password page instead of the regular site password.

https://gerrit-review.googlesource.com/Documentation/rest-api.html#authentication

* URL encode changeId when creating GerritPatchset (TouK#221)

When a cherry-pick is done and there are more commits with the same
changeId, an exended id can be used to distinguish between them.

It has a tilde separated format:
project/subproject~branch/subbranch~changeId

If this is not encoded but just put in the URL, an error message comes
from the server like:
Request not successful. Message: Not Found. Status-Code: 404.
Content: Not found: project

* Support gerrit configuration to omit duplicate comments (TouK#108)

As it's a Gerrit feature and not a client side deduplication, it should
not have a large overhead, therefore it's enabled by default.

* Improve test coverage of Gerrit connector

* Use Gerrit API's URL encoding in GerritFacadeBuilder

This actually does the same as the old 'safeUrlEncode(String)'.
Also a reference is now added for the ID encoding method.

* Clean up Gerrit connector tests to better fit the project style

Co-authored-by: Gabor Garancsi <gabor.garancsi@casrd.net>
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.

None yet

3 participants