use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class GroupConfigTest method commitMessageOfMemberRemovalContainsFooters.
@Test
public void commitMessageOfMemberRemovalContainsFooters() throws Exception {
Account account13 = createAccount(Account.id(13), "John");
Account account7 = createAccount(Account.id(7), "Jane");
ImmutableSet<Account> accounts = ImmutableSet.of(account13, account7);
createArbitraryGroup(groupUuid);
AuditLogFormatter auditLogFormatter = AuditLogFormatter.createBackedBy(accounts, ImmutableSet.of(), "server-id");
GroupDelta groupDelta1 = GroupDelta.builder().setMemberModification(members -> ImmutableSet.of(account13.id(), account7.id())).build();
updateGroup(groupUuid, groupDelta1, auditLogFormatter);
GroupDelta groupDelta2 = GroupDelta.builder().setMemberModification(members -> ImmutableSet.of(account7.id())).build();
updateGroup(groupUuid, groupDelta2, auditLogFormatter);
RevCommit revCommit = getLatestCommitForGroup(groupUuid);
assertThat(revCommit.getFullMessage()).isEqualTo("Update group\n\nRemove: John <13@server-id>");
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class AccountFieldTest method externalIdStateFieldValues.
@Test
public void externalIdStateFieldValues() throws Exception {
Account.Id id = Account.id(1);
Account account = Account.builder(id, TimeUtil.now()).setMetaId("1234567812345678123456781234567812345678").build();
ExternalId extId1 = ExternalId.create(ExternalId.Key.create(ExternalId.SCHEME_MAILTO, "foo.bar@example.com", false), id, "foo.bar@example.com", null, ObjectId.fromString("1b9a0cf038ea38a0ab08617c39aa8e28413a27ca"));
ExternalId extId2 = ExternalId.create(ExternalId.Key.create(ExternalId.SCHEME_USERNAME, "foo", false), id, null, "secret", ObjectId.fromString("5b3a73dc9a668a5b89b5f049225261e3e3291d1a"));
ExternalId extId3 = ExternalId.create(ExternalId.Key.create(ExternalId.SCHEME_USERNAME, "Bar", true), id, null, "secret", ObjectId.fromString("483ea804e84282e15ddcdd1d15a797eb4796a760"));
List<String> values = toStrings(AccountField.EXTERNAL_ID_STATE.get(AccountState.forAccount(account, ImmutableSet.of(extId1, extId2, extId3))));
String expectedValue1 = extId1.key().sha1().name() + ":" + extId1.blobId().name();
String expectedValue2 = extId2.key().sha1().name() + ":" + extId2.blobId().name();
String expectedValue3 = extId3.key().sha1().name() + ":" + extId3.blobId().name();
assertThat(values).containsExactly(expectedValue1, expectedValue2, expectedValue3);
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class AccountFieldTest method refStateFieldValues.
@Test
public void refStateFieldValues() throws Exception {
AllUsersName allUsersName = new AllUsersName(AllUsersNameProvider.DEFAULT);
Account.Builder account = Account.builder(Account.id(1), TimeUtil.now());
String metaId = "0e39795bb25dc914118224995c53c5c36923a461";
account.setMetaId(metaId);
List<String> values = toStrings(AccountField.REF_STATE.get(AccountState.forAccount(account.build())));
assertThat(values).hasSize(1);
String expectedValue = allUsersName.get() + ":" + RefNames.refsUsers(account.id()) + ":" + metaId;
assertThat(Iterables.getOnlyElement(values)).isEqualTo(expectedValue);
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class MergeUtil method createDetailedCommitMessage.
/**
* Adds footers to existing commit message based on the state of the change.
*
* <p>This adds the following footers if they are missing:
*
* <ul>
* <li>Reviewed-on: <i>url</i>
* <li>Reviewed-by | Tested-by | <i>Other-Label-Name</i>: <i>reviewer</i>
* <li>Change-Id
* </ul>
*
* @return new message
*/
private String createDetailedCommitMessage(RevCommit n, ChangeNotes notes, PatchSet.Id psId) {
Change c = notes.getChange();
final List<FooterLine> footers = n.getFooterLines();
final StringBuilder msgbuf = new StringBuilder();
msgbuf.append(n.getFullMessage());
if (msgbuf.length() == 0) {
// WTF, an empty commit message?
msgbuf.append("<no commit message provided>");
}
if (msgbuf.charAt(msgbuf.length() - 1) != '\n') {
// Missing a trailing LF? Correct it (perhaps the editor was broken).
msgbuf.append('\n');
}
if (footers.isEmpty()) {
// Doesn't end in a "Signed-off-by: ..." style line? Add another line
// break to start a new paragraph for the reviewed-by tag lines.
//
msgbuf.append('\n');
}
if (ChangeUtil.getChangeIdsFromFooter(n, urlFormatter.get()).isEmpty()) {
msgbuf.append(FooterConstants.CHANGE_ID.getName());
msgbuf.append(": ");
msgbuf.append(c.getKey().get());
msgbuf.append('\n');
}
Optional<String> url = urlFormatter.get().getChangeViewUrl(c.getProject(), c.getId());
if (url.isPresent()) {
if (!contains(footers, FooterConstants.REVIEWED_ON, url.get())) {
msgbuf.append(FooterConstants.REVIEWED_ON.getName()).append(": ").append(url.get()).append('\n');
}
}
PatchSetApproval submitAudit = null;
for (PatchSetApproval a : safeGetApprovals(notes, psId)) {
if (a.value() <= 0) {
// Negative votes aren't counted.
continue;
}
if (a.isLegacySubmit()) {
//
if (submitAudit == null || a.granted().compareTo(submitAudit.granted()) > 0) {
submitAudit = a;
}
continue;
}
final Account acc = identifiedUserFactory.create(a.accountId()).getAccount();
final StringBuilder identbuf = new StringBuilder();
if (acc.fullName() != null && acc.fullName().length() > 0) {
if (identbuf.length() > 0) {
identbuf.append(' ');
}
identbuf.append(acc.fullName());
}
if (acc.preferredEmail() != null && acc.preferredEmail().length() > 0) {
if (isSignedOffBy(footers, acc.preferredEmail())) {
continue;
}
if (identbuf.length() > 0) {
identbuf.append(' ');
}
identbuf.append('<');
identbuf.append(acc.preferredEmail());
identbuf.append('>');
}
if (identbuf.length() == 0) {
// Nothing reasonable to describe them by? Ignore them.
continue;
}
final String tag;
if (isCodeReview(a.labelId())) {
tag = "Reviewed-by";
} else if (isVerified(a.labelId())) {
tag = "Tested-by";
} else {
final Optional<LabelType> lt = project.getLabelTypes().byLabel(a.labelId());
if (!lt.isPresent()) {
continue;
}
tag = lt.get().getName();
}
if (!contains(footers, new FooterKey(tag), identbuf.toString())) {
msgbuf.append(tag);
msgbuf.append(": ");
msgbuf.append(identbuf);
msgbuf.append('\n');
}
}
return msgbuf.toString();
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class OutgoingEmail method getUserNameEmailFor.
/**
* Gets the human readable name and email for an account; if both are unavailable, returns the
* username. If no username is set, this function returns null.
*
* @param accountId user to fetch.
* @return name/email of account, username, or null if unset or the accountId is null.
*/
protected String getUserNameEmailFor(@Nullable Account.Id accountId) {
if (accountId == null) {
return null;
}
Optional<AccountState> accountState = args.accountCache.get(accountId);
if (!accountState.isPresent()) {
return null;
}
Account account = accountState.get().account();
String name = account.fullName();
String email = account.preferredEmail();
if (name != null && email != null) {
return name + " <" + email + ">";
} else if (email != null) {
return email;
} else if (name != null) {
return name;
}
return accountState.get().userName().orElse(null);
}
Aggregations