use of org.eclipse.jgit.revwalk.FooterLine in project gerrit by GerritCodeReview.
the class MailUtil method getRecipientsFromFooters.
public static MailRecipients getRecipientsFromFooters(AccountResolver accountResolver, List<FooterLine> footerLines) throws IOException, ConfigInvalidException {
MailRecipients recipients = new MailRecipients();
for (FooterLine footerLine : footerLines) {
try {
if (isReviewer(footerLine)) {
Account.Id accountId = toAccountId(accountResolver, footerLine.getValue().trim());
recipients.reviewers.add(accountId);
logger.atFine().log("Added account %d from footer line \"%s\" as reviewer", accountId.get(), footerLine);
} else if (footerLine.matches(FooterKey.CC)) {
Account.Id accountId = toAccountId(accountResolver, footerLine.getValue().trim());
recipients.cc.add(accountId);
logger.atFine().log("Added account %d from footer line \"%s\" as cc", accountId.get(), footerLine);
}
} catch (UnprocessableEntityException e) {
logger.atFine().log("Skip adding reviewer/cc from footer line \"%s\": %s", footerLine, e.getMessage());
continue;
}
}
return recipients;
}
use of org.eclipse.jgit.revwalk.FooterLine 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 org.eclipse.jgit.revwalk.FooterLine in project gerrit by GerritCodeReview.
the class ChangeNotesCommit method getFooterLineValues.
public List<String> getFooterLineValues(FooterKey key) {
if (footerLines == null) {
List<FooterLine> src = getFooterLines();
footerLines = MultimapBuilder.hashKeys(src.size()).arrayListValues(1).build();
for (FooterLine fl : src) {
footerLines.put(fl.getKey().toLowerCase(), fl.getValue());
}
}
return footerLines.get(key.getName().toLowerCase());
}
use of org.eclipse.jgit.revwalk.FooterLine in project gerrit by GerritCodeReview.
the class AuditLogReader method parse.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
private Optional<ParsedCommit> parse(AccountGroup.UUID uuid, RevCommit c) {
Optional<Account.Id> authorId = NoteDbUtil.parseIdent(c.getAuthorIdent());
if (!authorId.isPresent()) {
// ReviewDb. May be revisited.
return Optional.empty();
}
List<Account.Id> addedMembers = new ArrayList<>();
List<AccountGroup.UUID> addedSubgroups = new ArrayList<>();
List<Account.Id> removedMembers = new ArrayList<>();
List<AccountGroup.UUID> removedSubgroups = new ArrayList<>();
for (FooterLine line : c.getFooterLines()) {
if (line.matches(GroupConfigCommitMessage.FOOTER_ADD_MEMBER)) {
parseAccount(uuid, c, line).ifPresent(addedMembers::add);
} else if (line.matches(GroupConfigCommitMessage.FOOTER_REMOVE_MEMBER)) {
parseAccount(uuid, c, line).ifPresent(removedMembers::add);
} else if (line.matches(GroupConfigCommitMessage.FOOTER_ADD_GROUP)) {
parseGroup(uuid, c, line).ifPresent(addedSubgroups::add);
} else if (line.matches(GroupConfigCommitMessage.FOOTER_REMOVE_GROUP)) {
parseGroup(uuid, c, line).ifPresent(removedSubgroups::add);
}
}
return Optional.of(new AutoValue_AuditLogReader_ParsedCommit(authorId.get(), c.getAuthorIdent().getWhen().toInstant(), ImmutableList.copyOf(addedMembers), ImmutableList.copyOf(removedMembers), ImmutableList.copyOf(addedSubgroups), ImmutableList.copyOf(removedSubgroups)));
}
use of org.eclipse.jgit.revwalk.FooterLine 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>
*
* @param n
* @param ctl
* @param psId
* @return new message
*/
private String createDetailedCommitMessage(RevCommit n, ChangeControl ctl, PatchSet.Id psId) {
Change c = ctl.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 (!contains(footers, FooterConstants.CHANGE_ID, c.getKey().get())) {
msgbuf.append(FooterConstants.CHANGE_ID.getName());
msgbuf.append(": ");
msgbuf.append(c.getKey().get());
msgbuf.append('\n');
}
final String siteUrl = urlProvider.get();
if (siteUrl != null) {
final String url = siteUrl + c.getId().get();
if (!contains(footers, FooterConstants.REVIEWED_ON, url)) {
msgbuf.append(FooterConstants.REVIEWED_ON.getName());
msgbuf.append(": ");
msgbuf.append(url);
msgbuf.append('\n');
}
}
PatchSetApproval submitAudit = null;
for (final PatchSetApproval a : safeGetApprovals(ctl, psId)) {
if (a.getValue() <= 0) {
// Negative votes aren't counted.
continue;
}
if (a.isLegacySubmit()) {
//
if (submitAudit == null || a.getGranted().compareTo(submitAudit.getGranted()) > 0) {
submitAudit = a;
}
continue;
}
final Account acc = identifiedUserFactory.create(a.getAccountId()).getAccount();
final StringBuilder identbuf = new StringBuilder();
if (acc.getFullName() != null && acc.getFullName().length() > 0) {
if (identbuf.length() > 0) {
identbuf.append(' ');
}
identbuf.append(acc.getFullName());
}
if (acc.getPreferredEmail() != null && acc.getPreferredEmail().length() > 0) {
if (isSignedOffBy(footers, acc.getPreferredEmail())) {
continue;
}
if (identbuf.length() > 0) {
identbuf.append(' ');
}
identbuf.append('<');
identbuf.append(acc.getPreferredEmail());
identbuf.append('>');
}
if (identbuf.length() == 0) {
// Nothing reasonable to describe them by? Ignore them.
continue;
}
final String tag;
if (isCodeReview(a.getLabelId())) {
tag = "Reviewed-by";
} else if (isVerified(a.getLabelId())) {
tag = "Tested-by";
} else {
final LabelType lt = project.getLabelTypes().byLabel(a.getLabelId());
if (lt == null) {
continue;
}
tag = lt.getName();
}
if (!contains(footers, new FooterKey(tag), identbuf.toString())) {
msgbuf.append(tag);
msgbuf.append(": ");
msgbuf.append(identbuf);
msgbuf.append('\n');
}
}
return msgbuf.toString();
}
Aggregations