Make adding of signed-off-by footer for online changes customizable

Now that we migrated general user preferences to Git backend, we can
easily introduce new customization option: Signed-off-by footer for
changes created with inline edit feature:

* "Create Change" button on project screen
* "Edit Config" button on project screen
* "Follow-Up" button on change screen

Change-Id: Ifa94c18d5351196fbc741c6b16d0b129e2b4a6cb
This commit is contained in:
David Ostrovsky
2015-11-01 22:49:28 +01:00
committed by David Pursehouse
parent 5f8ce2c486
commit 5d8f62c938
9 changed files with 82 additions and 5 deletions

View File

@@ -72,6 +72,7 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
assertThat(o.legacycidInChangeTable).isNull();
assertThat(o.muteCommonPathPrefixes).isEqualTo(
d.muteCommonPathPrefixes);
assertThat(o.signedOffBy).isNull();
assertThat(o.reviewCategoryStrategy).isEqualTo(
d.getReviewCategoryStrategy());
assertThat(o.diffView).isEqualTo(d.getDiffView());
@@ -93,6 +94,7 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
i.sizeBarInChangeTable ^= true;
i.legacycidInChangeTable ^= true;
i.muteCommonPathPrefixes ^= true;
i.signedOffBy ^= true;
i.reviewCategoryStrategy = ReviewCategoryStrategy.ABBREV;
i.diffView = DiffView.UNIFIED_DIFF;
i.my = new ArrayList<>();
@@ -117,6 +119,7 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
assertThat(o.sizeBarInChangeTable).isNull();
assertThat(o.legacycidInChangeTable).isEqualTo(i.legacycidInChangeTable);
assertThat(o.muteCommonPathPrefixes).isNull();
assertThat(o.signedOffBy).isEqualTo(i.signedOffBy);
assertThat(o.reviewCategoryStrategy).isEqualTo(
i.getReviewCategoryStrategy());
assertThat(o.diffView).isEqualTo(i.getDiffView());

View File

@@ -17,11 +17,13 @@ package com.google.gerrit.acceptance.rest.change;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.eclipse.jgit.lib.Constants.SIGNED_OFF_BY_TAG;
import com.google.common.collect.Iterables;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ChangeInput;
import com.google.gerrit.extensions.restapi.BadRequestException;
@@ -42,7 +44,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@NoHttpd
public class CreateChangeIT extends AbstractDaemonTest {
@ConfigSuite.Config
public static Config allowDraftsDisabled() {
@@ -59,7 +60,6 @@ public class CreateChangeIT extends AbstractDaemonTest {
TestTimeUtil.useSystemTime();
}
@Test
public void createEmptyChange_MissingBranch() throws Exception {
ChangeInput ci = new ChangeInput();
@@ -89,6 +89,17 @@ public class CreateChangeIT extends AbstractDaemonTest {
assertCreateSucceeds(newChangeInput(ChangeStatus.NEW));
}
@Test
public void createNewChangeSignedOffByFooter() throws Exception {
assume().that(isAllowDrafts()).isTrue();
setSignedOffByFooter();
ChangeInfo info = assertCreateSucceeds(newChangeInput(ChangeStatus.NEW));
String message = info.revisions.get(info.currentRevision).commit.message;
assertThat(message.contains(
String.format("%s Adminitrstaor %s", SIGNED_OFF_BY_TAG,
admin.getIdent().getEmailAddress())));
}
@Test
public void createDraftChange() throws Exception {
assume().that(isAllowDrafts()).isTrue();
@@ -164,4 +175,21 @@ public class CreateChangeIT extends AbstractDaemonTest {
}
return draft ? ChangeStatus.DRAFT : ChangeStatus.NEW;
}
// TODO(davido): Expose setting of account preferences in the API
private void setSignedOffByFooter() throws Exception {
RestResponse r = adminSession.get("/accounts/" + admin.email
+ "/preferences");
r.assertOK();
GeneralPreferencesInfo i =
newGson().fromJson(r.getReader(), GeneralPreferencesInfo.class);
i.signedOffBy = true;
r = adminSession.put("/accounts/" + admin.email + "/preferences", i);
r.assertOK();
GeneralPreferencesInfo o = newGson().fromJson(r.getReader(),
GeneralPreferencesInfo.class);
assertThat(o.signedOffBy).isTrue();
}
}