Merge "Notedb: Fix loading of draft comment refs"
This commit is contained in:
commit
cf75de2722
@ -288,6 +288,20 @@ public class CommentsIT extends AbstractDaemonTest {
|
||||
assertThat(c2.line).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listChangeWithDrafts() throws Exception {
|
||||
for (Integer line : lines) {
|
||||
PushOneCommit.Result r = createChange();
|
||||
String changeId = r.getChangeId();
|
||||
String revId = r.getCommit().getName();
|
||||
DraftInput comment = newDraft(
|
||||
"file1", Side.REVISION, line, "comment 1");
|
||||
addDraft(changeId, revId, comment);
|
||||
assertThat(gApi.changes().query(
|
||||
"change:" + changeId + " has:draft").get()).hasSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publishCommentsAllRevisions() throws Exception {
|
||||
PushOneCommit.Result r1 = createChange();
|
||||
|
@ -88,6 +88,17 @@ public class RefNames {
|
||||
|
||||
public static String refsDraftComments(Account.Id accountId,
|
||||
Change.Id changeId) {
|
||||
StringBuilder r = buildRefsDraftCommentsPrefix(accountId);
|
||||
r.append(changeId.get());
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
public static String refsDraftCommentsPrefix(Account.Id accountId) {
|
||||
return buildRefsDraftCommentsPrefix(accountId).toString();
|
||||
}
|
||||
|
||||
public static StringBuilder buildRefsDraftCommentsPrefix(
|
||||
Account.Id accountId) {
|
||||
StringBuilder r = new StringBuilder();
|
||||
r.append(REFS_DRAFT_COMMENTS);
|
||||
int n = accountId.get() % 100;
|
||||
@ -98,8 +109,7 @@ public class RefNames {
|
||||
r.append('/');
|
||||
r.append(accountId.get());
|
||||
r.append('-');
|
||||
r.append(changeId.get());
|
||||
return r.toString();
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,6 +42,12 @@ public class RefNamesTest {
|
||||
.isEqualTo("refs/draft-comments/23/1011123-67473");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refsDraftCommentsPrefix() throws Exception {
|
||||
assertThat(RefNames.refsDraftCommentsPrefix(accountId))
|
||||
.isEqualTo("refs/draft-comments/23/1011123-");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refsEdit() throws Exception {
|
||||
assertThat(RefNames.refsEdit(accountId, changeId, psId))
|
||||
|
@ -275,14 +275,10 @@ public class PatchLineCommentsUtil {
|
||||
return sort(db.patchComments().draftByAuthor(author).toList());
|
||||
}
|
||||
|
||||
// TODO(dborowitz): Just scan author space.
|
||||
Set<String> refNames = getRefNamesAllUsers(RefNames.REFS_DRAFT_COMMENTS);
|
||||
Set<String> refNames =
|
||||
getRefNamesAllUsers(RefNames.refsDraftCommentsPrefix(author));
|
||||
List<PatchLineComment> comments = Lists.newArrayList();
|
||||
for (String refName : refNames) {
|
||||
Account.Id id = Account.Id.fromRefPart(refName);
|
||||
if (!author.equals(id)) {
|
||||
continue;
|
||||
}
|
||||
Change.Id changeId = Change.Id.parse(refName);
|
||||
comments.addAll(
|
||||
draftFactory.create(changeId, author).load().getComments().values());
|
||||
@ -364,7 +360,7 @@ public class PatchLineCommentsUtil {
|
||||
}
|
||||
|
||||
private Set<String> getRefNamesAllUsers(String prefix) throws OrmException {
|
||||
try (Repository repo = repoManager.openRepository(allUsers)) {
|
||||
try (Repository repo = repoManager.openMetadataRepository(allUsers)) {
|
||||
RefDatabase refDb = repo.getRefDatabase();
|
||||
return refDb.getRefs(prefix).keySet();
|
||||
} catch (IOException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user