-
Notifications
You must be signed in to change notification settings - Fork 119
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
89b8a36
Allow usage of Gerrit HTTP password tokens (#220)
corebonts 87d0476
URL encode changeId when creating GerritPatchset (#221)
corebonts e1e1984
Support gerrit configuration to omit duplicate comments (#108)
corebonts 448173c
Improve test coverage of Gerrit connector
corebonts d635644
Use Gerrit API's URL encoding in GerritFacadeBuilder
7ee15f6
Clean up Gerrit connector tests to better fit the project style
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/pl/touk/sputnik/connector/gerrit/GerritOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package pl.touk.sputnik.connector.gerrit; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import pl.touk.sputnik.configuration.Configuration; | ||
import pl.touk.sputnik.configuration.GeneralOption; | ||
|
||
@Data | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class GerritOptions { | ||
/** | ||
* Indicates whether to use Gerrit's internal password token. | ||
*/ | ||
private final boolean useHttpPassword; | ||
/** | ||
* Indicates whether to avoid publishing the same comment again when the review is retriggered | ||
* for the same revision. | ||
*/ | ||
private final boolean omitDuplicateComments; | ||
|
||
static GerritOptions from(Configuration configuration) { | ||
return new GerritOptions( | ||
Boolean.parseBoolean(configuration.getProperty(GeneralOption.GERRIT_USE_HTTP_PASSWORD)), | ||
Boolean.parseBoolean(configuration.getProperty(GeneralOption.GERRIT_OMIT_DUPLICATE_COMMENTS))); | ||
} | ||
|
||
@VisibleForTesting | ||
static GerritOptions empty() { | ||
return new GerritOptions(false, false); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/pl/touk/sputnik/connector/gerrit/GerritFacadeBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package pl.touk.sputnik.connector.gerrit; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import pl.touk.sputnik.configuration.CliOption; | ||
import pl.touk.sputnik.configuration.Configuration; | ||
import pl.touk.sputnik.configuration.ConfigurationOption; | ||
import pl.touk.sputnik.configuration.GeneralOption; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class GerritFacadeBuilderTest { | ||
private static final String CHANGE_ID_WITH_SLASH = "project/subproject~branch/subbranch~changeId"; | ||
private static final String REVISION_ID = "changeId"; | ||
|
||
@Mock | ||
private Configuration configuration; | ||
|
||
private GerritFacadeBuilder gerritFacadeBuilder; | ||
|
||
@BeforeEach | ||
void setup() { | ||
when(configuration.getProperty(any())) | ||
.then(invocation -> ((ConfigurationOption)invocation.getArgument(0)).getDefaultValue()); | ||
configure(CliOption.CHANGE_ID, CHANGE_ID_WITH_SLASH); | ||
configure(CliOption.REVISION_ID, REVISION_ID); | ||
|
||
gerritFacadeBuilder = new GerritFacadeBuilder(); | ||
} | ||
|
||
@Test | ||
void shouldEscapeChangeIdWithSlash() { | ||
GerritFacade connector = gerritFacadeBuilder.build(configuration); | ||
|
||
assertThat(connector.gerritPatchset.getChangeId()) | ||
.isEqualTo("project%2Fsubproject~branch%2Fsubbranch~changeId"); | ||
assertThat(connector.gerritPatchset.getRevisionId()) | ||
.isEqualTo(REVISION_ID); | ||
} | ||
|
||
@Test | ||
void shouldBuildWithCorrectOptions() { | ||
configure(GeneralOption.GERRIT_USE_HTTP_PASSWORD, "true"); | ||
configure(GeneralOption.GERRIT_OMIT_DUPLICATE_COMMENTS, "false"); | ||
|
||
GerritFacade connector = gerritFacadeBuilder.build(configuration); | ||
|
||
assertThat(connector.options.isUseHttpPassword()).isTrue(); | ||
assertThat(connector.options.isOmitDuplicateComments()).isFalse(); | ||
} | ||
|
||
private void configure(ConfigurationOption option, String value) { | ||
when(configuration.getProperty(option)).thenReturn(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Great!