Skip to content

Commit 246af2f

Browse files
authored
Reconciler: prevent discourse post flapping between no draft and draft (#1762)
1 parent 6c896bc commit 246af2f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

release-controller/reconciler.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,18 @@ def draft_enabled_summary_retriever(
543543
commit_id: str, os_kind: OsKind, security_fix: bool
544544
) -> str | None:
545545
"""
546-
If a version/OS has a draft associated with it, return it instead of
547-
no release notes at all.
546+
If a version/OS has release notes, return them.
547+
Else fall back to a prepared draft if any exists.
548548
"""
549-
return drafts.get(f"{commit_id}-{os_kind}") or self.loader.proposal_summary(
549+
return self.loader.proposal_summary(
550550
commit_id, os_kind, security_fix
551-
)
551+
) or drafts.get(f"{commit_id}-{os_kind}")
552+
553+
def save_draft(v: VersionState, content: str) -> None:
554+
drafts[f"{v.git_revision}-{v.os_kind}"] = content
555+
556+
def has_draft(v: VersionState) -> bool:
557+
return f"{v.git_revision}-{v.os_kind}" in drafts
552558

553559
for v in versions:
554560
rclogger = logger.getChild(f"{v.rc_name}")
@@ -819,12 +825,7 @@ def draft_enabled_summary_retriever(
819825
p.incomplete()
820826

821827
with phase("forum post draft"):
822-
draft_key = f"{v.git_revision}-{v.os_kind}"
823-
if draft_key in drafts and changelog:
824-
# Forum post should only be updated with a draft if there
825-
# is no changelog yet. Otherwise use the actual changelog.
826-
del drafts[draft_key]
827-
elif not changelog and draft_key not in drafts:
828+
if not has_draft(v):
828829
rclogger.debug("Creating draft of changelog.")
829830
draft = post_process_release_notes(markdown_file)
830831
draft_start = draft.lower().find("# release notes for")
@@ -838,7 +839,7 @@ def draft_enabled_summary_retriever(
838839
f"Could not find title in draft notes: {draft}"
839840
)
840841
draft = draft[draft_start + 1 :]
841-
drafts[draft_key] = draft
842+
save_draft(v, draft)
842843

843844
with phase("forum post draft"):
844845
draft_key = f"{v.git_revision}-{v.os_kind}"

0 commit comments

Comments
 (0)