-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Gerrit connector usability (#230)
* Allow usage of Gerrit HTTP password tokens (#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 (#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 (#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 <[email protected]>
- Loading branch information
Showing
9 changed files
with
262 additions
and
20 deletions.
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.