Skip to content

Commit

Permalink
upload: Split populate reviews into 2 phases
Browse files Browse the repository at this point in the history
This sets the function up to allow arbitrary topic
order in the future.

The first pass handles finding the relative topic, but
does not assume it's already populated. The second pass
needs to assume that the relative is already populated
since it uses it, so it needs to be done in topological
order (which is a followup pr).
  • Loading branch information
jerry-skydio committed Mar 12, 2024
1 parent df29593 commit ad555d4
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions revup/topic_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,43 @@ async def populate_reviews(

if relative_topic:
topic.relative_topic = self.topics[relative_topic]

if labels is not None:
topic.tags[TAG_LABEL].update([label.lower() for label in labels.split(",")])

if user_aliases is not None:
for mapping in user_aliases.split(","):
# Map usernames from alias -> user_target
alias, _, user_target = mapping.partition(":")
for tag in [TAG_REVIEWER, TAG_ASSIGNEE]:
if alias in topic.tags[tag]:
topic.tags[tag].remove(alias)
topic.tags[tag].add(user_target)

if auto_add_users in ("r2a", "both"):
topic.tags[TAG_ASSIGNEE].update(topic.tags[TAG_REVIEWER])
if auto_add_users in ("a2r", "both"):
topic.tags[TAG_REVIEWER].update(topic.tags[TAG_ASSIGNEE])

seen_topics[name] = topic

if limit_topics:
for name in limit_topics:
if name not in self.topics:
logging.warning(f"Couldn't find any topic named {name}")

await self.populate_relative_reviews(uploader)

async def populate_relative_reviews(self, uploader: str) -> None:
for name, topic in list(self.topics.items()):
if topic.relative_topic:
if len(topic.tags[TAG_BRANCH]) == 0:
topic.tags[TAG_BRANCH].update(topic.relative_topic.tags[TAG_BRANCH])
elif not topic.tags[TAG_BRANCH].issubset(topic.relative_topic.tags[TAG_BRANCH]):
raise RevupUsageException(
f"Topic {name} has branches"
f" {topic.tags[TAG_BRANCH] - topic.relative_topic.tags[TAG_BRANCH]} not in"
f" relative topic {relative_topic}"
f" relative topic {topic.relative_topic.name}"
)

if len(topic.tags[TAG_RELATIVE_BRANCH]) == 0:
Expand All @@ -531,8 +561,8 @@ async def populate_reviews(
!= topic.relative_topic.tags[TAG_RELATIVE_BRANCH]
):
raise RevupUsageException(
f"Topic {name} and relative topic {relative_topic} have differing relative "
f"branches, {topic.tags[TAG_RELATIVE_BRANCH]} vs "
f"Topic {name} and relative topic {topic.relative_topic.name} have "
f"differing relative branches, {topic.tags[TAG_RELATIVE_BRANCH]} vs "
f"{topic.relative_topic.tags[TAG_RELATIVE_BRANCH]}"
)
else:
Expand Down Expand Up @@ -571,7 +601,7 @@ async def populate_reviews(
):
raise RevupUsageException(
f"Topic {name} has uploader '{topic.tags[TAG_UPLOADER]}' while relative topic"
f" {relative_topic} has uploader"
f" {topic.relative_topic.name} has uploader"
f" {topic.relative_topic.tags[TAG_UPLOADER] or '{}'}"
)
topic_uploader = min(topic.tags[TAG_UPLOADER]) if topic.tags[TAG_UPLOADER] else uploader
Expand All @@ -583,18 +613,6 @@ async def populate_reviews(
if extra_label:
topic.tags[TAG_LABEL].add(extra_label.lower())

if labels is not None:
topic.tags[TAG_LABEL].update([label.lower() for label in labels.split(",")])

if user_aliases is not None:
for mapping in user_aliases.split(","):
# Map usernames from alias -> user_target
alias, _, user_target = mapping.partition(":")
for tag in [TAG_REVIEWER, TAG_ASSIGNEE]:
if alias in topic.tags[tag]:
topic.tags[tag].remove(alias)
topic.tags[tag].add(user_target)

for branch in topic.tags[TAG_BRANCH]:
review = Review(topic)
# Track whether we need to query for the relative pr
Expand Down Expand Up @@ -628,18 +646,6 @@ async def populate_reviews(
# Don't add draft as a label since its instead used to mark a pr as a draft
topic.tags[TAG_LABEL].discard("draft")

if auto_add_users in ("r2a", "both"):
topic.tags[TAG_ASSIGNEE].update(topic.tags[TAG_REVIEWER])
if auto_add_users in ("a2r", "both"):
topic.tags[TAG_REVIEWER].update(topic.tags[TAG_ASSIGNEE])

seen_topics[name] = topic

if limit_topics:
for name in limit_topics:
if name not in self.topics:
logging.warning(f"Couldn't find any topic named {name}")

async def mark_rebases(self, skip_rebase: bool) -> None:
"""
Scan all topics and compare patch-ids to remote patch-ids. Appropriately mark any
Expand Down

0 comments on commit ad555d4

Please sign in to comment.