Skip to content

Commit 43d8ec8

Browse files
author
mildis
committed
use <project>~<numericId> as change id in requests
Change-Id: I64b2314f4e33e6de1dd3a7a98347482af460f120
1 parent b6d64a7 commit 43d8ec8

File tree

10 files changed

+43
-43
lines changed

10 files changed

+43
-43
lines changed

src/main/java/fr/techad/sonar/GerritConfiguration.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class GerritConfiguration {
3939

4040
private String projectName;
4141
private String branchName;
42-
private String changeId;
42+
private String changeNumber;
4343
private String revisionId;
4444

4545
public GerritConfiguration(Settings settings) {
@@ -70,7 +70,7 @@ public GerritConfiguration(Settings settings) {
7070

7171
this.setProjectName(settings.getString(PropertyKey.GERRIT_PROJECT));
7272
this.setBranchName(settings.getString(PropertyKey.GERRIT_BRANCH));
73-
this.setChangeId(settings.getString(PropertyKey.GERRIT_CHANGE_ID));
73+
this.setChangeNumber(settings.getString(PropertyKey.GERRIT_CHANGE_NUMBER));
7474
this.setRevisionId(settings.getString(PropertyKey.GERRIT_REVISION_ID));
7575

7676
this.assertGerritConfiguration();
@@ -88,9 +88,9 @@ public GerritConfiguration enable(boolean serverEnabled) {
8888

8989
public boolean isEnabled() {
9090
boolean ret = enabled;
91-
if (StringUtils.isEmpty(changeId) || StringUtils.isEmpty(revisionId)) {
91+
if (StringUtils.isEmpty(changeNumber) || StringUtils.isEmpty(revisionId)) {
9292
LOG.info(
93-
"[GERRIT PLUGIN] changeId or revisionId is empty. Not called from Gerrit ? Soft-disabling myself.");
93+
"[GERRIT PLUGIN] changeNumber or revisionId is empty. Not called from Gerrit ? Soft-disabling myself.");
9494
ret = false;
9595
}
9696
return ret;
@@ -292,12 +292,12 @@ public GerritConfiguration setBranchName(String branchName) {
292292
return this;
293293
}
294294

295-
public String getChangeId() {
296-
return changeId;
295+
public String getChangeNumber() {
296+
return changeNumber;
297297
}
298298

299-
public GerritConfiguration setChangeId(String changeId) {
300-
this.changeId = changeId;
299+
public GerritConfiguration setChangeNumber(String changeNumber) {
300+
this.changeNumber = changeNumber;
301301
return this;
302302
}
303303

@@ -337,7 +337,7 @@ void assertGerritConfiguration() {
337337
}
338338

339339
if (StringUtils.isBlank(label) || StringUtils.isBlank(projectName) || StringUtils.isBlank(branchName)
340-
|| StringUtils.isBlank(changeId) || StringUtils.isBlank(revisionId)) {
340+
|| StringUtils.isBlank(changeNumber) || StringUtils.isBlank(revisionId)) {
341341
valid = false;
342342
if (isEnabled() || LOG.isDebugEnabled()) {
343343
LOG.error("[GERRIT PLUGIN] ReviewConfiguration is not valid : {}", this.toString());
@@ -356,6 +356,6 @@ public String toString() {
356356
+ ", issueComment=" + issueComment + ", threshold=" + threshold + ", voteNoIssue=" + voteNoIssue
357357
+ ",voteBelowThreshold=" + voteBelowThreshold + ",voteAboveThreshold=" + voteAboveThreshold
358358
+ ",commentNewIssuesOnly=" + commentNewIssuesOnly + ", projectName=" + projectName + ", branchName="
359-
+ branchName + ", changeId=" + changeId + ", revisionId=" + revisionId + "]";
359+
+ branchName + ", changeNumber=" + changeNumber + ", revisionId=" + revisionId + "]";
360360
}
361361
}

src/main/java/fr/techad/sonar/GerritPostJob.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public GerritPostJob(Settings settings, GerritConfiguration gerritConfiguration,
4343
@Override
4444
public void describe(PostJobDescriptor descriptor) {
4545
descriptor.name("GERRIT PLUGIN");
46-
descriptor.requireProperty(PropertyKey.GERRIT_CHANGE_ID);
46+
descriptor.requireProperty(PropertyKey.GERRIT_CHANGE_NUMBER);
4747
}
4848

4949
@Override
@@ -98,7 +98,7 @@ public void execute(PostJobContext postJobContext) {
9898
gerritConfiguration.getLabel());
9999
}
100100

101-
LOG.debug("[GERRIT PLUGIN] Send review for ChangeId={}, RevisionId={}", gerritConfiguration.getChangeId(),
101+
LOG.debug("[GERRIT PLUGIN] Send review for ChangeNumber={}, RevisionId={}", gerritConfiguration.getChangeNumber(),
102102
gerritConfiguration.getRevisionId());
103103

104104
gerritFacade.setReview(reviewInput);

src/main/java/fr/techad/sonar/PropertyKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public final class PropertyKey {
77
public static final String GERRIT_PORT = "GERRIT_PORT";
88
public static final String GERRIT_PROJECT = "GERRIT_PROJECT";
99
public static final String GERRIT_BRANCH = "GERRIT_BRANCH";
10-
public static final String GERRIT_CHANGE_ID = "GERRIT_CHANGE_ID";
10+
public static final String GERRIT_CHANGE_NUMBER = "GERRIT_CHANGE_NUMBER";
1111
public static final String GERRIT_REVISION_ID = "GERRIT_PATCHSET_REVISION";
1212
public static final String GERRIT_USERNAME = "GERRIT_USERNAME";
1313
public static final String GERRIT_PASSWORD = "GERRIT_PASSWORD"; // NOSONAR

src/main/java/fr/techad/sonar/gerrit/network/rest/GerritRestConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class GerritRestConnector implements GerritConnector {
3535
private static final Logger LOG = Loggers.get(GerritRestConnector.class);
3636
private static final String URI_AUTH_PREFIX = "/a";
37-
private static final String URI_CHANGES = "/changes/%s~%s~%s";
37+
private static final String URI_CHANGES = "/changes/%s~%s";
3838
private static final String URI_REVISIONS = "/revisions/%s";
3939
private static final String URI_LIST_FILES_SUFFIX = "/files/";
4040
private static final String URI_SET_REVIEW = "/review";
@@ -161,7 +161,7 @@ public String rootUriBuilder() {
161161
uri = uri.concat(URI_AUTH_PREFIX);
162162
}
163163
uri = uri.concat(String.format(URI_CHANGES, encode(gerritConfiguration.getProjectName()),
164-
encode(gerritConfiguration.getBranchName()), encode(gerritConfiguration.getChangeId())));
164+
encode(gerritConfiguration.getChangeNumber())));
165165
uri = uri.concat(String.format(URI_REVISIONS, encode(gerritConfiguration.getRevisionId())));
166166

167167
LOG.debug("[GERRIT PLUGIN] Built URI : {}", uri);

src/main/java/fr/techad/sonar/gerrit/network/ssh/GerritSshConnector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
public class GerritSshConnector implements GerritConnector {
2222
private static final Logger LOG = Loggers.get(GerritSshConnector.class);
23-
private static final String CMD_LIST_FILES = "gerrit query --format=JSON --files --current-patch-set status:open change:%s limit:1";
23+
private static final String CMD_LIST_FILES = "gerrit query --format=JSON --files --current-patch-set -- status:open change:%s limit:1";
2424
private static final String CMD_SET_REVIEW = "gerrit review %s -j";
2525
private static final String SSH_KNWON_HOSTS = ".ssh/known_hosts";
2626
private static final String SSH_STRICT_NO = "StrictHostKeyChecking=no";
@@ -41,9 +41,9 @@ public String listFiles() throws IOException {
4141
SshClient sshClient = getSshClient();
4242

4343
LOG.debug("[GERRIT PLUGIN] Execute command SSH {}",
44-
String.format(CMD_LIST_FILES, gerritConfiguration.getChangeId()));
44+
String.format(CMD_LIST_FILES, gerritConfiguration.getChangeNumber()));
4545

46-
Result cmdResult = sshClient.executeCommand(String.format(CMD_LIST_FILES, gerritConfiguration.getChangeId()),
46+
Result cmdResult = sshClient.executeCommand(String.format(CMD_LIST_FILES, gerritConfiguration.getChangeNumber()),
4747
userAtHost);
4848

4949
return cmdResult.stdoutAsText("UTF-8");

src/main/resources/org/sonar/l10n/gerrit.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ property.GERRIT_MESSAGE.name=Review message
2828
property.GERRIT_MESSAGE.description=Define the message which will be added in comment
2929
property.GERRIT_ISSUE_COMMENT.name=Issue comment
3030
property.GERRIT_ISSUE_COMMENT.description=Define the message which will be used to comment issues
31-
property.GERRIT_CHANGE_ID.name=Change ID
32-
property.GERRIT_CHANGE_ID.description=Leave blank to delegate the definition by gerrit
31+
property.GERRIT_CHANGE_NUMBER.name=Change number
32+
property.GERRIT_CHANGE_NUMBER.description=Leave blank to delegate the definition by gerrit
3333
property.GERRIT_REVISION_ID.name=Patchset Revision ID
3434
property.GERRIT_REVISION_ID.description=Leave blank to delegate the definition by gerrit
3535
property.GERRIT_THRESHOLD.name=Alert threshold

src/main/resources/org/sonar/l10n/gerrit_fr.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ property.GERRIT_MESSAGE.name=Message de r\u00e9vision
2828
property.GERRIT_MESSAGE.description=D\u00e9fini le message qui sera ajout\u00e9 en commentaire de la r\u00e9vision
2929
property.GERRIT_ISSUE_COMMENT.name=Commentaire des d\u00e9fauts
3030
property.GERRIT_ISSUE_COMMENT.description=D\u00e9fini le message qui sera ajout\u00e9 en commentaire des d\u00e9fauts
31-
property.GERRIT_CHANGE_ID.name=ID du changement
32-
property.GERRIT_CHANGE_ID.description=Ne rien renseigner pour laisser Gerrit g\u00e9rer
31+
property.GERRIT_CHANGE_NUMBER.name=Num\u00e9ro du changement
32+
property.GERRIT_CHANGE_NUMBER.description=Ne rien renseigner pour laisser Gerrit g\u00e9rer
3333
property.GERRIT_REVISION_ID.name=ID de la r\u00e9vision
3434
property.GERRIT_REVISION_ID.description=Ne rien renseigner pour laisser Gerrit g\u00e9rer
3535
property.GERRIT_THRESHOLD.name=Seuil des alertes

src/test/java/fr/techad/sonar/GerritConfigurationTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class GerritConfigurationTest {
1616
private final String LABEL = "Code-Review";
1717
private final String PROJECT = "example";
1818
private final String BRANCH = "example";
19-
private final String CHANGE_ID = "I8473b95934b5732ac55d26311a706c9c2bde9940";
19+
private final String CHANGE_NUMBER = "12345";
2020
private final String REVISION_ID = "674ac754f91e64a0efb8087e59a176484bd534d1";
2121
private GerritConfiguration gerritConfiguration;
2222

@@ -27,7 +27,7 @@ public void setUp() {
2727
.setProperty(PropertyKey.GERRIT_PORT, PORT.toString()).setProperty(PropertyKey.GERRIT_USERNAME, USERNAME)
2828
.setProperty(PropertyKey.GERRIT_PASSWORD, PASSWORD).setProperty(PropertyKey.GERRIT_BASE_PATH, "")
2929
.setProperty(PropertyKey.GERRIT_PROJECT, PROJECT).setProperty(PropertyKey.GERRIT_BRANCH, BRANCH)
30-
.setProperty(PropertyKey.GERRIT_CHANGE_ID, CHANGE_ID)
30+
.setProperty(PropertyKey.GERRIT_CHANGE_NUMBER, CHANGE_NUMBER)
3131
.setProperty(PropertyKey.GERRIT_REVISION_ID, REVISION_ID)
3232
.setProperty(PropertyKey.GERRIT_LABEL, LABEL);
3333
gerritConfiguration = new GerritConfiguration(settings);
@@ -93,9 +93,9 @@ public void shouldNotValidateIfBranchNameIsBlank() throws GerritPluginException
9393
}
9494

9595
@Test
96-
public void shouldNotValidateIfChangeIdIsBlank() throws GerritPluginException {
96+
public void shouldNotValidateIfChangeNumberIsBlank() throws GerritPluginException {
9797
// given
98-
gerritConfiguration.setChangeId("");
98+
gerritConfiguration.setChangeNumber("");
9999
// when
100100
gerritConfiguration.assertGerritConfiguration();
101101
// then
@@ -346,8 +346,8 @@ public void shouldGetBranchName() {
346346
}
347347

348348
@Test
349-
public void shouldGetChangeId() {
350-
Assertions.assertEquals(CHANGE_ID, this.gerritConfiguration.getChangeId());
349+
public void shouldGetChangeNumber() {
350+
Assertions.assertEquals(CHANGE_NUMBER, this.gerritConfiguration.getChangeNumber());
351351
}
352352

353353
@Test
@@ -393,8 +393,8 @@ public void shouldInvalidateConfigurationWithBlankBranchName() {
393393
}
394394

395395
@Test
396-
public void shouldInvalidateConfigurationWithBlankChangeId() {
397-
gerritConfiguration.setChangeId("");
396+
public void shouldInvalidateConfigurationWithBlankChangeNumber() {
397+
gerritConfiguration.setChangeNumber("");
398398
gerritConfiguration.assertGerritConfiguration();
399399
Assertions.assertFalse(gerritConfiguration.isValid());
400400
}

src/test/java/fr/techad/sonar/GerritPostJobTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void setUp() {
6363
.setProperty(PropertyKey.GERRIT_HOST, "localhost")
6464
.appendProperty(PropertyKey.GERRIT_PORT, "10800")
6565
.setProperty(PropertyKey.GERRIT_PROJECT, "project")
66-
.setProperty(PropertyKey.GERRIT_CHANGE_ID, "changeid")
66+
.setProperty(PropertyKey.GERRIT_CHANGE_NUMBER, "changenumber")
6767
.setProperty(PropertyKey.GERRIT_REVISION_ID, "revisionid")
6868
.setProperty(PropertyKey.GERRIT_VOTE_NO_ISSUE, "1")
6969
.setProperty(PropertyKey.GERRIT_VOTE_ISSUE_ABOVE_THRESHOLD, "-2")
@@ -87,7 +87,7 @@ void shouldDescribeTheJob() {
8787
verify(descriptor).requireProperty(describeStringCaptor.capture());
8888
String property = describeStringCaptor.getValue();
8989
Assertions.assertEquals("GERRIT PLUGIN", name);
90-
Assertions.assertEquals(PropertyKey.GERRIT_CHANGE_ID, property);
90+
Assertions.assertEquals(PropertyKey.GERRIT_CHANGE_NUMBER, property);
9191
}
9292

9393
@Test

src/test/java/fr/techad/sonar/gerrit/network/rest/GerritRestConnectorTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void setUp() {
6565
.setProperty(PropertyKey.GERRIT_HOST, "localhost")
6666
.appendProperty(PropertyKey.GERRIT_PORT, "10800")
6767
.setProperty(PropertyKey.GERRIT_PROJECT, "project")
68-
.setProperty(PropertyKey.GERRIT_CHANGE_ID, "changeid")
68+
.setProperty(PropertyKey.GERRIT_CHANGE_NUMBER, "changenumber")
6969
.setProperty(PropertyKey.GERRIT_REVISION_ID, "revisionid")
7070
.setProperty(PropertyKey.GERRIT_LABEL, "Code-Review");
7171
}
@@ -87,7 +87,7 @@ public void shouldAggregateBasicParamsWhenAuthenticated() throws GerritPluginExc
8787
GerritRestConnector gerritRestConnector = getRestConnector();
8888

8989
// then
90-
assertEquals("/a/changes/project~branch~changeid/revisions/revisionid",
90+
assertEquals("/a/changes/project~changeid/revisions/revisionid",
9191
gerritRestConnector.rootUriBuilder());
9292
}
9393

@@ -103,7 +103,7 @@ public void shouldEncodeBranchWithSlash() throws GerritPluginException {
103103
GerritRestConnector gerritRestConnector = getRestConnector();
104104

105105
// then
106-
assertEquals("/a/changes/project~branch%2Fsubbranch~changeid/revisions/revisionid",
106+
assertEquals("/a/changes/project~changeid/revisions/revisionid",
107107
gerritRestConnector.rootUriBuilder());
108108
}
109109

@@ -119,7 +119,7 @@ public void shouldPrependCustomBasePath() throws GerritPluginException {
119119
GerritRestConnector gerritRestConnector = getRestConnector();
120120

121121
// then
122-
assertEquals("/r/a/changes/project~branch%2Fsubbranch~changeid/revisions/revisionid",
122+
assertEquals("/r/a/changes/project~changeid/revisions/revisionid",
123123
gerritRestConnector.rootUriBuilder());
124124
}
125125

@@ -133,7 +133,7 @@ public void shouldAggregateBasicParamsWhenAnonymous() throws GerritPluginExcepti
133133
GerritRestConnector gerritRestConnector = getRestConnector();
134134

135135
// then
136-
assertEquals("/changes/project~branch%2Fsubbranch~changeid/revisions/revisionid",
136+
assertEquals("/changes/project~changeid/revisions/revisionid",
137137
gerritRestConnector.rootUriBuilder());
138138
}
139139

@@ -147,15 +147,15 @@ public void shouldPrependCustomBasePathWhenAnonymous() throws GerritPluginExcept
147147
GerritRestConnector gerritRestConnector = getRestConnector();
148148

149149
// then
150-
assertEquals("/r/changes/project~branch%2Fsubbranch~changeid/revisions/revisionid",
150+
assertEquals("/r/changes/project~changeid/revisions/revisionid",
151151
gerritRestConnector.rootUriBuilder());
152152
}
153153

154154
@Test
155155
public void shouldSetReview() throws IOException {
156156
mockServer.when(
157157
request()
158-
.withPath("/a/changes/project~branch~changeid/revisions/revisionid/review")
158+
.withPath("/a/changes/project~changeid/revisions/revisionid/review")
159159
.withMethod("POST"))
160160
.respond(
161161
response()
@@ -179,7 +179,7 @@ public void shouldSetReview() throws IOException {
179179
public void shouldSetReviewWithNullResponseBody() throws IOException {
180180
mockServer.when(
181181
request()
182-
.withPath("/a/changes/project~branch~changeid2/revisions/revisionid/review")
182+
.withPath("/a/changes/project~12345/revisions/revisionid/review")
183183
.withMethod("POST"))
184184
.respond(
185185
response()
@@ -193,7 +193,7 @@ public void shouldSetReviewWithNullResponseBody() throws IOException {
193193
.setProperty(PropertyKey.GERRIT_PASSWORD, "sonar")
194194
.appendProperty(PropertyKey.GERRIT_BASE_PATH, "")
195195
.setProperty(PropertyKey.GERRIT_BRANCH, "branch")
196-
.setProperty(PropertyKey.GERRIT_CHANGE_ID, "changeid2")
196+
.setProperty(PropertyKey.GERRIT_CHANGE_NUMBER, "12345")
197197
;
198198

199199
String response = getRestConnector().setReview("review");
@@ -204,7 +204,7 @@ public void shouldSetReviewWithNullResponseBody() throws IOException {
204204
public void shouldSetReviewAsAnonymous() throws IOException {
205205
mockServer.when(
206206
request()
207-
.withPath("/changes/project~branch~changeid/revisions/revisionid/review")
207+
.withPath("/changes/project~changeid/revisions/revisionid/review")
208208
.withMethod("POST"))
209209
.respond(
210210
response()
@@ -225,7 +225,7 @@ public void shouldSetReviewAsAnonymous() throws IOException {
225225
public void shouldListFiles() throws IOException {
226226
mockServer.when(
227227
request()
228-
.withPath("/a/changes/project~branch~changeid/revisions/revisionid/files/")
228+
.withPath("/a/changes/project~changeid/revisions/revisionid/files/")
229229
.withMethod("GET"))
230230
.respond(
231231
response()

0 commit comments

Comments
 (0)