Add notify to /changes/{change-id}/edit:publish.
Adds optional notify parameter to change edit:publish API. Bug: Issue 4483 Change-Id: Ife7ded1347d98e4ce9d808aec68dff0b2d27bd23
This commit is contained in:
@@ -2135,9 +2135,17 @@ Alternatively, if the only value of the Accept request header is
|
|||||||
|
|
||||||
Promotes change edit to a regular patch set.
|
Promotes change edit to a regular patch set.
|
||||||
|
|
||||||
|
Options can be provided in the request body as a
|
||||||
|
link:#publish-change-edit-input[PublishChangeEditInput] entity.
|
||||||
|
|
||||||
.Request
|
.Request
|
||||||
----
|
----
|
||||||
POST /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/edit:publish HTTP/1.0
|
POST /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/edit:publish HTTP/1.0
|
||||||
|
Content-Type: application/json; charset=UTF-8
|
||||||
|
|
||||||
|
{
|
||||||
|
"notify": "NONE"
|
||||||
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
As response "`204 No Content`" is returned.
|
As response "`204 No Content`" is returned.
|
||||||
@@ -5007,6 +5015,21 @@ If `status` is set, an additional plaintext message describing the
|
|||||||
outcome of the fix.
|
outcome of the fix.
|
||||||
|===========================
|
|===========================
|
||||||
|
|
||||||
|
[[publish-change-edit-input]]
|
||||||
|
=== PublishChangeEditInput
|
||||||
|
The `PublishChangeEditInput` entity contains options for the publishing of
|
||||||
|
change edit.
|
||||||
|
|
||||||
|
[options="header",cols="1,^1,5"]
|
||||||
|
|=======================
|
||||||
|
|Field Name||Description
|
||||||
|
|`notify` |optional|
|
||||||
|
Notify handling that defines to whom email notifications should be sent
|
||||||
|
after the change edit is published. +
|
||||||
|
Allowed values are `NONE` and `ALL`. +
|
||||||
|
If not set, the default is `ALL`.
|
||||||
|
|=======================
|
||||||
|
|
||||||
[[push-certificate-info]]
|
[[push-certificate-info]]
|
||||||
=== PushCertificateInfo
|
=== PushCertificateInfo
|
||||||
The `PushCertificateInfo` entity contains information about a push
|
The `PushCertificateInfo` entity contains information about a push
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ import com.google.gerrit.acceptance.TestProjectInput;
|
|||||||
import com.google.gerrit.common.RawInputUtil;
|
import com.google.gerrit.common.RawInputUtil;
|
||||||
import com.google.gerrit.common.data.LabelType;
|
import com.google.gerrit.common.data.LabelType;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
|
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||||
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
|
import com.google.gerrit.extensions.api.changes.PublishChangeEditInput;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
import com.google.gerrit.extensions.client.InheritableBoolean;
|
import com.google.gerrit.extensions.client.InheritableBoolean;
|
||||||
import com.google.gerrit.extensions.client.ListChangesOption;
|
import com.google.gerrit.extensions.client.ListChangesOption;
|
||||||
@@ -161,7 +164,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
|
|||||||
assertThat(
|
assertThat(
|
||||||
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
|
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
|
||||||
RawInputUtil.create(CONTENT_NEW2))).isEqualTo(RefUpdate.Result.FORCED);
|
RawInputUtil.create(CONTENT_NEW2))).isEqualTo(RefUpdate.Result.FORCED);
|
||||||
editUtil.publish(editUtil.byChange(change).get());
|
editUtil.publish(editUtil.byChange(change).get(), NotifyHandling.NONE);
|
||||||
Optional<ChangeEdit> edit = editUtil.byChange(change);
|
Optional<ChangeEdit> edit = editUtil.byChange(change);
|
||||||
assertThat(edit.isPresent()).isFalse();
|
assertThat(edit.isPresent()).isFalse();
|
||||||
assertChangeMessages(change,
|
assertChangeMessages(change,
|
||||||
@@ -190,6 +193,24 @@ public class ChangeEditIT extends AbstractDaemonTest {
|
|||||||
"Patch Set 3: Published edit on patch set 2."));
|
"Patch Set 3: Published edit on patch set 2."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void publishEditNotifyRest() throws Exception {
|
||||||
|
AddReviewerInput in = new AddReviewerInput();
|
||||||
|
in.reviewer = user.email;
|
||||||
|
gApi.changes().id(change.getChangeId()).addReviewer(in);
|
||||||
|
|
||||||
|
modifier.createEdit(change, getCurrentPatchSet(changeId));
|
||||||
|
assertThat(
|
||||||
|
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
|
||||||
|
RawInputUtil.create(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED);
|
||||||
|
|
||||||
|
sender.clear();
|
||||||
|
PublishChangeEditInput input = new PublishChangeEditInput();
|
||||||
|
input.notify = NotifyHandling.NONE;
|
||||||
|
adminRestSession.post(urlPublish(), input).assertNoContent();
|
||||||
|
assertThat(sender.getMessages()).hasSize(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteEditRest() throws Exception {
|
public void deleteEditRest() throws Exception {
|
||||||
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
|
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
|
||||||
@@ -354,7 +375,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
|
|||||||
edit = editUtil.byChange(change);
|
edit = editUtil.byChange(change);
|
||||||
assertThat(edit.get().getEditCommit().getFullMessage()).isEqualTo(msg);
|
assertThat(edit.get().getEditCommit().getFullMessage()).isEqualTo(msg);
|
||||||
|
|
||||||
editUtil.publish(edit.get());
|
editUtil.publish(edit.get(), NotifyHandling.NONE);
|
||||||
assertThat(editUtil.byChange(change).isPresent()).isFalse();
|
assertThat(editUtil.byChange(change).isPresent()).isFalse();
|
||||||
|
|
||||||
ChangeInfo info = get(changeId, ListChangesOption.CURRENT_COMMIT,
|
ChangeInfo info = get(changeId, ListChangesOption.CURRENT_COMMIT,
|
||||||
@@ -397,7 +418,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
|
|||||||
assertThat(readContentFromJson(r)).isEqualTo(commit.getFullMessage());
|
assertThat(readContentFromJson(r)).isEqualTo(commit.getFullMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
editUtil.publish(edit.get());
|
editUtil.publish(edit.get(), NotifyHandling.NONE);
|
||||||
assertChangeMessages(change,
|
assertChangeMessages(change,
|
||||||
ImmutableList.of("Uploaded patch set 1.",
|
ImmutableList.of("Uploaded patch set 1.",
|
||||||
"Uploaded patch set 2.",
|
"Uploaded patch set 2.",
|
||||||
@@ -700,7 +721,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
|
|||||||
assertThat(modifier.modifyMessage(edit.get(), newMsg))
|
assertThat(modifier.modifyMessage(edit.get(), newMsg))
|
||||||
.isEqualTo(RefUpdate.Result.FORCED);
|
.isEqualTo(RefUpdate.Result.FORCED);
|
||||||
edit = editUtil.byChange(change);
|
edit = editUtil.byChange(change);
|
||||||
editUtil.publish(edit.get());
|
editUtil.publish(edit.get(), NotifyHandling.NONE);
|
||||||
|
|
||||||
ChangeInfo info = get(changeId);
|
ChangeInfo info = get(changeId);
|
||||||
assertThat(info.subject).isEqualTo(newSubj);
|
assertThat(info.subject).isEqualTo(newSubj);
|
||||||
@@ -727,7 +748,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
|
|||||||
editUtil.delete(editUtil.byChange(change).get());
|
editUtil.delete(editUtil.byChange(change).get());
|
||||||
assertThat(queryEdits()).hasSize(1);
|
assertThat(queryEdits()).hasSize(1);
|
||||||
|
|
||||||
editUtil.publish(editUtil.byChange(change2).get());
|
editUtil.publish(editUtil.byChange(change2).get(), NotifyHandling.NONE);
|
||||||
assertThat(queryEdits()).hasSize(0);
|
assertThat(queryEdits()).hasSize(0);
|
||||||
|
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2016 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.extensions.api.changes;
|
||||||
|
|
||||||
|
/** Input passed to {@code POST /changes/[id]/edit:publish/}. */
|
||||||
|
public class PublishChangeEditInput {
|
||||||
|
/** Who to send email notifications to after the change edit is published. */
|
||||||
|
public NotifyHandling notify = NotifyHandling.ALL;
|
||||||
|
}
|
||||||
@@ -16,6 +16,8 @@ package com.google.gerrit.server.change;
|
|||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.gerrit.common.data.Capable;
|
import com.google.gerrit.common.data.Capable;
|
||||||
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
|
import com.google.gerrit.extensions.api.changes.PublishChangeEditInput;
|
||||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||||
import com.google.gerrit.extensions.restapi.AcceptsPost;
|
import com.google.gerrit.extensions.restapi.AcceptsPost;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
@@ -71,9 +73,8 @@ public class PublishChangeEdit implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class Publish implements RestModifyView<ChangeResource, Publish.Input> {
|
public static class Publish
|
||||||
public static class Input {
|
implements RestModifyView<ChangeResource, PublishChangeEditInput> {
|
||||||
}
|
|
||||||
|
|
||||||
private final ChangeEditUtil editUtil;
|
private final ChangeEditUtil editUtil;
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ public class PublishChangeEdit implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<?> apply(ChangeResource rsrc, Publish.Input in)
|
public Response<?> apply(ChangeResource rsrc, PublishChangeEditInput in)
|
||||||
throws NoSuchChangeException, IOException, OrmException,
|
throws NoSuchChangeException, IOException, OrmException,
|
||||||
RestApiException, UpdateException {
|
RestApiException, UpdateException {
|
||||||
Capable r =
|
Capable r =
|
||||||
@@ -98,7 +99,10 @@ public class PublishChangeEdit implements
|
|||||||
"no edit exists for change %s",
|
"no edit exists for change %s",
|
||||||
rsrc.getChange().getChangeId()));
|
rsrc.getChange().getChangeId()));
|
||||||
}
|
}
|
||||||
editUtil.publish(edit.get());
|
if (in == null) {
|
||||||
|
in = new PublishChangeEditInput();
|
||||||
|
}
|
||||||
|
editUtil.publish(edit.get(), in.notify);
|
||||||
return Response.none();
|
return Response.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.gerrit.common.TimeUtil;
|
import com.google.gerrit.common.TimeUtil;
|
||||||
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
import com.google.gerrit.extensions.client.ChangeKind;
|
import com.google.gerrit.extensions.client.ChangeKind;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
@@ -169,8 +170,9 @@ public class ChangeEditUtil {
|
|||||||
* @throws UpdateException
|
* @throws UpdateException
|
||||||
* @throws RestApiException
|
* @throws RestApiException
|
||||||
*/
|
*/
|
||||||
public void publish(final ChangeEdit edit) throws NoSuchChangeException,
|
public void publish(final ChangeEdit edit, NotifyHandling notify)
|
||||||
IOException, OrmException, RestApiException, UpdateException {
|
throws NoSuchChangeException, IOException, OrmException, RestApiException,
|
||||||
|
UpdateException {
|
||||||
Change change = edit.getChange();
|
Change change = edit.getChange();
|
||||||
try (Repository repo = gitManager.openRepository(change.getProject());
|
try (Repository repo = gitManager.openRepository(change.getProject());
|
||||||
RevWalk rw = new RevWalk(repo);
|
RevWalk rw = new RevWalk(repo);
|
||||||
@@ -186,8 +188,9 @@ public class ChangeEditUtil {
|
|||||||
changeControlFactory.controlFor(db.get(), change, edit.getUser());
|
changeControlFactory.controlFor(db.get(), change, edit.getUser());
|
||||||
PatchSet.Id psId =
|
PatchSet.Id psId =
|
||||||
ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
|
ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
|
||||||
PatchSetInserter inserter =
|
PatchSetInserter inserter = patchSetInserterFactory
|
||||||
patchSetInserterFactory.create(ctl, psId, squashed);
|
.create(ctl, psId, squashed)
|
||||||
|
.setNotify(notify);
|
||||||
|
|
||||||
StringBuilder message = new StringBuilder("Patch Set ")
|
StringBuilder message = new StringBuilder("Patch Set ")
|
||||||
.append(inserter.getPatchSetId().get())
|
.append(inserter.getPatchSetId().get())
|
||||||
|
|||||||
Reference in New Issue
Block a user